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:


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:


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

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
    @user255406 libx264 ignores -qscale. Use -crf instead. – llogan Oct 10 '15 at 20:23
  • It looks like in some cases you can simply use setsar= or even just setsar – Steven Penny Nov 27 '17 at 2:43

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, privacy policy and cookie policy

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