go - Running FFMPEG command through Golang exec -
i need run ffmpeg command create video images crossfade between images transition. command derived post. need run through golang os/exec package. command need run is:
ffmpeg -loop 1 -t 5 -i img-0.png -loop 1 -t 5 -i img-1.png -loop 1 -t 5 -i img-2.png -filter_complex "[1:v][0:v]blend=all_expr='a*(if(gte(t,0.5),1,t/0.5))+b*(1-(if(gte(t,0.5),1,t/0.5)))'[b1v];[2:v][1:v]blend=all_expr='a*(if(gte(t,0.5),1,t/0.5))+b*(1-(if(gte(t,0.5),1,t/0.5)))'[b2v];[0:v][b1v][1:v][b2v][2:v]concat=n=5:v=1:a=0,format=yuv420p[v]" -map '[v]' -c:v libx264 -pix_fmt yuv420p -r 30 -s 1280x720 -aspect 16:9 -crf 1 -preset ultrafast output.mp4
if run command directly in terminal, works fine. however, not work through code. code takes string command , runs through os/exec package:
command := "ffmpeg -loop 1 -t 5 -i img-0.png -loop 1 -t 5 -i img-1.png -loop 1 -t 5 -i img-2.png -filter_complex "[1:v][0:v]blend=all_expr='a*(if(gte(t,0.5),1,t/0.5))+b*(1-(if(gte(t,0.5),1,t/0.5)))'[b1v];[2:v][1:v]blend=all_expr='a*(if(gte(t,0.5),1,t/0.5))+b*(1-(if(gte(t,0.5),1,t/0.5)))'[b2v];[0:v][b1v][1:v][b2v][2:v]concat=n=5:v=1:a=0,format=yuv420p[v]" -map '[v]' -c:v libx264 -pix_fmt yuv420p -r 30 -s 1280x720 -aspect 16:9 -crf 1 -preset ultrafast output.mp4" lastquote := rune(0) f := func(c rune) bool { switch { case c == lastquote: lastquote = rune(0) return false case lastquote != rune(0): return false case unicode.in(c, unicode.quotation_mark): lastquote = c return false default: return unicode.isspace(c) } } parts := strings.fieldsfunc(command, f) cmd := exec.command(parts[0], parts[1:]...) cmd.stderr = os.stderr cmd.stdout = os.stdout err := cmd.run() if err != nil { return err }
when run this, ffmpeg error: no such filter: '"', error configuring filters. know has quotes have in video filters, have tried work , can't figure out.
any appreciated!
this work correctly :
exec.command("ffmpeg", "-loop", "1", "-t", "5", "-i", "img-0.png", "-loop", "1", "-t", "5", "-i", "img-1.png", "-loop", "1", "-t", "5", "-i", "img-2.png", "-filter_complex", "[1:v][0:v]blend=all_expr='a*(if(gte(t,0.5),1,t/0.5))+b*(1-(if(gte(t,0.5),1,t/0.5)))'[b1v];[2:v][1:v]blend=all_expr='a*(if(gte(t,0.5),1,t/0.5))+b*(1-(if(gte(t,0.5),1,t/0.5)))'[b2v];[0:v][b1v][1:v][b2v][2:v]concat=n=5:v=1:a=0,format=yuv420p[v]", "-map", "[v]", "-c:v", "libx264", "-pix_fmt", "yuv420p", "-r", "30", "-s", "1280x720", "-aspect", "16:9", "-crf", "1", "-preset", "ultrafast", "output.mp4")
notice did remove start , end double quotes -filter_complex
parameters , 2 single quotes -map
parameters.
did hand, though, not sure of strings
function automagically.
Comments
Post a Comment