Search code examples
ffmpeg

FFmpeg command to trim lavfi ignores start


Why doesn't this ffmpeg command generate 1 second video, but 5 seconds?

If I modify end parameter of trim filter, the length changes, but it looks like ffmpeg is ignoring the start parameter.

ffmpeg -f lavfi -i color=blue@1:640x480:d=60,format=rgba -filter_complex "[0]trim=start=4.0:end=5.0[s0]" -map "[s0]" -y  trim.mp4

Solution

  • The output is correct. However, since timestamps aren't reset to start from zero, most apps will compute duration values based on the final timestamp value, and may even show a 'freeze' or black till the first timestamp.

    Reset timestamp by using the setpts filter.

    ffmpeg -f lavfi -i color=blue@1:640x480:d=60,format=rgba -filter_complex "[0]trim=start=4.0:end=5.0,setpts=PTS-STARTPTS[s0]" -map "[s0]" -y trim.mp4