I'd like to use ffmpeg to extract everything from the 20 second to 25 second mark and then the 50 second to 65 second mark of a video, and take those two 5 second clips, concatenate them, and output a 10 second clip.

I know it can be done in three separate commands, but I'm wondering if there's a single ffmpeg command that could do the same?


1 Answer 1


Basic method is

ffmpeg -i video -vf "select='between(t,20,25)+between(t,50,55)',setpts=N/FRAME_RATE/TB" -af "aselect='between(t,20,25)+between(t,50,55)',asetpts=N/SR/TB" out.mp4

  • Perfect, thanks! I didn't know about the setpts/asetpts parameters. Seems like that's needed to preserve the timestamps correctly for some reason? Would you mind elaborating on why that's needed?
    – Zain R
    Commented Mar 1, 2020 at 8:41
  • 1
    The pts filters are needed to make timestamps smooth since the segments selected are discontinuous in the input stream.
    – Gyan
    Commented Mar 1, 2020 at 13:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .