kkroening / ffmpeg-python

Python bindings for FFmpeg - with complex filtering support
Apache License 2.0
9.87k stars 883 forks source link

concat with the same video multiple time #186

Open lc-thomas opened 5 years ago

lc-thomas commented 5 years ago

Hi

I'd like to build videos with transitions. Like : Intro - Clip1 - Transition - Clip2 - Transition - Clip3 - Outro The transition video is always the same one.

But when I put twice the same video in ffmpeg.concat(), the generated ffmpeg command hangs, it doesn't work.

This code :

infiles = []

ffmpeg_transition_clip = ffmpeg.input('/tmp/resized_transition.mp4')
transition_v = ffmpeg_transition_clip['v']
transition_a = ffmpeg_transition_clip['a']
infiles.append(transition_v)
infiles.append(transition_a)
infiles.append(transition_v)
infiles.append(transition_a)

concatened = ffmpeg.concat(*infiles, n=len(infiles)/2, v=1, a=1).node
v = concatened[0]
a = concatened[1]
output = ffmpeg.output(v, f'output/test.mp4', threads=4).overwrite_output()

Generates this command :

ffmpeg -i /tmp/resized_transition.mp4 -filter_complex [0:v][0:a][0:v][0:a]concat=a=1:n=2:v=1[s0] -map [s0] -threads 4 output/test.mp4 -y

Which hangs as well.

Changing it to this :

ffmpeg -i /tmp/resized_transition.mp4 -i /tmp/resized_transition.mp4 -filter_complex [0:v][0:a][1:v][1:a]concat=a=1:n=2:v=1[s0] -map [s0] -threads 4 output/test.mp4 -y

It works.

How can I do that using ffmpeg-python ?

Thank you !

julienbeisel commented 2 years ago

@Guisch I'm late to the party but thank you so much for figuring this out!

I spent 30mn debugging my code without knowing what to do.