I have a video called 1.mp4
I want to extract 17+17= 34 total clips from this video with one FFmpeg command
Each clip should have a unique name like 1a 1b 1c 1d and so on.
17 clips will have a 1920x1080 dimension and remaining 17 will have 720x720 dimension
I will appreciate if someone can help me to do this. It will save my several hours.
Asked
Active
Viewed 1,074 times
-2

jayp
- 192
- 2
- 13

Gabbar Singh
- 1
- 1
-
Will your inputs always be the same size, or will they be arbitrary? Do you need the audio? Should the video be cropped or padded to fit 1920x1080 and 720x720? – llogan Jun 16 '21 at 16:55
-
1. Every morning I get video in 1920 x 1080 dimension 2. This dimension suits to my client's youtube channel hence I just have to trim it with given timestamps 3. The same video has to go on twitter with different dimension (700x700) i.e. 1:1 ratio 4. Same video has to go on instagram with different dimension (1080x1920) Thanks in advance for your help. – Gabbar Singh Jun 17 '21 at 16:54
1 Answers
2
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

llogan
- 121,796
- 28
- 232
- 243
-
I am amazed with this reply. This is the first time I have used stack exchange and I think I got what I want. I am from creative background and have no experience of coding. I will be really thankful of you, if you could help me to design this command in such a way I can supply inputs in HH:MM:FF (Hour:Minutes:Frames) format, – Gabbar Singh Jun 20 '21 at 09:56
-
One more request please give command in one line (without breaking / pressing enter button) when I copy that command in notepad it doesn't come the way as it should. – Gabbar Singh Jun 20 '21 at 10:08
-
Is it possible to apply the same scaling and cropping settings to all segments without repeating this for each segment, or even for each output video? For example I want to do a cut-and-merge similar to above for multiple segments, and my original command has: -filter:v "scale='min(480,iw)':-2:flags=lanczos,fps=15" -pix_fmt yuv420p -c:v libx264 -preset slow -crf 22 – Display Name Jul 10 '23 at 02:04