u2takey / ffmpeg-go

golang binding for ffmpeg
Apache License 2.0
1.76k stars 172 forks source link

how to redirect stdout stderr to zap logger? #20

Closed xiongchuan86 closed 3 years ago

xiongchuan86 commented 3 years ago

I want to get output(stdout,stderr) from a log file

u2takey commented 3 years ago

you should write a adapter for logger which implement writer interface, example:

type LogAdapter struct{}

func (l *LogAdapter) Write(p []byte) (n int, err error) {
    log.Printf("%s", string(p))
    return len(p), nil
}

func TestWithLogger(t *testing.T) {
    err := ffmpeg.Input("./sample_data/in1.mp4", ffmpeg.KwArgs{"ss": "1"}).
        Output("./sample_data/out1.gif", ffmpeg.KwArgs{"s": "320x240", "pix_fmt": "rgb24", "t": "3", "r": "3"}).
        OverWriteOutput().WithOutput(&LogAdapter{}, &LogAdapter{}).Run()
    assert.Nil(t, err)
}