4

I have an ffmpeg command using -vf to square crop a video:

ffmpeg -i input.mp4 -vf \
"crop='if(gte(iw,ih),ih,iw):if(gte(ih,iw),iw,ih)', scale=720x720" \
-an -c:v libx264 -profile:v high -level 4.1 \
-preset superfast -crf 20 output.mp4

I also have a separate ffmpeg command using -filter_complex to apply a slow motion "profile" (normal speed, then slow, then normal speed) to a video:

ffmpeg -i input.mp4 -filter_complex \
"[0:v]trim=0:4.95,setpts=PTS-STARTPTS[v1]; \
 [0:v]trim=4.95:6.75,setpts=PTS-STARTPTS[v2]; \
 [0:v]trim=6.75:8,setpts=PTS-STARTPTS[v3]; \
 [v2]setpts=PTS/0.1[vslow2]; \
 [v1][vslow2][v3]concat=n=3:v=1:a=0[out]" \
-map [out] -an -c:v libx264 -profile:v high -level 4.1 \
-preset superfast -crf 20 -r 30 output.mp4

If I try and put them together:

ffmpeg -i input.mp4 -vf "crop='if(gte(iw,ih),ih,iw):if(gte(ih,iw),iw,ih)', scale=720x720" \
-filter_complex \
"[0:v]trim=0:4.95,setpts=PTS-STARTPTS[v1]; \
 [0:v]trim=4.95:6.75,setpts=PTS-STARTPTS[v2]; \
 [0:v]trim=6.75:8,setpts=PTS-STARTPTS[v3]; \
 [v2]setpts=PTS/0.1[vslow2]; \
 [v1][vslow2][v3]concat=n=3:v=1:a=0[out]" \
-map [out] -an -c:v libx264 -profile:v high -level 4.1 \
-preset superfast -crf 20 -r 30 output.mp4

I then get:

-vf/-af/-filter and -filter_complex cannot be used together for the same stream.

Is there a way of applying the crop filter to the entire stream, or will I have to apply it to each of the [v1], [v2], etc. streams?

3

Use this:

ffmpeg -i input.mp4  -filter_complex \
"[0:v]crop='if(gte(iw,ih),ih,iw):if(gte(ih,iw),iw,ih)',scale=720x720,split=3[1v][2v][3v]; \
 [1v]trim=0:4.95,setpts=PTS-STARTPTS[v1]; \
 [2v]trim=4.95:6.75,setpts=(PTS-STARTPTS)/0.1[v2]; \
 [3v]trim=6.75:8,setpts=PTS-STARTPTS[v3]; \
 [v1][v2][v3]concat=n=3:v=1:a=0[out]" \
-map [out] -an -c:v libx264 -profile:v high -level 4.1 \
-preset superfast -crf 20 -r 30 output.mp4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.