Warm tip: This article is reproduced from serverfault.com, please click

ffmpeg cut a video + make a rescaled preview (proxie)

发布于 2020-12-03 09:54:17

I would like to cut (mulicut if possible else it's ok) a mp4 and generate the cut + a preview file in 360p.

My goal is to achieve something that looks like that :

`ffmpeg -y -progress /dev/stdout -i media.mp4
-vf "select='+between(t,0,25)',setpts=N/FRAME_RATE/TB"
-af "aselect='+between(t,0,25)’,asetpts=N/SR/TB"
-filter_complex split=2[mvideo][pvideo]
-map [mvideo] media_cut.mp4
-map [pvideo] -vf scale=-1:360 media_preview.mp4`

Here, a first -vf select filter to multicut the media, a split filter to generate both the cut media and a resized cut with a second -vf on scale that keep aspect ratio with a width of 360.

I can't mix filter with filter complex that's why i have no idea how to do it.

Thanks a lot for your tips.

Questioner
Hugo Monsieur
Viewed
0
Gyan 2020-12-03 20:37:42

You can do it one of two ways. 1) declare simple filtergraph for each output, or 2) do all filtering inside a complex filtergraph.

#1 Per-output simple filtergraph.

ffmpeg -y -progress /dev/stdout -i media.mp4
-vf "select='between(t,0,25)',setpts=N/FRAME_RATE/TB"
-af "aselect='between(t,0,25)’,asetpts=N/SR/TB"
media_cut.mp4
-vf "select='between(t,0,25)',setpts=N/FRAME_RATE/TB,scale=-2:360"
-af "aselect='between(t,0,25)’,asetpts=N/SR/TB"
media_preview.mp4

#2 A complex filtergraph.

ffmpeg -y -progress /dev/stdout -i media.mp4
-filter_complex
"[0:v]select='between(t,0,25)',setpts=N/FRAME_RATE/TB,split=2[mvideo][pvideo];
 [pvideo]scale=-2:360[pvideo];
 [0:a]aselect='between(t,0,25)’,asetpts=N/SR/TB,asplit=2[maudio][paudio]"
-map [mvideo] -map [maudio]
media_cut.mp4
-map [pvideo] -map [paudio]
media_preview.mp4