How to compose 2 videos by using FFmpeg hstack fil

2019-03-02 13:36发布

问题:

I want to compose 2 videos into 1 video by putting side by side. I also hope to set start/stop time for each video. Final video should be H264/AAC codec and mp4 format. I attached sample videos. https://www.dropbox.com/s/e5eouyrrqsy44ts/1.webm?dl=0 https://www.dropbox.com/s/u0zqie0icxamt3q/2.webm?dl=0

I used the following ffmpeg command.

ffmpeg -i 1.webm -i 2.webm -filter_complex "[0:v][1:v]hstack" output.mp4

When I run this command on Terminal of Mac OS X 10.11, It gave me the following error.

Input 1 height 480 does not match input 0 height.

The video are from smartphone, so its orientation is not correct. Please help me to make composed video with FFmpeg.

回答1:

For this set of videos, you need

ffmpeg -i 1.webm -i 2.webm -filter_complex "[0:v]scale=480:640,setsar=1[l];[1:v]scale=480:640,setsar=1[r];[l][r]hstack;[0][1]amix" -vsync 0 output.mp4

The writing application hasn't written the stream attributes correctly. The videos should be tagged as 480x640. It's not about a missing rotation tag, as the frame context changes.



标签: ffmpeg