Skip to content

Instantly share code, notes, and snippets.

@RingoMar
Created October 23, 2022 23:59
Show Gist options
  • Save RingoMar/fde2af30aeb00f35cd9fd66e82264d63 to your computer and use it in GitHub Desktop.
Save RingoMar/fde2af30aeb00f35cd9fd66e82264d63 to your computer and use it in GitHub Desktop.
Download webms and save it to a folder with ffmpeg
package main
import (
"crypto/rand"
"fmt"
"os"
"os/exec"
"strings"
)
// https://stackoverflow.com/a/67035900
var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-"
func shortID(length int) string {
ll := len(chars)
b := make([]byte, length)
rand.Read(b) // generates len(b) random bytes
for i := 0; i < length; i++ {
b[i] = chars[int(b[i])%ll]
}
return string(b)
}
func main() {
s := strings.Join([]string{"D:/webms/", shortID(10), ".mp4"}, "")
cmd := exec.Command("ffmpeg", "-fflags", "+genpts", "-i", os.Args[1], "-r", "24", s)
stdout, err := cmd.Output()
if err != nil {
fmt.Println("Unable to download file.")
fmt.Println(err)
return
}
fmt.Println("Downloaded file:", s)
fmt.Println(string(stdout))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment