Opened 3 months ago

#10669 new defect

crop filter with exact=0 does not work correctly on non-chroma-subsampled hardware-backed inputs

Reported by: Russell Owned by:
Priority: normal Component: avfilter
Version: git-master Keywords: crop vaapi hwaccel
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug: I'm trying to crop a 444 (no chroma subsampling) video using crop using vaapi. The crop region seems to always be rounded to a multiple of two, even though the input has no chroma subsampling, which according to the documentation means that exact should have no effect.

Originally reported to a project I develop at https://github.com/russelltg/wl-screenrec/issues/26

The sample video has lines at x,y = 100,299. So the crop args w=200:h=200:x=100:x=100 should give a perfect box around the corner (which it does). But w=200:h=200:x=101:x=101 incorrectly gives the same result.

How to reproduce:

% ffmpeg -vaapi_device /dev/dri/renderD129 -i screenrecord.mp4 -vf 'hwupload, crop=w=200:h=200:x=101:y=101,scale_vaapi=format=nv12:w=200:h=200' -c:v h264_vaapi cropped.mp4
ffmpeg version N-112783-g5452cbdc15
  built with gcc 13.2.1 (GCC) 20230801
  HW: Intel i9-11900H

However, it does work if you put exact=1

It seems to me that the problematic snippet is from vf_crop.c:158

    if (pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL) {
        s->hsub = 1;
        s->vsub = 1;
    } else {
        s->hsub = pix_desc->log2_chroma_w;
        s->vsub = pix_desc->log2_chroma_h;
    }

from vf_crop.c, which seems to assume all hardware backed formats have 2x2 chroma subsampling (which, sure is typically the case, but not always!)

Attachments (1)

screenrecord.mp4 (2.1 KB ) - added by Russell 3 months ago.
A yuv444 HEVC encoded mp4 file with line indicators at known pixel values

Download all attachments as: .zip

Change History (1)

by Russell, 3 months ago

Attachment: screenrecord.mp4 added

A yuv444 HEVC encoded mp4 file with line indicators at known pixel values

Note: See TracTickets for help on using tickets.