Skip to content

Conversation

@mattrwoz
Copy link

This adds cropping metadata as proposed in CWG-D038. Accepted in the 10/10/2023 CWG meeting.
Most of the text is the same as the proposal document with some minor adjustments:

  • Replaced "valid picture data" with "rendered"
  • Clarified the scope of the metadata to be from "metadata_crop OBU to Keyframe and/or next metadata_crop OBU" instead of just "until next metadata_crop OBU"

| metadata_crop( ) { | **Type**
| @@crop_width_minus_1 | f(16)
| @@crop_height_minus_1 | f(16)
| @@crop_offset_present | f(1)
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we make it byte-aligned in the first place? having something like:

f(7) reserved
f(1) crop_offset_present;

would be better IMO than relying on the trailing_bits at the end of the OBU.

#### Metadata crop semantics

When present the metadata_crop OBU applies starting at the next frame in the sequence
with matching temporal_id and spatial_id, and shall apply to all matching frames until the next Key Frame
Copy link
Member

@podborski podborski Apr 1, 2024

Choose a reason for hiding this comment

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

When present the metadata_crop OBU applies starting at the next frame in the sequence
with matching temporal_id and spatial_id, ...

Alexis and myself are wondering here what the behavior should be if no extension header is present. Perhaps in that case it should apply to all layers? Then the language on the persistence should also be clarified.

Also instead of:

and shall apply to all matching frames

it would be better to write "and shall apply to all frames with a matching temporal_id and spatial_id"

Copy link
Author

Choose a reason for hiding this comment

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

Yes. I think it should apply to all layers if no header is present. I will add wording clarifying that.

When present the metadata_crop OBU applies starting at the next frame in the sequence
with matching temporal_id and spatial_id, and shall apply to all matching frames until the next Key Frame
or metadata_crop OBU. The output picture should be cropped to the region as specified in the
cropping metadata OBU. When applied, the crop shall be after all normal decode operations as a
Copy link
Member

Choose a reason for hiding this comment

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

When applied, the crop shall be after all normal decode operations as a post-processing step (after film grain synthesis in the output process). This metadata has no effect on the decoding process.

Maybe it would be better to re-write like this:

The crop shall be applied after all normal decode operations as a post-processing step. This metadata information has no effect on the decoding process.

Copy link
Author

Choose a reason for hiding this comment

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

Used your new wording.


**crop_y_offset** specifies the minimum pixel row containing picture data which should be rendered.

**crop_width_minus_1** specifies the number of pixel columns minus 1 which which should be rendered after applying crop_x_offset.
Copy link
Member

Choose a reason for hiding this comment

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

which which => which

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

When muxed into a container that supports signaling cropping information, this metadata should
be removed from the bitstream and included in the container’s signaling mechanism.
If both the container and bitstream signal cropping information, then the container’s cropping
information takes precedence.
Copy link
Member

@podborski podborski Apr 1, 2024

Choose a reason for hiding this comment

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

Instead of:

When muxed into a container that supports signaling cropping information, this metadata should
be removed from the bitstream and included in the container’s signaling mechanism.
If both the container and bitstream signal cropping information, then the container’s cropping
information takes precedence.

We could write:

In cases where cropping information is present in both the bitstream and the delivery or container format, the latter should be preferred.

NOTE: Container or delivery formats that package the AV1 bitstream are recommended to address this redundancy, potentially by excluding bitstream cropping information when it is already available in the container or delivery format.

Then we will have to update the AV1 ISOBMFF spec and say there that we use the clap box and remove this metadata OBU. Thoughts @cconcolato ?

Copy link
Author

Choose a reason for hiding this comment

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

Updated to new wording.

@podborski
Copy link
Member

Some relevant discussion in the file format group on how such metadata can co-exist MPEGGroup/FileFormat#77

cyanreg added a commit to cyanreg/FFmpeg that referenced this pull request Sep 14, 2024
Unlike H264/H265, AV1 contains no fields to crop encoded output
to specific sizes.
AMD's hardware cannot handle encoding of unaligned dimensions for
AV1, hence it codes 1920x1080 as 1920x1088.

Add side data to crop the output back to the original dimensions.
There's an AV1-spec extension planned to fix this here:
AOMediaCodec/av1-spec#346

But it seems to have stuck for now.
cyanreg added a commit to cyanreg/FFmpeg that referenced this pull request Sep 14, 2024
Unlike H264/H265, AV1 contains no fields to crop encoded output
to specific sizes.
AMD's hardware cannot handle encoding of unaligned dimensions for
AV1, hence it codes 1920x1080 as 1920x1088.

Add side data to crop the output back to the original dimensions.
There's an AV1-spec extension planned to fix this here:
AOMediaCodec/av1-spec#346

But it seems to have stuck for now.
cyanreg added a commit to cyanreg/FFmpeg that referenced this pull request Sep 15, 2024
Unlike H264/H265, AV1 contains no fields to crop encoded output
to specific sizes.
AMD's hardware cannot handle encoding of unaligned dimensions for
AV1, hence it codes 1920x1080 as 1920x1088.

Add side data to crop the output back to the original dimensions.
There's an AV1-spec extension planned to fix this here:
AOMediaCodec/av1-spec#346

But it seems to have stuck for now.
@GrabbenD
Copy link

This spec would fix black padding with av1 encoded media on AMDGPU

https://gitlab.freedesktop.org/mesa/mesa/-/issues/9185

@imoccaga
Copy link

This adds cropping metadata as proposed in CWG-D038. Accepted in the 10/10/2023 CWG meeting.
Most of the text is the same as the proposal document with some minor adjustments:

I suggest to update CWG-D038 or submit a new doc with the adjustments and discuss it in CWG. Changes should be made after CWG has reviewed and approved the adjustments.

@aklemets
Copy link

This adds cropping metadata as proposed in CWG-D038. Accepted in the 10/10/2023 CWG meeting.
Most of the text is the same as the proposal document with some minor adjustments:

I suggest to update CWG-D038 or submit a new doc with the adjustments and discuss it in CWG. Changes should be made after CWG has reviewed and approved the adjustments.

Iole, is there a particular change that you think justifies bringing this already approved change back to CWG?

I have diffed the approved document, "CWG-D038_CroppingMetadata_V4.docx" against the text that was submitted in the initial PR commit, and I see no technical differences, but only some grammatical changes.
(The description that was in this initial commit to the PR that claimed differences between the PR and the approved document, appears to be inaccurate.)

@imoccaga
Copy link

imoccaga commented Mar 1, 2025

Thanks for double checking.

And, I see in https://github.com/AOMediaCodec/av1-spec/pull/346/files#diff-f215e95f9dd8408e553c3865e9cf72448db6bc62e4ffc27c21f5f74b73edf252
it has been clarified that
"This metadata information has no effect on the decoding process."

So, I have no concern on the current text.

@Sadarex
Copy link

Sadarex commented Mar 25, 2025

Any news on this?

Some other projects are still blocked:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/[email protected]/
https://gitlab.freedesktop.org/mesa/mesa/-/issues/9185

maitrungduc1410 pushed a commit to maitrungduc1410/webrtc that referenced this pull request Mar 26, 2025
Disable cropping to render resolution by default. This functionality was added in https://webrtc-review.googlesource.com/c/src/+/381340 and https://webrtc-review.googlesource.com/c/src/+/382241 and was enabled by default to make things work with HW encoders which use render resolution to signal cropping. After discussions with AV1 folks the consensus is that encoders should not use render resolution to signal crop. Currently there is no way to signal crop in AV1 bitstream. There is a proposal for adding this info to AV1 metadata: AOMediaCodec/av1-spec#346.

Bug: webrtc:405341160, b:402019802, b:405299912
Change-Id: I9cff9f2f8e7c9b8933fd0fbb100ce37221eaf084
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/382640
Reviewed-by: Danil Chapovalov <[email protected]>
Commit-Queue: Sergey Silkin <[email protected]>
Cr-Commit-Position: refs/heads/main@{#44228}
lando-prod-mozilla bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Jun 4, 2025
Upstream commit: https://webrtc.googlesource.com/src/+/ecde63eab5b643e9d84220b8a50208b4cd8ad866
    Do not crop to render resolution by default

    Disable cropping to render resolution by default. This functionality was added in https://webrtc-review.googlesource.com/c/src/+/381340 and https://webrtc-review.googlesource.com/c/src/+/382241 and was enabled by default to make things work with HW encoders which use render resolution to signal cropping. After discussions with AV1 folks the consensus is that encoders should not use render resolution to signal crop. Currently there is no way to signal crop in AV1 bitstream. There is a proposal for adding this info to AV1 metadata: AOMediaCodec/av1-spec#346.

    Bug: webrtc:405341160, b:402019802, b:405299912
    Change-Id: I9cff9f2f8e7c9b8933fd0fbb100ce37221eaf084
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/382640
    Reviewed-by: Danil Chapovalov <[email protected]>
    Commit-Queue: Sergey Silkin <[email protected]>
    Cr-Commit-Position: refs/heads/main@{#44228}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jun 4, 2025
Upstream commit: https://webrtc.googlesource.com/src/+/ecde63eab5b643e9d84220b8a50208b4cd8ad866
    Do not crop to render resolution by default

    Disable cropping to render resolution by default. This functionality was added in https://webrtc-review.googlesource.com/c/src/+/381340 and https://webrtc-review.googlesource.com/c/src/+/382241 and was enabled by default to make things work with HW encoders which use render resolution to signal cropping. After discussions with AV1 folks the consensus is that encoders should not use render resolution to signal crop. Currently there is no way to signal crop in AV1 bitstream. There is a proposal for adding this info to AV1 metadata: AOMediaCodec/av1-spec#346.

    Bug: webrtc:405341160, b:402019802, b:405299912
    Change-Id: I9cff9f2f8e7c9b8933fd0fbb100ce37221eaf084
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/382640
    Reviewed-by: Danil Chapovalov <[email protected]>
    Commit-Queue: Sergey Silkin <[email protected]>
    Cr-Commit-Position: refs/heads/main@{#44228}
i3roly pushed a commit to i3roly/firefox-dynasty that referenced this pull request Jun 7, 2025
Upstream commit: https://webrtc.googlesource.com/src/+/ecde63eab5b643e9d84220b8a50208b4cd8ad866
    Do not crop to render resolution by default

    Disable cropping to render resolution by default. This functionality was added in https://webrtc-review.googlesource.com/c/src/+/381340 and https://webrtc-review.googlesource.com/c/src/+/382241 and was enabled by default to make things work with HW encoders which use render resolution to signal cropping. After discussions with AV1 folks the consensus is that encoders should not use render resolution to signal crop. Currently there is no way to signal crop in AV1 bitstream. There is a proposal for adding this info to AV1 metadata: AOMediaCodec/av1-spec#346.

    Bug: webrtc:405341160, b:402019802, b:405299912
    Change-Id: I9cff9f2f8e7c9b8933fd0fbb100ce37221eaf084
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/382640
    Reviewed-by: Danil Chapovalov <[email protected]>
    Commit-Queue: Sergey Silkin <[email protected]>
    Cr-Commit-Position: refs/heads/main@{#44228}
alice pushed a commit to alice/firefox that referenced this pull request Jun 10, 2025
Upstream commit: https://webrtc.googlesource.com/src/+/ecde63eab5b643e9d84220b8a50208b4cd8ad866
    Do not crop to render resolution by default

    Disable cropping to render resolution by default. This functionality was added in https://webrtc-review.googlesource.com/c/src/+/381340 and https://webrtc-review.googlesource.com/c/src/+/382241 and was enabled by default to make things work with HW encoders which use render resolution to signal cropping. After discussions with AV1 folks the consensus is that encoders should not use render resolution to signal crop. Currently there is no way to signal crop in AV1 bitstream. There is a proposal for adding this info to AV1 metadata: AOMediaCodec/av1-spec#346.

    Bug: webrtc:405341160, b:402019802, b:405299912
    Change-Id: I9cff9f2f8e7c9b8933fd0fbb100ce37221eaf084
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/382640
    Reviewed-by: Danil Chapovalov <[email protected]>
    Commit-Queue: Sergey Silkin <[email protected]>
    Cr-Commit-Position: refs/heads/main@{#44228}
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Jun 11, 2025
Upstream commit: https://webrtc.googlesource.com/src/+/ecde63eab5b643e9d84220b8a50208b4cd8ad866
    Do not crop to render resolution by default

    Disable cropping to render resolution by default. This functionality was added in https://webrtc-review.googlesource.com/c/src/+/381340 and https://webrtc-review.googlesource.com/c/src/+/382241 and was enabled by default to make things work with HW encoders which use render resolution to signal cropping. After discussions with AV1 folks the consensus is that encoders should not use render resolution to signal crop. Currently there is no way to signal crop in AV1 bitstream. There is a proposal for adding this info to AV1 metadata: AOMediaCodec/av1-spec#346.

    Bug: webrtc:405341160, b:402019802, b:405299912
    Change-Id: I9cff9f2f8e7c9b8933fd0fbb100ce37221eaf084
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/382640
    Reviewed-by: Danil Chapovalov <danilchapwebrtc.org>
    Commit-Queue: Sergey Silkin <ssilkinwebrtc.org>
    Cr-Commit-Position: refs/heads/main{#44228}

UltraBlame original commit: 03d8ebe4ce8f1794a65113a7d3b05147e10be5a7
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Jun 11, 2025
Upstream commit: https://webrtc.googlesource.com/src/+/ecde63eab5b643e9d84220b8a50208b4cd8ad866
    Do not crop to render resolution by default

    Disable cropping to render resolution by default. This functionality was added in https://webrtc-review.googlesource.com/c/src/+/381340 and https://webrtc-review.googlesource.com/c/src/+/382241 and was enabled by default to make things work with HW encoders which use render resolution to signal cropping. After discussions with AV1 folks the consensus is that encoders should not use render resolution to signal crop. Currently there is no way to signal crop in AV1 bitstream. There is a proposal for adding this info to AV1 metadata: AOMediaCodec/av1-spec#346.

    Bug: webrtc:405341160, b:402019802, b:405299912
    Change-Id: I9cff9f2f8e7c9b8933fd0fbb100ce37221eaf084
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/382640
    Reviewed-by: Danil Chapovalov <danilchapwebrtc.org>
    Commit-Queue: Sergey Silkin <ssilkinwebrtc.org>
    Cr-Commit-Position: refs/heads/main{#44228}

UltraBlame original commit: 03d8ebe4ce8f1794a65113a7d3b05147e10be5a7
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Jun 11, 2025
Upstream commit: https://webrtc.googlesource.com/src/+/ecde63eab5b643e9d84220b8a50208b4cd8ad866
    Do not crop to render resolution by default

    Disable cropping to render resolution by default. This functionality was added in https://webrtc-review.googlesource.com/c/src/+/381340 and https://webrtc-review.googlesource.com/c/src/+/382241 and was enabled by default to make things work with HW encoders which use render resolution to signal cropping. After discussions with AV1 folks the consensus is that encoders should not use render resolution to signal crop. Currently there is no way to signal crop in AV1 bitstream. There is a proposal for adding this info to AV1 metadata: AOMediaCodec/av1-spec#346.

    Bug: webrtc:405341160, b:402019802, b:405299912
    Change-Id: I9cff9f2f8e7c9b8933fd0fbb100ce37221eaf084
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/382640
    Reviewed-by: Danil Chapovalov <danilchapwebrtc.org>
    Commit-Queue: Sergey Silkin <ssilkinwebrtc.org>
    Cr-Commit-Position: refs/heads/main{#44228}

UltraBlame original commit: 03d8ebe4ce8f1794a65113a7d3b05147e10be5a7
@taste1981
Copy link

@mattrwoz , any update on this spec change proposal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants