Gabbar Singh
Gabbar Singh

Reputation: 1

Trim multiple clips with one command of FFmpeg

  1. I have a video called 1.mp4

  2. I want to extract 17+17= 34 total clips from this video with one FFmpeg command

  3. Each clip should have a unique name like 1a 1b 1c 1d and so on.

  4. 17 clips will have a 1920x1080 dimension and remaining 17 will have 720x720 dimension

  5. I will appreciate if someone can help me to do this. It will save my several hours.

Upvotes: -2

Views: 2153

Answers (1)

llogan
llogan

Reputation: 133863

Adapt this shortened example for 2+2 outputs:

ffmpeg -i input.mp4 -filter_complex
"[0:v]trim=start=0:end=3,setpts=PTS-STARTPTS,split[va1][vb1];
 [0:v]trim=start=5:end=10,setpts=PTS-STARTPTS,split[va2][vb2];
 [0:a]atrim=start=0:end=3,asetpts=PTS-STARTPTS,asplit[aa1][ab1];
 [0:a]atrim=start=5:end=10,asetpts=PTS-STARTPTS,asplit[aa2][ab2];
 [va1]scale=700:700:force_original_aspect_ratio=increase,crop=700:700[700_1];
 [va2]scale=700:700:force_original_aspect_ratio=increase,crop=700:700[700_2];
 [vb1]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920[1920_1];
 [vb2]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920[1920_2]"
-map "[700_1]"  -map "[aa1]" 1a.mp4
-map "[700_2]"  -map "[aa2]" 1b.mp4
-map "[1920_1]" -map "[ab1]" 2a.mp4
-map "[1920_2]" -map "[ab2]" 2b.mp4
  • Command was split into multiple lines so you can read it easier. Make it one long line before executing.
  • See Resizing videos with ffmpeg to fit specific size for other options if you don't like the crop-to-fit.
  • The filter labels, such as [va1], are arbitrary and you can use whatever label names you prefer.

These filters are used:

  • (a)trim - to trim the video/audio
  • (a)setpts - to reset timestamps
  • (a)split - to make copies of the trimmed stream for the two different output sizes so you only have to trim once per clip
  • scale - to scale the video
  • crop - to crop the video

Upvotes: 2

Related Questions