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

video/image_writer: tag bits_per_raw_sample when pixfmt changes #11247

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Traneptora
Copy link
Member

This populates the AVCodecContext->bits_per_raw_sample field value when the pixel format of the screenshot being written doesn't match the pixel format of the original video. For example, if the original video was 10-bit and the screenshot is 16-bit, it populates this field so the encoder can make use of it.

Currently only the libjxl encoder respects this tag although PNG supports sBIT. Once lavc's PNG encoder respects this tag it will work seamlessly with this commit as well.

This feature is only enabled if screenshot-high-bit-depth=yes is enabled, because bits_per_raw_sample shouldn't be set for 8-bit screenshots.

* ignore this value, but some codecs can make use of it (for example, PNG's
* sBIT chunk or JXL's bit depth header)
*/
if (ctx->opts->high_bit_depth && ctx->original_format.id != image->imgfmt) {
Copy link
Member

Choose a reason for hiding this comment

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

why only if the pixfmt is different?

Copy link
Member Author

@Traneptora Traneptora Jan 31, 2023

Choose a reason for hiding this comment

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

If the pixel format is the same, then there's no need for this metadata as it would set it to the max of the pixel format.

If you think it would still be valuable to set anyway, then I can remove that check.

Copy link
Member

Choose a reason for hiding this comment

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

That's fine it just tripped me up.

Copy link
Member

Choose a reason for hiding this comment

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

One thing to note is that ctx->opts->high_bit_depth is no guarantee that you get a bit depth > 8, so you may need to adjust the check.

because bits_per_raw_sample shouldn't be set for 8-bit screenshots.

btw, why is that?

Copy link
Member Author

@Traneptora Traneptora Feb 3, 2023

Choose a reason for hiding this comment

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

The idea was that higher bit depth video can be tagged appropriately (e.g. 10bit) although I suppose theoretically you could have a lower bit depth PNG or JXL than 8.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I thought there was a technical reason why that must not happen not just "it's pointless".
re the problem I mentioned: drop the ctx->opts->high_bit_depth check then?

This populates the AVCodecContext->bits_per_raw_sample field value when
the pixel format of the screenshot being written doesn't match the pixel format
of the original video. For example, if the original video was 10-bit and the
screenshot is 16-bit, it populates this field so the encoder can make use of it.

Currently only the libjxl encoder respects this tag although PNG supports sBIT.
Once lavc's PNG encoder respects this tag it will work seamlessly with this commit
as well.

This feature is only enabled if screenshot-high-bit-depth=yes is enabled, because
bits_per_raw_sample shouldn't be set for 8-bit screenshots.
@Traneptora
Copy link
Member Author

Update: This only appears to work when screenshot-sw=yes. Do we care about the other case enough?

@sfan5
Copy link
Member

sfan5 commented Feb 2, 2023

That is to be expected since hardware screenshots are downloaded as RGB0 (8bpc) or RGBA64 (16bpc) and that is considered the "source" format.

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.

2 participants