Nouh LC
Nouh LC

Reputation: 31

Merge two video side by side ffmpeg

I´m working on project android with ffmpeg who can merge two videos side by side and i have a problem for example the first video has 20 seconds and the second has 35 seconds when i merge them i got video has 35 seconds everytime video got the large time but i want the small in above exmaple i want the output video has 20 seconds not 35. my shot

"-i","firsth.mp4","-i","second.mp4","-filter_complex","[0:v]scale=480:640,setsar=1[l];[1:v]scale=480:640,setsar=1[r];[l][r]hstack","-c:v","libx264","-crf","23","-preset","veryfast myoutput.mp4"

Upvotes: 1

Views: 2417

Answers (2)

MichaelsonBritt
MichaelsonBritt

Reputation: 986

This could be done with a batch script. Get the duration of both videos using the ffmpeg -i first.mp4 as discussed here. Then, calculate the lower of the two values, and pass that time as the -t parameter when creating the video, which limits the duration of the output. Command-line parameters are described here. You will have to format the time as a time duration specification, described here.

Upvotes: 0

llogan
llogan

Reputation: 134293

Use the shortest option in hstack:

"-i","firsth.mp4","-i","second.mp4","-filter_complex","[0:v]scale=480:640,setsar=1[l];[1:v]scale=480:640,setsar=1[r];[l][r]hstack=shortest=1","-c:v","libx264","-crf","23","-preset","veryfast","myoutput.mp4"

Upvotes: 3

Related Questions