A commandline tool to Merge videos

royalmemer

Junior Member
Joined
Feb 24, 2022
Messages
125
Reaction score
51
Does anyone know or have a tool/utility which can merge videos.
Example: I want to merge all videos in a folder which have different resolution and FPS.
I have tried all possible ffmpeg and moviepy solutions on stackoverflow and other sites but no luck.
If anyone has an idea or a reference about a similar tool that would really help!! :)
 
yeah its handbrake or ffmpeg, but the issue ur trying is that ur wanting it all done with 1 command line(yes i know u can do multiple things in 1 command line, but annoying).
i dont know the command line but someone else googling can always help.
firstly:
frames
ffmpeg -i in -vf "setpts=PTS/6,fps=30" -af "atempo=6" out

aspect ratio
ffmpeg -i in -vf scale=720x406,setdar=16:9 out


EDIT: but looks like someone found the solution to do everything at once(even with different aspect ratio)
https://stackoverflow.com/a/11175851/3355246
 
yeah its handbrake or ffmpeg, but the issue ur trying is that ur wanting it all done with 1 command line(yes i know u can do multiple things in 1 command line, but annoying).
i dont know the command line but someone else googling can always help.
firstly:
frames
ffmpeg -i in -vf "setpts=PTS/6,fps=30" -af "atempo=6" out

aspect ratio
ffmpeg -i in -vf scale=720x406,setdar=16:9 out


EDIT: but looks like someone found the solution to do everything at once(even with different aspect ratio)
https://stackoverflow.com/a/11175851/3355246
Thanks for the inputs. This command: ffmpeg -i in -vf scale=720x406,setdar=16:9 out you mentioned makes my video stretch and look ugly. I tried changing scale and setdar but no luck. Can you help me with that. :)

I have one video with resolution: 576x806
and second with resolution: 1920x1080
 
Just found these commands on BHW which does work for merging 2 videos:
Can someone help me modify these commands to merge like 20 videos at once:

//Add intro - main - outro
ffmpeg -y -i intro.mp4 -i input.mp4 -i outro.mp4 -filter_complex "[1:v]scale=1280:720,setdar=16/9 [vmain]; [1:a]volume=1.6 [amain]; [0:v]scale=1280:720,setdar=16/9 [vintro]; [2:v]scale=1280:720 [voutro]; [vintro][0:a][vmain][amain][voutro][2:a]concat=n=3:v=1:a=1" -vcodec libx264 -pix_fmt yuv420p -r 30 -g 60 -b:v 1400k -profile:v main -level 3.1 -acodec libmp3lame -b:a 128k -ar 44100 -bufsize 500000k -preset superfast output.mp4

//Add intro - main
ffmpeg -y -i intro.mp4 -i input.mp4 -filter_complex "[1:v]scale=1280:720,setdar=16/9 [vmain]; [1:a]volume=1.6 [amain]; [0:v]scale=1280:720,setdar=16/9 [vintro]; [vintro][0:a][vmain][amain]concat=n=2:v=1:a=1" -vcodec libx264 -pix_fmt yuv420p -r 30 -g 60 -b:v 1400k -profile:v main -level 3.1 -acodec libmp3lame -b:a 128k -ar 44100 -preset superfast output.mp4

//Add main - outro
ffmpeg -y -i outro.mp4 -i input.mp4 -filter_complex "[1:v]scale=1280:720,setdar=16/9 [vmain]; [1:a]volume=1.6 [amain]; [0:v]scale=1280:720,setdar=16/9 [voutro]; [vmain][amain][voutro][0:a]concat=n=2:v=1:a=1" -vcodec libx264 -pix_fmt yuv420p -r 30 -g 60 -b:v 1400k -profile:v main -level 3.1 -acodec libmp3lame -b:a 128k -ar 44100 -preset superfast output.mp4
 
The videos will get stretched, if they aren't the same aspect ratio. If you pick a resolution for the final video, such as the 1920x1080 (1080p), the aspect ratio is 16:9. You can merge two 16:9 videos with different resolution without distortion, e.g. an 1080p video with a 720p video. If you don't want the 720p video to look blurry in the final video, you need to downscale the 1080p video and not upscale the 720p.
This would be easy, but since the resolution and aspect ratio of your videos vary greatly, it will be tricky.

I have one video with resolution: 576x806
and second with resolution: 1920x1080
Those two resolutions aren't even the same orientation. The 1080p is landscape, the other one is a portrait mode video. How would you exactly imagine those being merged without distortion?

One thing you can do is add black borders to the smaller resolution, non-16:9 videos, so they become 16:9 aspect ratio. They will still look iffy in the final video, if the resolution is too low compared to 1080p. So probably don't pick 1080p resolution for the final video, only 720p (1280x720).

Do the commands in your last post solve the aspect ratio issue, so the videos aren't getting stretched? It wasn't yesterday, when i used ffmpeg past and i don't exactly understand everything in the code. Is it adding the black borders or maybe putting the smaller resolution videos to the center of the 720p canvas, so they aren't getting stretched?
 
The "adding black border" part was good suggestion. I used this command to do it:

ffmpeg -i 1.mp4 -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,setsar=1" look.mp4

How to make this command fast, any idea/improvement to this command.
I dont know why the emojis are coming when I paste the command above: here is the screenshot
1653044946574.png
 
Last edited:
Back
Top