M€rging videos with different dimensions, ffmpeg and scaling?

Just have a drink and chat
postcd
Blank Cone
Blank Cone
Posts: 21
Joined: 18 Feb 2016 16:09

M€rging videos with different dimensions, ffmpeg and scaling?

Postby postcd » 17 Jun 2021 18:15

Hello,
i spent hours trying to figure out how to m€rg€ numerous files with different dimensions and asp€ct rati0s.
My result so far is to recode video files 1.mp4 and 2.mp4 like this:
A) method where i scale both files in attempt to match the normalize dimensions of both segments:
cd videosdir;
for i in 1 2; do ffmpeg -i $i.mp4 -vf "scale=576:-2,setdar=4:3,setsar=1" "$i"sdarsar1.mp4; done
Seems to be working to merge files (i am using LosslessCut/Tools/Merge menu item), aspect quite ok on merged files, but downscaled the first segment of the video file too much as you can see on the left side of the following image.
B) or command without scaling filter:
cd videosdir;
for i in 1 2; do ffmpeg -i $i.mp4 -vf "setdar=4:3,setsar=1" "$i"sdarsar1.mp4; done

Resulting merged file (scaling on the left, no scaling on the right):
Image
Some more details about source and resulting files dimensions and aspect is also here.

Do you have idea how to best process the files so the aspect r@tios are same as original and the dimensions as similar or same as possible?

postcd
Blank Cone
Blank Cone
Posts: 21
Joined: 18 Feb 2016 16:09

Re: M€rging videos with different dimensions, ffmpeg and scaling?

Postby postcd » 17 Aug 2021 09:59

This forum is stupidly set not to allow editing of my post, so i am bumping the topic with an update:

what may work is following ffmpeg parameters:

Code: Select all

-vf "scale=640|480"
numbers are just an example, in my case i was re encoding using -c:v libx264
if merging multiple videos, it seems to be least effort to re encode (means quality loss) all using same parameters:

Code: Select all

-f mp4 -rc_mode 1 -qp "26" -r "$vfps" -c:a aac -ar "$sr"000
-qp "26" is some quality factor, lower value should mean better quality and bigger file size
$vfps is the target fps of the video (example 25)
"$sr"000 is the target Hz value for audio track, usually 48000 or 44000
(i may be wrong above and there are certainly other/better ways and i welcome if shared)


Return to “Coffee Corner”

Who is online

Users browsing this forum: No registered users and 40 guests