ffmpegwrapper

package module
v0.0.0-...-dcbae37 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2019 License: MIT Imports: 9 Imported by: 0

README

Simple ffmpeg wrapper

Big thanks to:

barsanuphe for goexiftool wrapper.

xfrr for goffmpeg wrapper.

Defaults

Wrapper uses ffprobe to get mediafile info, so there is default args:

   ffprobe -show_format -show_streams -pretty -print_format json -hide_banner -i %file_name%

This command produce output in json format, so we can unmarshall it to Info struct.

Defaults for ffmpeg command:

   ffmpeg -y -v error -stats -i %file_name% %out_file_name%

-y for answer yes on file rewrite

-v error verbose with only errors

-stats show transcoding status

-i input file

Example

func main(){
     // Initialize
     m, err := ffmpegwraper.NewMediaFile("./test/test.MOV")
     if err != nil {
        panic(fmt.Errorf("Failed get file info : %s", err))
     }
     // Data from ffprobe
     fmt.Println(m.Info)

     // ffmpeg params
     ffmpParams := "-ss 00:01:30 -crf 20 -bufsize 4096k -vf scale=1280:800:force_original_aspect_ratio=decrease"
     out, err := m.Convert("pre_test.mov", strings.Split(ffmpParams, " "));
     if err != nil{
     		panic(fmt.Errorf("Failed convert file : %s", err))
     }
     // Getting status of transcoding
     for msg := range out {
       fmt.Println(msg)
     }
}

-ss flag with arg will be moved befote -i flag

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Disposition

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

type Format

type Format struct {
	Filename       string
	NbStreams      int    `json:"nb_streams"`
	NbPrograms     int    `json:"nb_programs"`
	FormatName     string `json:"format_name"`
	FormatLongName string `json:"format_long_name"`
	Duration       string `json:"duration"`
	Size           string `json:"size"`
	BitRate        string `json:"bit_rate"`
	ProbeScore     int    `json:"probe_score"`
}

type MediaFile

type MediaFile struct {
	Filename string
	Info     *Metadata
}

func NewMediaFile

func NewMediaFile(filename string) (mf *MediaFile, err error)

NewMediaFile initializes a MediaFile and parses its metadata with ffprobe.

func (*MediaFile) AnalyzeMetadata

func (m *MediaFile) AnalyzeMetadata() (err error)

AnalyzeMetadata calls ffprobe on the file and parses its output to MedisaFile/Info structure.

func (*MediaFile) Convert

func (m *MediaFile) Convert(outFileName string, args []string) (chan string, error)

Convert checks that outFileName is abs path or put the output file in the same dir that original

type Metadata

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

type Streams

type Streams struct {
	Index              int
	CodecName          string      `json:"codec_name"`
	CodecLongName      string      `json:"codec_long_name"`
	Profile            string      `json:"profile"`
	CodecType          string      `json:"codec_type"`
	CodecTimeBase      string      `json:"codec_time_base"`
	CodecTagString     string      `json:"codec_tag_string"`
	CodecTag           string      `json:"codec_tag"`
	Width              int         `json:"width"`
	Height             int         `json:"height"`
	CodedWidth         int         `json:"coded_width"`
	CodedHeight        int         `json:"coded_height"`
	HasBFrames         int         `json:"has_b_frames"`
	SampleAspectRatio  string      `json:"sample_aspect_ratio"`
	DisplayAspectRatio string      `json:"display_aspect_ratio"`
	PixFmt             string      `json:"pix_fmt"`
	Level              int         `json:"level"`
	ChromaLocation     string      `json:"chroma_location"`
	Refs               int         `json:"refs"`
	QuarterSample      string      `json:"quarter_sample"`
	DivxPacked         string      `json:"divx_packed"`
	RFrameRrate        string      `json:"r_frame_rate"`
	AvgFrameRate       string      `json:"avg_frame_rate"`
	TimeBase           string      `json:"time_base"`
	DurationTs         int         `json:"duration_ts"`
	Duration           string      `json:"duration"`
	NbFrames           string      `json:"nb_frames"`
	Disposition        Disposition `json:"disposition"`
	BitRate            string      `json:"bit_rate"`
	Tags               Tags        `json:"tags"`
}

type Tags

type Tags struct {
	Rotate       string `json:"rotate, omitempty"`
	CreationTime string `json:"creation_time"`
	Language     string `json:"language"`
	HandlerName  string `json:"handler_name"`
	Encoder      string `json:"encoder, omitempty"`
}

Jump to

Keyboard shortcuts

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