Reputation: 1156
In my scenario, I would like to trim the source video and loop it for specified times. And below is my code
ffmpeg -i source.mp4 -filter_complex "[0:v]trim=start=6:end=46,loop=5[vf];[0:a]atrim=start=6:end=46,aloop=5[af]" -map "[vf]" -map "[af]" output.mp4 -y
For this I have to get 200 seconds video as a output.mp4. But I got video with 40 seconds duration.
Upvotes: 1
Views: 1240
Reputation: 50815
You need to specify the maximum number of frames/samples to loop in your loop
and aloop
filters, because it is set to 0 by default. For example;
[0:v] loop = '5 : 10'
outputs [0:v]
unchanged and followed by the first 10 frames of it looped 5 times. And don't forget to fix timestamps of trimmed output.
So, what you want to do can be achieved using this filter (assuming input frame rate is 30fps and sample rate is 48k/s)
[0:v] trim = 'start = 6 : end = 46',
setpts = 'PTS - STARTPTS',
loop = 'loop = 4 : size = 40 * 30' [vf];
[0:a] atrim = 'start = 6 : end = 46',
asetpts = 'PTS - STARTPTS',
aloop = 'loop = 4 : size = 40 * 48000' [af]
Upvotes: 1