Hi!
Wanted to make a video out of multiple trimmed input videos (same video of input)
I'm trying this:
import ffmpeg
inp = ffmpeg.input('video.mkv')
out = ffmpeg.concat(
*[
inp.video.trim(start=50, end=51).setpts('PTS-STARTPTS'),
inp.audio.filter('atrim', start=50, end=51).filter('asetpts', expr='PTS-STARTPTS')
],
v=1, a=1
).output('out.mkv')
out.run()
this does work for trimming video and audio and creating an output, but if I wanted to make a loop on this portion of video using list multiplication:
out = ffmpeg.concat(
*[
inp.video.trim(start=50, end=51).setpts('PTS-STARTPTS'),
inp.audio.filter('atrim', start=50, end=51).filter('asetpts', expr='PTS-STARTPTS')
]*2,
v=1, a=1
).output('out.mkv')
I got:
ValueError: Encountered setpts('PTS-STARTPTS') <11a03426e6b6> with multiple outgoing edges with same upstream label None; a `split` filter is probably required
as I was reading in docs, using filter_multi_output allow us to have multiple streams of the same input, so I tried with something simple:
import ffmpeg
inp = ffmpeg.input('video.mkv').filter_multi_output('split')
out = ffmpeg.concat(
*[
inp.stream(0).video.trim(start=10, end=11).setpts('PTS-STARTPTS'),
inp.stream(0).audio.filter('atrim', start=10, end=11).filter('asetpts',expr='PTS-STARTPTS')
],
v=1, a=1
).output('out.mkv')
out.run()
but I got the same error.
How can I achieve this ?
nevermind I figured it out
thanks, you guys are my heros
import ffmpeg
import random
inp = ffmpeg.input('video.mkv')
# just split over video and audio, audio SHOULD use asplit instead of split
vid = inp.video.filter_multi_output('split')
aud = inp.audio.filter_multi_output('asplit')
# this is just for acumulating the trimmed videos
outs = []
# 500 pieces of videos / audios
for k in range(500):
x = random.randint(10,500)
v = vid[k].trim(start=x, end=x+0.05).setpts('PTS-STARTPTS')
a = aud[k].filter('atrim', start=x, end=x+0.05).filter('asetpts',expr='PTS-STARTPTS')
outs.extend((v, a))
out = ffmpeg.concat(
*outs,
v=1,
a=1
).output('out.mkv')
out = ffmpeg.overwrite_output(out)
out.run()
thanks for making such a nice project :+1:
Most helpful comment
nevermind I figured it out
thanks, you guys are my heros
thanks for making such a nice project :+1: