ff

package module
v0.0.0-...-71483ec Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2015 License: BSD-2-Clause Imports: 4 Imported by: 0

README

ff: an ffmpeg (or ffprobe) command-line parameter builder

Implements useful functions for building params for a call to ffmpeg or ffprobe.

It was written, partially, as an exploration of TDD (Test Driven Development).

To install:

go get -t github.com/xdave/ff

(the -t flag ensures deps are pulled in required to run the tests)

To run the tests:

go test -v github.com/xdave/ff

To run the tests in your browser:

cd $GOPATH/src/github.com/xdave/ff
$GOPATH/bin/goconvey

(Then, open your browser to the URL given in the output)

Copyright 2015 Dave Gradwell

Released under a BSD-style license (see LICENSE file)

Documentation

Overview

Package ff implements an ffmpeg (or ffprobe) command-line parameter builder

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseFile

type BaseFile struct {
	Filename string
	Params   *ParamSet
}

Base structure representing an input file or an output file. Not meant to be used directly; use InputFile or OutputFile

func (BaseFile) AddParam

func (f BaseFile) AddParam(param ...Param)

Add a parameter to this file

func (BaseFile) Name

func (f BaseFile) Name() string

Returns the filename passed into the constructor

type Command

type Command struct {
	Path    string
	Input   File
	Outputs []File
}

Represents the entire commandline for ffmpeg/ffprobe

func NewCommand

func NewCommand(path string, input File, outputs ...File) (cmd *Command, err error)

You can pass in only input (for ffprobe). You can pass in one or more outputs. Returns a new Command structure

func (*Command) Slice

func (c *Command) Slice() (results []string)

Returns a []string slice of how a ffmpeg/ffprobe call should be represented. Does not include the command Path before it

type CommandFunc

type CommandFunc func(string, ...string) CommandInterface

Used for faking exec.Command() to test Probe()

var DefaultCommandFunc CommandFunc = func(name string, arg ...string) CommandInterface {
	return exec.Command(name, arg...)
}

Used for faking exec.Command() to test Probe()

type CommandInterface

type CommandInterface interface {
	Output() ([]byte, error)
}

Used for faking exec.Cmd.Output() to test Probe()

type Disposition

type Disposition struct {
	AttachedPic     int `json:"attached_pic"`
	CleanEffects    int `json:"clean_effects"`
	Comment         int `json:"comment"`
	Default         int `json:"default"`
	Dub             int `json:"dub"`
	Forced          int `json:"forced"`
	HearingImpaired int `json:"hearing_impaired"`
	Karaoke         int `json:"karaoke"`
	Lyrics          int `json:"lyrics"`
	Original        int `json:"original"`
	VisualImpaired  int `json:"visual_impaired"`
}

Stream disposition

type File

type File interface {
	Name() string
	AddParam(...Param)
	Slice() []string
}

Interface for either an input file or an output file

func NewInput

func NewInput(filename string, params *ParamSet) File

Returns a new File for input to ffmpeg/ffprobe

func NewOutput

func NewOutput(filename string, params *ParamSet) File

Returns a new File for output from ffmpeg/ffprobe

type Format

type Format struct {
	BitRate     string `json:"bit_rate"`
	Duration    string `json:"duration"`
	Filename    string `json:"filename"`
	LongName    string `json:"format_long_name"`
	Name        string `json:"format_name"`
	NumPrograms int    `json:"nb_programs"`
	NumStreams  int    `json:"nb_streams"`
	ProbeScore  int    `json:"probe_score"`
	Size        string `json:"size"`
	StartTime   string `json:"start_time"`
	Tags        Tags   `json:"tags"`
}

Container Format info

type InputFile

type InputFile struct {
	BaseFile
}

Represents an input file for ffmpeg/ffprobe

func (InputFile) Slice

func (f InputFile) Slice() (result []string)

Returns a slice representation of how an input file should be passed to ffmpeg/ffprobe

type OutputFile

type OutputFile struct {
	BaseFile
}

Represents an output file for ffmpeg/ffprobe

func (OutputFile) Slice

func (f OutputFile) Slice() (result []string)

Returns a slice representation of how an output file should be passed to ffmpeg/ffprobe

type Param

type Param struct {
	Key   interface{}
	Value interface{}
}

Contains the key and/or value of a command-line parameter.

func NewParam

func NewParam(key, value interface{}) (param Param)

If `key` is not a string, or is nil, it will be ignored. If `value` is nil, it will be ignored. Always returns a new Param struct, even if the fields are nil.

func (Param) Slice

func (p Param) Slice() (pair []string)

Converts this parameter to a []string{}. As above, if the `key` is not a string, it won't be added to the slice. And if `value` is nil, it will not be added to the slice. Always returns a []string slice, even if empty.

type ParamSet

type ParamSet []string

Represents a set of Params

func NewParamSet

func NewParamSet(params ...Param) *ParamSet

