2

I have a heterogenous set of videos (codecs, dimensions, size) that I would like to crop off the top using ffmpeg. I've used this code successfully for year without any trouble (example here crops off 64px):

ffmpeg -i in.avi -y -pix_fmt yuv420p -an -qscale 1 -vcodec libx264 -vf crop=in_w:in_h-64:0:64 out.mp4

However, I've now run into a case that it does not work correctly, and I suspect it has something to do with SAR and DAR. I have a clip that shows pixel dimensions of 960x720 [SAR 960:720 DAR 16:9], original looks close to this:

original

When I use the above command, I end up with a video that ffprobe/ffmpeg says is 960x656 [SAR 4:3 DAR 80:41], but when I view it on a web browser or quicktime it is displayed as 1280x656:

output

How can I modify the command to account for this use case, without breaking the cropping of all other clips? Here's what I've unsuccessfully tried:

ffmpeg -i in.avi -y -pix_fmt yuv420p -an -qscale 1 -vcodec libx264 -vf scale=960:656,setsar=1 -vf crop=in_w:in_h-64:0:64 out.mp4
ffmpeg -i in.avi -y -pix_fmt yuv420p -an -qscale 1 -vcodec libx264 -vf setsar=sar=0 -vf setdar=dar=0 -vf crop=in_w:in_h-64:0:64 out.mp4
2
  • Here's an archive of the input and output files I'm getting. ultrasoundoftheweek.com/give/uploads/clips.zip
    – user255406
    Oct 10, 2015 at 17:24
  • "Keep in mind that the sample aspect ratio set by the setsar filter may be changed by later filters in the filterchain, e.g. if another "setsar" or a "setdar" filter is applied." - so the correct order is needed and as said by @orgoro possibly try to do not separate filters and instead do: -vf "filter1=...,filter2=...,filter3"
    – 16851556
    Jun 15, 2021 at 21:18

2 Answers 2

1

This should work universally.

ffmpeg -i in.avi -y -pix_fmt yuv420p -an -qscale 1 -vcodec libx264 -vf setsar=1,crop=in_w:in_h-64:0:64 out.mp4
2
  • 2
    @user255406 libx264 ignores -qscale. Use -crf instead.
    – llogan
    Oct 10, 2015 at 20:23
  • It looks like in some cases you can simply use setsar= or even just setsar
    – Zombo
    Nov 27, 2017 at 2:43
0

ffmpeg accepts only one video filter (marked as -vf) you should merge all the video filters you want into one, comma separated string:

ffmpeg ... -vf setsar=1,crop=in_w:in_h-64:0:64 out.mp4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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