Skip to main content

concat filter

This method is best if you need to perform additional filtering:

Use the trim, atrim, setpts, asetpts, and concat filters:

ffmpeg -i input -filter_complex \
"[0:v]trim=60:65,setpts=PTS-STARTPTS[v0]; \
 [0:a]atrim=60:65,asetpts=PTS-STARTPTS[a0]; \
 [0:v]trim=120:125,setpts=PTS-STARTPTS[v1];
 [0:a]atrim=120:125,asetpts=PTS-STARTPTS[a1]; \
 [v0][a0][v1][a1]concat=n=2:v=1:a=1[out]" \
-map "[out]" output.mkv
ffmpeg -i input -filter_complex \
"[0:v]trim=60:65,setpts=PTS-STARTPTS[v0]; \
 [0:a]atrim=60:65,asetpts=PTS-STARTPTS[a0]; \
 [0:v]trim=120:125,setpts=PTS-STARTPTS[v1];
 [0:a]atrim=120:125,asetpts=PTS-STARTPTS[a1]; \
 [v0][a0][v1][a1]concat=n=2:v=1:a=1[out]" \
-map "[out]" output.mkv
  • setpts and asetpts will prevent a jerky output due to presentation timestamp issues.

  • Make sure to use a recent version. See the FFmpeg Download page for links to builds for Windows, OS X, and Linux.


concat demuxer

Another method is to to create the segments individually and stream copy them instead of re-encoding (to save time and quality), and join them with the concat demuxer.

$ ffmpeg -ss 60 -i input -t 5 -codec copy clip1.mkv
$ ffmpeg -ss 120 -i input -t 5 -codec copy clip2.mkv
$ echo "file 'clip1.mkv'" > concat.txt
$ echo "file 'clip2.mkv'" >> concat.txt
$ ffmpeg -f concat -i concat.txt -codec copy output.mkv
$ ffmpeg -ss 60 -i input -t 5 -codec copy clip1.mkv
$ ffmpeg -ss 120 -i input -t 5 -codec copy clip2.mkv
$ echo "file 'clip1.mkv'" > concat.txt
$ echo "file 'clip2.mkv'" >> concat.txt
$ ffmpeg -f concat -i concat.txt -codec copy output.mkv

concat filter

This method is best if you need to perform additional filtering:

Use the trim, atrim, setpts, asetpts, and concat filters:

ffmpeg -i input -filter_complex \
"[0:v]trim=60:65,setpts=PTS-STARTPTS[v0]; \
 [0:a]atrim=60:65,asetpts=PTS-STARTPTS[a0]; \
 [0:v]trim=120:125,setpts=PTS-STARTPTS[v1];
 [0:a]atrim=120:125,asetpts=PTS-STARTPTS[a1]; \
 [v0][a0][v1][a1]concat=n=2:v=1:a=1[out]" \
-map "[out]" output.mkv
  • setpts and asetpts will prevent a jerky output due to presentation timestamp issues.

  • Make sure to use a recent version. See the FFmpeg Download page for links to builds for Windows, OS X, and Linux.


concat demuxer

Another method is to to create the segments individually and stream copy them instead of re-encoding (to save time and quality), and join them with the concat demuxer.

$ ffmpeg -ss 60 -i input -t 5 -codec copy clip1.mkv
$ ffmpeg -ss 120 -i input -t 5 -codec copy clip2.mkv
$ echo "file 'clip1.mkv'" > concat.txt
$ echo "file 'clip2.mkv'" >> concat.txt
$ ffmpeg -f concat -i concat.txt -codec copy output.mkv

concat filter

This method is best if you need to perform additional filtering:

Use the trim, atrim, setpts, asetpts, and concat filters:

ffmpeg -i input -filter_complex \
"[0:v]trim=60:65,setpts=PTS-STARTPTS[v0]; \
 [0:a]atrim=60:65,asetpts=PTS-STARTPTS[a0]; \
 [0:v]trim=120:125,setpts=PTS-STARTPTS[v1];
 [0:a]atrim=120:125,asetpts=PTS-STARTPTS[a1]; \
 [v0][a0][v1][a1]concat=n=2:v=1:a=1[out]" \
-map "[out]" output.mkv
  • setpts and asetpts will prevent a jerky output due to presentation timestamp issues.

  • Make sure to use a recent version. See the FFmpeg Download page for links to builds for Windows, OS X, and Linux.


concat demuxer

Another method is to to create the segments individually and stream copy them instead of re-encoding (to save time and quality), and join them with the concat demuxer.

$ ffmpeg -ss 60 -i input -t 5 -codec copy clip1.mkv
$ ffmpeg -ss 120 -i input -t 5 -codec copy clip2.mkv
$ echo "file 'clip1.mkv'" > concat.txt
$ echo "file 'clip2.mkv'" >> concat.txt
$ ffmpeg -f concat -i concat.txt -codec copy output.mkv
added 424 characters in body
Source Link
llogan
  • 10.3k
  • 2
  • 46
  • 58