If no params are passed in, nothing is added. If the Slice() representation of a passed-in param is 0, they won't be added. Always returns a pointer to a new ParamSet, never nil

func (*ParamSet) Add

func (p *ParamSet) Add(params ...Param)

Contains exactly the same functionality as NewParamSet(). Does not return any value.

func (*ParamSet) Len

func (p *ParamSet) Len() int

Just runs len() on the slice.

func (*ParamSet) Slice

func (p *ParamSet) Slice() []string

Always returns a []string slice, even if empty.

type ProbeInfo

type ProbeInfo struct {
	Format  Format   `json:"format"`
	Streams []Stream `json:"streams"`
}

Just a nice structure that represents the JSON data returned by ffprobe. Mostly auto-generated with http://mholt.github.io/json-to-go

func NewInfo

func NewInfo(jsonData string) (*ProbeInfo, error)

Returns a new ProbeInfo structure from the input JSON

func Probe

func Probe(path string) (info *ProbeInfo, err error)

Actually calls ffprobe on a file and returns a ProbeInfo object

func (ProbeInfo) FilterStreams

func (info ProbeInfo) FilterStreams(t StreamType) (streams []Stream)

Filters out streams of the given StreamType. Returns a []Stream slice, even if it's empty

type SideData

type SideData struct {
	Displaymatrix string `json:"displaymatrix"`
	Rotation      int    `json:"rotation"`
	Size          int    `json:"side_data_size"`
	Type          string `json:"side_data_type"`
}

Stream side data. More fields may be added later as needed.

type Stream

type Stream struct {
	AvgFrameRate       string      `json:"avg_frame_rate"`
	BitRate            string      `json:"bit_rate"`
	BitsPerRawSample   string      `json:"bits_per_raw_sample"`
	BitsPerSample      int         `json:"bits_per_sample"`
	ChannelLayout      string      `json:"channel_layout"`
	Channels           int         `json:"channels"`
	ChromaLocation     string      `json:"chroma_location"`
	CodecLongName      string      `json:"codec_long_name"`
	CodecName          string      `json:"codec_name"`
	CodecTag           string      `json:"codec_tag"`
	CodecTagString     string      `json:"codec_tag_string"`
	CodecTimeBase      string      `json:"codec_time_base"`
	CodecType          StreamType  `json:"codec_type"`
	CodedHeight        int         `json:"coded_height"`
	CodedWidth         int         `json:"coded_width"`
	ColorPrimaries     string      `json:"color_primaries"`
	ColorRange         string      `json:"color_range"`
	ColorSpace         string      `json:"color_space"`
	ColorTransfer      string      `json:"color_transfer"`
	DisplayAspectRatio string      `json:"display_aspect_ratio"`
	DivxPacked         string      `json:"divx_packed"`
	DmixMode           string      `json:"dmix_mode"`
	Duration           string      `json:"duration"`
	DurationTs         int         `json:"duration_ts"`
	HasBFrames         int         `json:"has_b_frames"`
	Height             int         `json:"height"`
	ID                 string      `json:"id"`
	Index              int         `json:"index"`
	IsAvc              string      `json:"is_avc"`
	Level              int         `json:"level"`
	LoroCmixlev        string      `json:"loro_cmixlev"`
	LoroSurmixlev      string      `json:"loro_surmixlev"`
	LtrtCmixlev        string      `json:"ltrt_cmixlev"`
	LtrtSurmixlev      string      `json:"ltrt_surmixlev"`
	MaxBitRate         string      `json:"max_bit_rate"`
	NalLengthSize      string      `json:"nal_length_size"`
	NumFrames          string      `json:"nb_frames"`
	PixFmt             string      `json:"pix_fmt"`
	Profile            string      `json:"profile"`
	QuarterSample      string      `json:"quarter_sample"`
	FrameRate          string      `json:"r_frame_rate"`
	Refs               int         `json:"refs"`
	SampleAspectRatio  string      `json:"sample_aspect_ratio"`
	SampleFmt          string      `json:"sample_fmt"`
	SampleRate         string      `json:"sample_rate"`
	StartPts           int         `json:"start_pts"`
	StartTime          string      `json:"start_time"`
	TimeBase           string      `json:"time_base"`
	Timecode           string      `json:"timecode"`
	Width              int         `json:"width"`
	Tags               Tags        `json:"tags"`
	Disposition        Disposition `json:"disposition"`
	SideDataList       []SideData  `json:"side_data_list"`
}

Represents any kind of stream (Audio, Video, etc)

func (Stream) IsRotated

func (s Stream) IsRotated() bool

Does what it says.

func (Stream) Rotation

func (s Stream) Rotation() int

Gets rotation value of video stream, either from stream side-data, or tags. Returns 0 if it's not rotated, or if we can't figure it out.

type StreamType

type StreamType string

Used for enumerating the CodecType field in Stream

const (
	VideoStream StreamType = "video"
	AudioStream            = "audio"
)

type Tags

type Tags map[string]interface{}

Represents either Format or Stream tags embedded in the file

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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