Cropping a video using libplacebo
filter doesn't work as expected. I want to crop and scale a video, I am using the following filter:
-vf libplacebo=crop_x=0:crop_y=138:crop_w=1920:crop_h=804:w=1280:h=-2: \
force_original_aspect_ratio=decrease:normalize_sar=true
Expected behavior: video is cropped from 1920x1080 to 1920x804, and then scaled to the width of 1280 with height determined automatically preserving the aspect ratio, which would result in a 1280x536 video.
My result: video is cropped, but then forcefully stretched to 1280x720, not preserving the aspect ratio.
It works when I am using ffmpeg's standard crop
and then passing the cropped video to libplacebo
filter:
-vf crop=1920:804:0:138,libplacebo=w=1280:h=-2:force_original_aspect_ratio=decrease:normalize_sar=true
But I'd like to understand how to crop using libplacebo
native means and replicate the default crop
behavior.
It works as expected using ffplay
:
ffplay -vf "libplacebo=crop_x=0:crop_y=138:crop_w=1920:crop_h=804:w=1920:h=804" input.mkv
I am getting a properly cropped 1920x804 video that is not stretched to 1920x1080, with the correct aspect ratio. But I can't seem to get it working when trying to encode it into a new file with ffmpeg
.
ffmpeg -i input.mkv -vf "libplacebo=crop_x=0:crop_y=138:crop_w=1920:crop_h=804:w=1280:h=-2:force_original_aspect_ratio=decrease:normalize_sar=true" -c:v libx264 -crf 18 -c:a copy output.mkv
ffmpeg version:ffmpeg version 2023-06-19-git-1617d1a752-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers