FFmpeg - concat videos error, do not match the cor

2019-03-04 15:55发布

问题:

I'm trying to concat some video into one single video using ffmpeg.

input information:

a.mp4 1920x808 , b.mkv 1280x720

First I tried command below and it works fine:

ffmpeg -i a.mp4 -i b.mkv -f lavfi -t 0.1 -i anullsrc -filter_complex [1:v]scale=1920:808:force_original_aspect_ratio=decrease,pad=1920:808:(ow-iw)/2:(oh-ih)/2[v1]; [0:v][0:a][v1][1:a]concat=n=2:v=1:a=1[outv][outa] -map [outv] -map [outa] -vcodec libx264 -crf 27 -preset ultrafast -threads 2 out.mp4

And then I put 'b.mkv' first:

ffmpeg -i b.mkv -i a.mp4 -f lavfi -t 0.1 -i anullsrc -filter_complex [0:v]scale=1920:808:force_original_aspect_ratio=decrease,pad=1920:808:(ow-iw)/2:(oh-ih)/2[v0]; [v0][0:a][1:v][1:a]concat=n=2:v=1:a=1[outv][outa] -map [outv] -map [outa] -vcodec libx264 -crf 27 -preset ultrafast -threads 2 out.mp4

but this time I got error:

Input link in1:v0 parameters (size 1920x808, SAR 0:1) do not match the corresponding output link in0:v0 parameters (1920x808, SAR 3232:3231)

I don't understand why?

Any ideas anyone?

Many thanks in advance.

回答1:

The concat filters require all segments to have the same properties, including aspect ratio. You can tell the filter to ignore that

concat=n=2:v=1:a=1:unsafe=1 (not recommended)

or set same aspect ratio for both video streams,

ffmpeg -i b.mkv -i a.mp4
-f lavfi -t 0.1 -i anullsrc
-filter_complex
[0:v]scale=1920:808:force_original_aspect_ratio=decrease,pad=1920:808:(ow-iw)/2:(oh-ih)/2,setsar=1[v0];
[1:v]setsar=1[v1];[v0][0:a][v1][1:a]concat=n=2:v=1:a=1[outv][outa]
-map [outv] -map [outa] -vcodec libx264 -crf 27
-preset ultrafast -threads 2 out.mp4


标签: ffmpeg