0

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.

2
  • What's your full command?
    – Gyan
    Commented Jun 24, 2023 at 4:00
  • @Gyan 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
    – piety1753
    Commented Jun 24, 2023 at 11:45

1 Answer 1

0

Change h=-2 to h=ow/(a*sar), normalize_sar to false.

And add setsar=1 filter after libplacebo.

4
  • Didn't work. Here is the source video: i.imgur.com/DcRxEHy.png And here is the cropped and scaled video: i.imgur.com/2VL77Yh.png Yet again, it forcefully stretches it to the height of 720px and messes up the aspect ratio, when all I want to do is crop black borders and preserve the aspect ratio with libplacebo crop. ffmpeg -hide_banner -i .\input.mkv -init_hw_device vulkan -vf "libplacebo=crop_x=0:crop_y=138:crop_w=1920:crop_h=804:w=1280:h=ow/(a*sar):force_original_aspect_ratio=decrease:normalize_sar=false,setsar=1" -c:v libx264 -crf 18 -c:a copy output.mkv
    – piety1753
    Commented Jun 25, 2023 at 13:06
  • Okay, I've experimented a bit. It worked like this: ffmpeg -hide_banner -i test.mkv -init_hw_device vulkan -vf "libplacebo=crop_x=0:crop_y=138:crop_w=1920:crop_h=804:w=1920:h=804,libplacebo=w=1280:h=-2:force_original_aspect_ratio=decrease:normalize_sar=false,setsar=1" -c:v libx264 -crf 18 output.mkv But it's really rather cumbersome and I am not sure if it's any better than just using the default crop first, and then libplacebo to scale.
    – piety1753
    Commented Jun 25, 2023 at 22:03
  • Sorry, remove force_original_aspect_ratio=decrease and then use my changes.
    – Gyan
    Commented Jun 26, 2023 at 7:20
  • FTR, the SAR logic was recently changed/updated, see github.com/FFmpeg/FFmpeg/commit/…
    – diegocr
    Commented Jul 1, 2023 at 2:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .