Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Created April 23, 2017 15:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save peterhellberg/7ec4bfc5d27a592c58aca9aa1af7955b to your computer and use it in GitHub Desktop.
Save peterhellberg/7ec4bfc5d27a592c58aca9aa1af7955b to your computer and use it in GitHub Desktop.
FFmpeg from Go usage example
package main
import (
"os/exec"
)
func newCmd(imageFile, audioFile, outFile string) *exec.Cmd {
return exec.Command("ffmpeg",
"-r", "1",
"-loop", "1",
"-i", imageFile,
"-i", audioFile,
"-acodec", "copy",
"-r", "1",
"-shortest", "-vf",
"scale=1280:720",
outFile,
)
}
func main() {
cmd := newCmd("ep1.jpg", "ep1.wav", "ep1.flv")
cmd.Run()
}
@peterhellberg
Copy link
Author

peterhellberg commented Apr 23, 2017

Example with flag parsing, and output on error

package main

import (
	"flag"
	"fmt"
	"os/exec"
)

func main() {
	var imageFile, audioFile, outFile string

	flag.StringVar(&imageFile, "image", "ep1.jpg", "The image file")
	flag.StringVar(&audioFile, "audio", "ep1.wav", "The image file")
	flag.StringVar(&outFile, "out", "ep1.flv", "The image file")

	flag.Parse()

	cmd := newCmd(imageFile, audioFile, outFile)

	if err := cmd.Run(); err != nil {
		fmt.Printf("Error: %v\n", err)
	}
}

func newCmd(imageFile, audioFile, outFile string) *exec.Cmd {
	return exec.Command("ffmpeg",
		"-r", "1",
		"-loop", "1",
		"-i", imageFile,
		"-i", audioFile,
		"-acodec", "copy",
		"-r", "1",
		"-shortest", "-vf",
		"scale=1280:720",
		outFile,
	)
}

Copy link

ghost commented Apr 2, 2021

thanks for those!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment