Created
October 23, 2022 23:59
-
-
Save RingoMar/fde2af30aeb00f35cd9fd66e82264d63 to your computer and use it in GitHub Desktop.
Download webms and save it to a folder with ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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