Skip to content

Latest commit

 

History

History
83 lines (59 loc) · 1.93 KB

README.md

File metadata and controls

83 lines (59 loc) · 1.93 KB

# FFmpex

go control ffmpeg program

Encapsulates commonly used methods and parameters


Usage notes

go get github.com/elizabevil/ffmpegx

  • create args
//make cmd args
param := paramx.Param{}
param.GlobalHandle(func(input *optionx.Global) {
	input.Overwrite = true
}).InputHandle(func(input *optionx.Input) {
	input.Inputs = []string{InputVedio}
}).OutputHandle(func(output *optionx.Output) {
	output.Outputs = []string{OutputVideo}
}).CommonHandle(paramx.PositionOutput, optionx.Common{
	F:  "flv",
	Ss: typex.MustPosition("00:00:00"),
	T:  5, // 5 second
	C:  []string{"copy"},
})
fmt.Println(param.Args())
//--》[-y -i ./input.mp4 -t 5 -c copy -f flv ./output.mp4]
  • Run directly
transcoderx.Metadata(ffprobeBinPath,InputVedio) // ffprobeBinPath get InputVedio's Metadata 
transcoderx.Cmd(ffmpegBinPath,args) //  ffmpegBinPath run with args
  • use transcoder to Run
// basic
// make transcode
// transcoderx.NewConfig() //default config: ffmpegbin: /usr/bin/ffmpeg
transcode := transcoderx.NewTranscode(transcoderx.NewConfig()) 
tran.Args = someParam()  // must set cmd param
tran.Debug=true // show full cmd
// ==> /usr/bin/ffmpeg -y -re -i ./input.mp4 -c copy -vcodec libx264 ./output.mp4
  • use Pipeline (runtime progress)
transcode :=someTranscode()
tran.Args = someParam()  // must set cmd param
metadata, err := transcode.GetMetadata(InputVedio ) // InputVedio 's Metadata (format,streams)
if err != nil {
fmt.Println("err", err)
}
pipline, err := transcode.Pipeline(metadata.Format.Duration) // currentTime/totalDuration ==> xx% 
if err != nil {
log.Panicln(err)
}
for progress := range pipline {
fmt.Printf("progress %+v\n", progress)
// progress {Frame:1 Fps:0.0 Size:0kB Time:00:00:00.00 Progress:0 Bitrate:4000.0kbits/s Speed:N/A}
// progress {Frame:150 Fps:0.0 Size:0kB Time:00:00:05.00 Progress:55.35259603675413 Bitrate:369.1kbits/s Speed:5.6e+03x}
}
fmt.Println("end!! Done")