[FFmpeg-trac] #10012(avcodec:new): rkmppdec improperly judging interlaced source
FFmpeg
trac at avcodec.org
Mon Nov 7 05:38:36 EET 2022
#10012: rkmppdec improperly judging interlaced source
-------------------------------------+-----------------------------------
Reporter: tc | Owner: (none)
Type: defect | Status: new
Priority: normal | Component: avcodec
Version: unspecified | Resolution:
Keywords: interlaced | Blocked By:
Blocking: | Reproduced by developer: 0
Analyzed by developer: 0 |
-------------------------------------+-----------------------------------
Description changed by tc:
Old description:
> Summary of the bug:
>
> https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/rkmppdec.c#L407
>
> {{{#!c
> frame->interlaced_frame = ((mode & MPP_FRAME_FLAG_FIELD_ORDER_MASK) ==
> MPP_FRAME_FLAG_DEINTERLACED);
> }}}
>
> my understanding of frame->interlaced is that it should be non-zero when
> input frames are interlaced.
> `mpp_frame_get_mode(mppframe)` returns a bitfield covered by
> `mpp_frame.h`:
>
> {{{#!c
> #define MPP_FRAME_FLAG_TOP_FIELD (0x00000001)
> /* bottom field only */
> #define MPP_FRAME_FLAG_BOT_FIELD (0x00000002)
> /* paired field */
> #define MPP_FRAME_FLAG_PAIRED_FIELD
> (MPP_FRAME_FLAG_TOP_FIELD|MPP_FRAME_FLAG_BOT_FIELD)
> /* paired field with field order of top first */
> #define MPP_FRAME_FLAG_TOP_FIRST (0x00000004)
> /* paired field with field order of bottom first */
> #define MPP_FRAME_FLAG_BOT_FIRST (0x00000008)
> /* paired field with unknown field order (MBAFF) */
> #define MPP_FRAME_FLAG_DEINTERLACED
> (MPP_FRAME_FLAG_TOP_FIRST|MPP_FRAME_FLAG_BOT_FIRST)
> #define MPP_FRAME_FLAG_FIELD_ORDER_MASK (0x0000000C)
> }}}
>
> For a typical tff interlaced source, returned mode is `0x7` (`0b111`).
> For bff, it would be `0b1011`.
>
> However, MPP_FRAME_FLAG_DEINTERLACED masks both TFF and BFF, which is
> impossible in interlaced sources.
> As per discussion here: https://github.com/JeffyCN/FFmpeg/issues/10
>
> the correct logic would be inverse of current, i.e.
>
> {{{#!c
> frame->interlaced_frame = (!((mode & MPP_FRAME_FLAG_FIELD_ORDER_MASK) ==
> MPP_FRAME_FLAG_DEINTERLACED));
> }}}
>
> After making this change, the stream is properly marked as interlaced:
> {{{
> Stream #0:0: Video: h264, drm_prime(bt709, top coded first (swapped)),
> 1440x1080, q=2-31, 3000 kb/s, 29.97 fps, 90k tbn
> }}}
New description:
Summary of the bug:
https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/rkmppdec.c#L407
{{{#!c
frame->interlaced_frame = ((mode & MPP_FRAME_FLAG_FIELD_ORDER_MASK) ==
MPP_FRAME_FLAG_DEINTERLACED);
}}}
my understanding of frame->interlaced is that it should be non-zero when
input frames are interlaced.
`mpp_frame_get_mode(mppframe)` returns a bitfield covered by
`mpp_frame.h`:
{{{#!c
#define MPP_FRAME_FLAG_TOP_FIELD (0x00000001)
/* bottom field only */
#define MPP_FRAME_FLAG_BOT_FIELD (0x00000002)
/* paired field */
#define MPP_FRAME_FLAG_PAIRED_FIELD
(MPP_FRAME_FLAG_TOP_FIELD|MPP_FRAME_FLAG_BOT_FIELD)
/* paired field with field order of top first */
#define MPP_FRAME_FLAG_TOP_FIRST (0x00000004)
/* paired field with field order of bottom first */
#define MPP_FRAME_FLAG_BOT_FIRST (0x00000008)
/* paired field with unknown field order (MBAFF) */
#define MPP_FRAME_FLAG_DEINTERLACED
(MPP_FRAME_FLAG_TOP_FIRST|MPP_FRAME_FLAG_BOT_FIRST)
#define MPP_FRAME_FLAG_FIELD_ORDER_MASK (0x0000000C)
}}}
For a typical tff interlaced source, returned mode is `0x7` (`0b111`). For
bff, it would be `0b1011`.
However, MPP_FRAME_FLAG_DEINTERLACED masks both TFF and BFF, which is
impossible in interlaced sources.
As per discussion here: https://github.com/JeffyCN/FFmpeg/issues/10
the correct logic would be inverse of current, i.e.
{{{#!c
frame->interlaced_frame = (mode & MPP_FRAME_FLAG_FIELD_ORDER_MASK);
}}}
After making this change, the stream is properly marked as interlaced:
{{{
Stream #0:0: Video: h264, drm_prime(bt709, top coded first (swapped)),
1440x1080, q=2-31, 3000 kb/s, 29.97 fps, 90k tbn
}}}
--
--
Ticket URL: <https://trac.ffmpeg.org/ticket/10012#comment:1>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker
More information about the FFmpeg-trac
mailing list