ffmpeg

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2019 License: MIT Imports: 3 Imported by: 0

README

FFmpeg

GoDoc Go Report Card

Deprecated! Use github.com/practigo/exe instead.

Helper for using FFmpeg in Go.

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 ErrHook

type ErrHook func(cmd *exec.Cmd) error

An ErrHook provides access to the underlying Cmd and return an error.

type Hook

type Hook func(cmd *exec.Cmd)

A Hook provides access to the underlying Cmd.

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)
}

func (*HookedRunner) Run

func (r *HookedRunner) Run(ctx context.Context, arg string) error

Run runs the command (path + arg) and waits for its exit or the context timeout.

type Runner

type Runner interface {
	// Run starts a FFmpeg process and waits for its exit.
	// The ctx is used to cancel the process while it is
	// still running.
	// The arg provided should exclude the first ffmpeg path.
	Run(ctx context.Context, arg string) error
}

A Runner runs FFmpeg.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL