Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SEI - Mainly for Film Grain and Field Frame #257

Open
wants to merge 29 commits into
base: up
Choose a base branch
from

Conversation

QSXW
Copy link
Collaborator

@QSXW QSXW commented Aug 6, 2024

use -vf tinterlace filter to generate the same yuv as VTM
passed files:
FIELD_A_Panasonic_4.bit
FIELD_B_Panasonic_2.bit

VVCSoftware_VTM
image

FFmpeg
image

@QSXW QSXW mentioned this pull request Aug 6, 2024
@QSXW QSXW force-pushed the feat/FilmGrain branch 3 times, most recently from 9205eea to 4024167 Compare August 10, 2024 18:50
Copy link
Member

@nuomi2021 nuomi2021 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the patch.

@@ -862,6 +862,14 @@ typedef struct CodedBitstreamH266Context {
H266RawVPS *vps[VVC_MAX_VPS_COUNT]; ///< RefStruct references
H266RawSPS *sps[VVC_MAX_SPS_COUNT]; ///< RefStruct references
H266RawPPS *pps[VVC_MAX_PPS_COUNT]; ///< RefStruct references

// The currently active parameter sets. These are updated when any
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vvc spec did not define the active parameter set.
the parameter set will be active by the H266RawPictureHeader

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Will check that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Remove it and move the film grain to the h274 sei syntax template also.

@@ -848,6 +848,27 @@ typedef struct H266RawSlice {
int data_bit_start;
} H266RawSlice;

typedef struct H266RawSEIFilmGrainCharacteristics {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we reuse AVFilmGrainH274Params?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better not to use here. It's used to align for h264/h265/h266 syntax_template.

@@ -31,8 +31,19 @@
#include "libavcodec/sei.h"
#include "libavcodec/vvc.h"

typedef struct VVCSEIPictureHash {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we define this in h274.h? and follow film grain things

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can, but film grain is exposed to the API user with the AV prefix. It's used to align with hevc/sei.h

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the vvc sei defined in h274, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Will do.

libavcodec/cbs.c Outdated
@@ -158,7 +158,7 @@ av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
av_freep(ctx_ptr);
}

static void cbs_unit_uninit(CodedBitstreamUnit *unit)
void ff_cbs_unit_uninit(CodedBitstreamUnit *unit)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this? better give some explain on the commit log

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be better to change it to ff_cbs_unref_unit?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, why we need to expose this to public.
can we just take a reference to unit->content_ref, like slice_start

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goot catch. I use the same way to add a reference to the unit content_ref and remove the redundant commit for exposing ref unit.

@QSXW QSXW changed the title Support Film Grain Support Film Grain and Field Frame Aug 14, 2024
@QSXW QSXW changed the title Support Film Grain and Field Frame Support Versatile supplemental enhancement information messages - Mainly for Film Grain and Field Frame Aug 14, 2024
@QSXW QSXW changed the title Support Versatile supplemental enhancement information messages - Mainly for Film Grain and Field Frame Support SEI - Mainly for Film Grain and Field Frame Aug 14, 2024
@QSXW QSXW mentioned this pull request Aug 14, 2024
@QSXW QSXW self-assigned this Aug 14, 2024
typedef struct VVCSEI {
H2645SEI common;
VVCSEIPictureHash picture_hash;
VVCSEIFrameFieldInfo frame_field_info;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be defined in h274.h too, right?

Copy link
Collaborator Author

@QSXW QSXW Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Update VVCSET to H274SEI and move to h274.h

…istics

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
@QSXW QSXW force-pushed the feat/FilmGrain branch 2 times, most recently from bc2d955 to 69a02c9 Compare August 27, 2024 20:14
@QSXW QSXW requested a review from nuomi2021 August 27, 2024 20:14
@QSXW
Copy link
Collaborator Author

QSXW commented Aug 27, 2024

Should we also move to verify picture hash to ff_h274_verify_decoded_picture_hash like ff_h274_apply_film_grain?

Copy link
Member

@nuomi2021 nuomi2021 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for the patch.
comment inline

#include "libavcodec/h274.h"

typedef struct VVCSEI {
H2645SEI common;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong indent??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. It is a tab and replace it with spaces.

h->comp_model_present_flag[c] = s->fg_comp_model_present_flag[c];

for (int c = 0; c < 3; c++) {
if (h->comp_model_present_flag[c]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we combine the previous with this?

Copy link
Collaborator Author

@QSXW QSXW Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sure. Good point.

flags(fg_comp_model_present_flag[c], 1, c);

for (c = 0; c < 3; c++) {
if (current->fg_comp_model_present_flag[c]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about:
const int bd = (c ? current->fg_bit_depth_chroma_minus8 ? current->fg_bit_depth_luma_minus8) + 8;
const int min = 0 - current->fg_model_id * (1 << (bd - 1));
const int max =((1 << bd) - 1) - current->fg_model_id * (1 << (bd - 1))

flag(ffi_top_field_first_flag);
u(8, ffi_display_elemental_periods_minus1, 0, 0xff);
}
u(2, ffi_source_scan_type, 0, 3);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ub(2, ffi_source_scan_type); ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The range of ffi_source_scan_type is from 0~3. Shouldn't we add it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do two bits mean it ranges from 0~3

SEI_MESSAGE_RW(sei, film_grain_characteristics),
},
{
SEI_TYPE_DISPLAY_ORIENTATION,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not included in h274, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it is. See 8.25 Display orientation SEI message

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8.25? not in vvc spec, right

@@ -623,6 +665,10 @@ static av_cold int frame_context_init(VVCFrameContext *fc, AVCodecContext *avctx
fc->DPB[j].frame = av_frame_alloc();
if (!fc->DPB[j].frame)
return AVERROR(ENOMEM);

fc->DPB[j].frame_grain = av_frame_alloc();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DPB is not a good place for frame_grain. frame_grain is not included in dpb process.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reference it from hevcdec.

    for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
        ff_hevc_unref_frame(&s->DPB[i], ~0);
        av_frame_free(&s->DPB[i].frame_grain);
    }

May you help check where is a better place to put on?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me try, how to test frame_grain?

@@ -887,16 +999,192 @@ static int set_output_format(const VVCContext *s, const AVFrame *output)
return 0;
}

static int verify_md5(VVCContext *s, VVCFrameContext *fc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can move this to h274.c

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah! Moved.

#include "sei.h"
#include "dec.h"

static int decode_film_grain_characteristics(const VVCFrameContext *fc, H2645SEIFilmGrainCharacteristics *h, void *payload)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needed by all h274 users, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs a valid sps, so it's better to keep it for codec specific.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about put
luma_bit_depth, chroma_bit_depth, vui_full_range_flag, vui_colour_primaries, vui_transfer_characteristics, vui_matrix_coeffs in params list


if (fc->ref->needs_fg) {
av_assert0(fc->ref->frame_grain->buf[0]);
fgp = av_film_grain_params_select(fc->ref->frame);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fgp can be NULL,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. It is checked check_film_grain.

    if (fc->ref->needs_fg &&
        (fc->sei.common.film_grain_characteristics.present &&
            !ff_h274_film_grain_params_supported(fc->sei.common.film_grain_characteristics.model_id,
                fc->ref->frame->format) ||
            !av_film_grain_params_select(fc->ref->frame))) {
        av_log_once(s->avctx, AV_LOG_WARNING, AV_LOG_DEBUG, &s->film_grain_warning_shown,
            "Unsupported film grain parameters. Ignoring film grain.\n");
        fc->ref->needs_fg = 0;
    }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but not in this function, right?

if (!ret)
*got_output = 1;
if (!ret) {
ret = frame_end(s, delayed);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to call it export_sei and move it to " if (delayed->output_frame->buf[0] && output) {"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not. We already have a function set_side_data for export sei.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried add it to if (delayed->output_frame->buf[0] && output) { at my first version but it doesn't work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you have a check?

@nuomi2021
Copy link
Member

nuomi2021 commented Aug 31, 2024

Should we also move to verify picture hash to ff_h274_verify_decoded_picture_hash like ff_h274_apply_film_grain?

Yes, if a function is needed by all H.274 users, we should move it to h274.c

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
QSXW and others added 13 commits September 6, 2024 01:21
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
passed files:
    FIELD_A_Panasonic_4.bit
    FIELD_B_Panasonic_2.bit

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
The type of data of AVBufferRef is uint8_t * and the name can
be various types of pointer, so cast it to void * before the
assignment to silence the compiling warning.

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
The sei parsing doesn't influent the decoding, so skip the corrupt sei.

The buffering period SEI of the following clip also failed to parse on
VVCSoftware_VTM:
https://www.itu.int/wftp3/av-arch/jvet-site/bitstream_exchange/VVC/under_test/VTM-15.0/HRD_B_Fujitsu_2.zip

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Buffering Period SEI message will be used by other SEI messages
like Picture Timing and DU information.

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
…ms_present_flag

Signed-off-by: Wu Jianhua <toqsxw@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants