Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg concat and scale simultaneously?

Tags:

linux

ffmpeg

I have two ffmpeg commands:

ffmpeg -i d:\1.mp4 -i d:\1.mp4 -filter_complex "[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" d:\3.mp4

and

ffmpeg -i d:\1.mp4 -vf scale=320:240 d:\3.mp4

How to use them both simultaneously?

like image 351
Peter Zhukov Avatar asked Oct 17 '13 11:10

Peter Zhukov


2 Answers

For posterity: The accepted answer does not work if the input sources are of different sizes (which is the primary reason why you need to scale before combining).

What you need to do is to first scale and then pipe that video output into the concat filter like so:

ffmpeg -i input1.mp4 -i input2.mp4 -filter_complex \
"[0:v]scale=1024:576:force_original_aspect_ratio=1[v0]; \ 
 [1:v]scale=1024:576:force_original_aspect_ratio=1[v1]; \
 [v0][0:a][v1][1:a]concat=n=2:v=1:a=1[v][a]" -map [v] -map [a] output.mp4

Had this problem today and was pulling my hair for good three hours trying to figure this out and unfortunately the accepted answer did not work as noted in the comments.

like image 190
Sverrir Sigmundarson Avatar answered Sep 19 '22 21:09

Sverrir Sigmundarson


ffmpeg -i d:\1.mp4 -i d:\2.mp4 -filter_complex "concat=n=2:v=1:a=1 [v] [a]; \
[v]scale=320:200[v2]" -map "[v2]" -map "[a]" d:\3.mp4

Firstly we concatenate everything and pipe result to [v] [a] (see filtergraph syntax docs - its output from concat filter). Next we take [v], scale it and output to [v2], lastly we take [v2] and [a] and mux it to d:\3.mp4 file.

like image 32
Peter Zhukov Avatar answered Sep 17 '22 21:09

Peter Zhukov