Reputation: 11734
I've been trimming some videos recently using ffmpeg, and I've noticed that as the trim position increases, the time taken to trim the video also increases.Even if the duration is same. (5 seconds)
Below given the command to trim the video from 0
to 5
seconds, and it takes only 1 second to process.
ffmpeg -y \
-i input.mp4 \
-filter_complex \
"[0:v]trim=0:5,setpts=PTS-STARTPTS[v0];
[0:a]atrim=0:5, asetpts=PTS-STARTPTS[a0]
" -map "[v0]" -map "[a0]" output.mp4
But when I try to trim the video with exact same command, but with different index, from 300
second to 305
, it takes 5 seconds
.
ffmpeg -y \
-i input.mp4 \
-filter_complex \
"[0:v]trim=300:305,setpts=PTS-STARTPTS[v0];
[0:a]atrim=300:305, asetpts=PTS-STARTPTS[a0]
" -map "[v0]" -map "[a0]" output.mp4
So here are my questions
Upvotes: 0
Views: 384
Reputation: 92928
You are trimming the streams using filters, so all frames from the start of the file till the trim points still have to be decoded in order to be trimmed.
For MP4 files, perform an input seek, which will only pull frames from the closest keyframe. No need to use filters either since all trimming and timestamp reset happens via input switches.
ffmpeg -y -ss 300 -to 305 -i input.mp4 -map 0:v -map 0:a output.mp4
Upvotes: 1