1

I am trying to create a video from two videos that will be stacked horizontally, but the resulting video is not what I expected. The same video is appearing on both sides (left and right). How can that be achieved?

The ffmpeg command I tried, which kind of worked:

ffmpeg -i left.mp4 -i right.mp4 -filter_complex "
[0:v]setpts=PTS-STARTPTS[l];
[1:v]setpts=PTS-STARTPTS,tpad=start_duration=14:start_mode=add:color=black[r];
[l][r]hstack=inputs=2[stacked]; [0:a][1:a]amix=inputs=2[a]
" -map "[stacked]" -map "[a]" -c:a aac -preset superfast result.mp4

The ffmpeg-python script that's not working:

in0 = ffmpeg.input('0.mp4')
in1 = ffmpeg.input('right.mkv')
aout = ffmpeg.filter([in0.audio, in1.audio.filter('adelay', "5000|5000")],'amix')
vout = ffmpeg.filter([inv0.video, inv1.video.filter('tpad', start_duration=5, start_mode='add', color='black')], 'hstack')

(
    ffmpeg
    .concat(vout, aout, v=1, a=1)
    .output("out.mkv")
    .run()
)

This script is not resulting in the expected output which is two videos side-by-side horizontally stacked.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kup
  • 731
  • 5
  • 18
  • I think it should be `in0.video, in1.video` instead of `inv0.video, inv1.video`. Beside that, your code sample is working. Make sure the vertical resolution of `0.mp4` and `right.mkv` is the same. In case it's still not working, try to post a reproducible code sample (build synthetic pattern videos to be used as input). – Rotem Jul 29 '21 at 20:38
  • @Rotem (in0,in1) and (in0.video, inv1.video) both is working for me and yes 0.mp4 has different dimension than right.mkv, so that's working now but i don't want to use concat, that is just a workaround i found, i want to use "[0:a][1:a]amix=inputs=2[a]" as shown in above ffmpeg command can it be done without using concat? – kup Jul 30 '21 at 05:50
  • 1
    Instead of using `concat`, you can place `aout` and `vout` as the first arguments of the `output`: `ffmpeg.output(aout, vout, "out.mkv").run()` – Rotem Jul 30 '21 at 08:05

0 Answers0