Meddah Abdallah
Meddah Abdallah

Reputation: 706

FFMPEG concatenate 2 random and different videos

I am trying to make an app in which users can send a video and it will be concatenated with other videos automatically. So the videos are in random formats, but I am converting them before concatenation using this command :

ffmpeg -y -i {orginalVideo.itsExtention} -vcodec wmv2 4.wmv

For the concatenation I have the following command:

ffmpeg -y -i concat.wmv -i 4.wmv -filter_complex "[0:0][0:1][1:0][1:1] concat=n=2:v=1:a=1" output.wmv

but I get the following error

Input link in1:v0 parameters (size 640x480, SAR 1:1) do not match the corresponding output link in0:v0 parameters (1080x1920, SAR 1:1)

Failed to configure output pad on Parsed_concat_0
Error reinitializing filters!
Failed to inject frame into filter network: Invalid argument
Error while processing the decoded data for stream #1:0

Thank you for your answer

Upvotes: 3

Views: 4591

Answers (2)

llogan
llogan

Reputation: 133783

Using a separate step to scale is not efficient and will introduce another generational loss of quality if using a lossy encoder.

Since you're already re-encoding you can scale in the same command:

ffmpeg -y -i concat.wmv -i 4.wmv -filter_complex "[1:v]scale=1080:1920,setsar=1[v1];[0:v][0:a][v1][1:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" output.wmv

Or you could use a more complex command to avoid stretching or squishing due to the aspect ratio differences:

ffmpeg -y -i concat.wmv -i 4.wmv -filter_complex "[1:v]scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2,setsar=1[v1];[0:v][0:a][v1][1:a]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" output.wmv

Upvotes: 3

L. Scott Johnson
L. Scott Johnson

Reputation: 4382

The videos have to be the same size (pixel dimensions, that is). The output stream can't change sizes midway through. So resize one (or both) to the desired size.

e.g.:

ffmpeg -y -i {orginalVideo.itsExtention} -vf scale=640:480 -vcodec wmv2 4.wmv

And see https://trac.ffmpeg.org/wiki/Scaling for more.

Upvotes: 0

Related Questions