Documentation
¶
Overview ¶
Package ffmpeg provides runners for running a ffmpeg process from Go code.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CustomPath ¶
func CustomPath(p string) func(r *HookedRunner)
CustomPath sets the ffmpeg binary path. It should be able to found by exec.LookPath.
func DoneHook ¶
func DoneHook(h Hook) func(r *HookedRunner)
DoneHook replace the default hook that kills the process when a done context signal is received, typically sending another signals that ffmpeg can handle as normal exit.
func PostHook ¶
func PostHook(h Hook) func(r *HookedRunner)
PostHook provides a hook that runs after the cmd starts. The runner waits for the cmd's exit after this hook.
func PreHook ¶
func PreHook(h ErrHook) func(r *HookedRunner)
PreHook provides a hook that runs before the cmd starts. A non-nil error returned would stop the cmd.
Types ¶
type HookedRunner ¶
type HookedRunner struct {
// contains filtered or unexported fields
}
A HookedRunner allows hooks to access the underlying FFmpeg Command before/after FFmpeg starts and when the exit signal received.
func HookRunner ¶
func HookRunner(opts ...func(r *HookedRunner)) *HookedRunner
HookRunner returns a HookedRunner. The default Runner searches ffmpeg from system PATH, and kill (-9) the process when receiving a exit signal.
Example ¶
package main import ( "context" "log" "os" "os/exec" "syscall" "github.com/practigo/ffmpeg" ) func main() { fout, _ := os.OpenFile("proc.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) fin, _ := os.OpenFile("stdin.txt", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) r := ffmpeg.HookRunner(ffmpeg.PreHook(func(cmd *exec.Cmd) error { cmd.Env = append(os.Environ(), "FFREPORT=file=report.log:level=32") cmd.Stdout = fout cmd.Stderr = fout cmd.Stdin = fin return nil }), ffmpeg.PostHook(func(cmd *exec.Cmd) { log.Println("pid:", cmd.Process.Pid) }), ffmpeg.DoneHook(func(cmd *exec.Cmd) { cmd.Process.Signal(syscall.SIGTERM) // kill -15 })) err := r.Run(context.TODO(), "-loglevel warning -y -re -i test.mp4 out.mp4") log.Println(err) }