concat filter

This method is best if you need to perform additional filtering:

Use the trim, atrim, setpts, asetpts, and concat filters:

ffmpeg -i input -filter_complex \
"[0:v]trim=60:65,setpts=PTS-STARTPTS[v0]; \
 [0:a]atrim=60:65,asetpts=PTS-STARTPTS[a0]; \
 [0:v]trim=120:125,setpts=PTS-STARTPTS[v1];
 [0:a]atrim=120:125,asetpts=PTS-STARTPTS[a1]; \
 [v0][a0][v1][a1]concat=n=2:v=1:a=1[out]" \
-map "[out]" output.mkv
  • setpts and asetpts will prevent a jerky output due to presentation timestamp issues.

  • Make sure to use a recent version. See the FFmpeg Download page for links to builds for Windows, OS X, and Linux.

  • If you wanted to create the segments individually for some reason you can stream copy them instead of re-encoding to save time and quality ffmpeg -ss 60 -i input -t 5 -codec copy output.mkv


concat demuxer

Another method is to to create the segments individually and stream copy them instead of re-encoding (to save time and quality), and join them with the concat demuxer.

$ ffmpeg -ss 60 -i input -t 5 -codec copy clip1.mkv
$ ffmpeg -ss 120 -i input -t 5 -codec copy clip2.mkv
$ echo "file 'clip1.mkv'" > concat.txt
$ echo "file 'clip2.mkv'" >> concat.txt
$ ffmpeg -f concat -i concat.txt -codec copy output.mkv

Use the trim, atrim, setpts, asetpts, and concat filters:

ffmpeg -i input -filter_complex \
"[0:v]trim=60:65,setpts=PTS-STARTPTS[v0]; \
 [0:a]atrim=60:65,asetpts=PTS-STARTPTS[a0]; \
 [0:v]trim=120:125,setpts=PTS-STARTPTS[v1];
 [0:a]atrim=120:125,asetpts=PTS-STARTPTS[a1]; \
 [v0][a0][v1][a1]concat=n=2:v=1:a=1[out]" \
-map "[out]" output.mkv
  • setpts and asetpts will prevent a jerky output due to presentation timestamp issues.

  • Make sure to use a recent version. See the FFmpeg Download page for links to builds for Windows, OS X, and Linux.

  • If you wanted to create the segments individually for some reason you can stream copy them instead of re-encoding to save time and quality ffmpeg -ss 60 -i input -t 5 -codec copy output.mkv

concat filter

This method is best if you need to perform additional filtering:

Use the trim, atrim, setpts, asetpts, and concat filters:

ffmpeg -i input -filter_complex \
"[0:v]trim=60:65,setpts=PTS-STARTPTS[v0]; \
 [0:a]atrim=60:65,asetpts=PTS-STARTPTS[a0]; \
 [0:v]trim=120:125,setpts=PTS-STARTPTS[v1];
 [0:a]atrim=120:125,asetpts=PTS-STARTPTS[a1]; \
 [v0][a0][v1][a1]concat=n=2:v=1:a=1[out]" \
-map "[out]" output.mkv
  • setpts and asetpts will prevent a jerky output due to presentation timestamp issues.

  • Make sure to use a recent version. See the FFmpeg Download page for links to builds for Windows, OS X, and Linux.


concat demuxer

Another method is to to create the segments individually and stream copy them instead of re-encoding (to save time and quality), and join them with the concat demuxer.

$ ffmpeg -ss 60 -i input -t 5 -codec copy clip1.mkv
$ ffmpeg -ss 120 -i input -t 5 -codec copy clip2.mkv
$ echo "file 'clip1.mkv'" > concat.txt
$ echo "file 'clip2.mkv'" >> concat.txt
$ ffmpeg -f concat -i concat.txt -codec copy output.mkv
Source Link
llogan
  • 10.3k
  • 2
  • 46
  • 58

Use the trim, atrim, setpts, asetpts, and concat filters:

ffmpeg -i input -filter_complex \
"[0:v]trim=60:65,setpts=PTS-STARTPTS[v0]; \
 [0:a]atrim=60:65,asetpts=PTS-STARTPTS[a0]; \
 [0:v]trim=120:125,setpts=PTS-STARTPTS[v1];
 [0:a]atrim=120:125,asetpts=PTS-STARTPTS[a1]; \
 [v0][a0][v1][a1]concat=n=2:v=1:a=1[out]" \
-map "[out]" output.mkv
  • setpts and asetpts will prevent a jerky output due to presentation timestamp issues.

  • Make sure to use a recent version. See the FFmpeg Download page for links to builds for Windows, OS X, and Linux.

  • If you wanted to create the segments individually for some reason you can stream copy them instead of re-encoding to save time and quality ffmpeg -ss 60 -i input -t 5 -codec copy output.mkv