Skip to content

codec2: add P010 output support for HEVC Main10 and 4k AV1#1

Open
leohearts wants to merge 4 commits into
WayDroid-ATV:14-x86/ffmpeg-7.1from
leohearts:main10-p010-codec2
Open

codec2: add P010 output support for HEVC Main10 and 4k AV1#1
leohearts wants to merge 4 commits into
WayDroid-ATV:14-x86/ffmpeg-7.1from
leohearts:main10-p010-codec2

Conversation

@leohearts
Copy link
Copy Markdown

Add YUV_420_P010 as a selectable ffmpeg Codec2 output format and map it to HAL_PIXEL_FORMAT_YCBCR_P010, VA_FOURCC_P010, VA_RT_FORMAT_YUV420_10BPP, DRM_FORMAT_P010 and AV_PIX_FMT_P010.

When VAAPI reports a P010 software format for hardware frames, switch the active output format to P010 and update Codec2 color info to 10-bit YUV 4:2:0. This allows HEVC Main10 streams to expose a P010 output buffer instead of being forced through the existing 8-bit YUV path.

Also advertise HEVC Main10 in the decoder profile list so MediaCodec clients can select c2.ffmpeg.hevc.decoder for Main10 content.

Test: m -j8 android.hardware.media.c2-ffmpeg-service media_codecs_ffmpeg_c2.xml android.hardware.media.c2-ffmpeg.policy
Test: Played a 2160p HEVC Main10 sample with Next Player on WayDroid; logcat showed c2.ffmpeg.hevc.decoder, VAAPI hwaccel and HAL_PIXEL_FORMAT_YCBCR_P010 output.

@leohearts
Copy link
Copy Markdown
Author

leohearts commented May 21, 2026

this contribution contains two(2) prs. the other (and tests) is here:
WayDroid-ATV/android_vendor_waydroid_init#1

Add YUV_420_P010 as an ffmpeg Codec2 output format and map it to HAL_PIXEL_FORMAT_YCBCR_P010, VA_FOURCC_P010, VA_RT_FORMAT_YUV420_10BPP, DRM_FORMAT_P010 and AV_PIX_FMT_P010.

For VAAPI hardware frames, switch the active output format to P010 only when the frame context reports AV_PIX_FMT_P010 as the software format. This keeps the default debug.ffmpeg-codec2.pixel_format at YUV_420 for 8-bit codecs such as H.264, VP9 and AV1, while still allowing HEVC Main10 streams to expose P010 output buffers.

Also advertise HEVC Main10 in the decoder profile list so MediaCodec clients can select c2.ffmpeg.hevc.decoder for Main10 content.

Test: m -j8 android.hardware.media.c2-ffmpeg-service media_codecs_ffmpeg_c2.xml android.hardware.media.c2-ffmpeg.policy
Test: With debug.ffmpeg-codec2.pixel_format=YUV_420, played a 2160p H.264 sample in Next Player; logcat showed c2.ffmpeg.h264.decoder and non-P010 output.
Test: With debug.ffmpeg-codec2.pixel_format=YUV_420, played a 2160p HEVC Main10 sample in Next Player; logcat showed c2.ffmpeg.hevc.decoder, VAAPI hwaccel and HAL_PIXEL_FORMAT_YCBCR_P010 output.
Test: With debug.ffmpeg-codec2.pixel_format=YUV_420, played a 1080p VP9 Profile 0 sample in Next Player; logcat showed c2.ffmpeg.vp9.decoder and non-P010 output.

Co-authored-by: OpenAI Codex <codex@openai.com>
@leohearts leohearts force-pushed the main10-p010-codec2 branch from a098a93 to dca6992 Compare May 21, 2026 04:45
leohearts and others added 3 commits May 21, 2026 13:06
Raise the ffmpeg AV1 decoder size limit to 4096x4096 and add the same basic throughput and performance limits used by other 4K-capable video decoders.\n\nThe previous 2048x2048 limit can prevent 4K AV1 streams from matching c2.ffmpeg.av1.decoder through MediaCodec capabilities.\n\nTest: m -j8 media_codecs_ffmpeg_c2.xml android.hardware.media.c2-ffmpeg-service\nTest: Deployed media_codecs_ffmpeg_c2.xml and confirmed c2.ffmpeg.av1.decoder advertises max=4096x4096.\nTest: Played a controlled 1080p AV1 10-bit sample with Next Player; logcat showed c2.ffmpeg.av1.decoder, VAAPI hwaccel and HAL_PIXEL_FORMAT_YCBCR_P010 output.\n\nCo-authored-by: OpenAI Codex <codex@openai.com>
Keep VAAPI Main10 downloads in P010 instead of forcing YUV420P. Also handle decoder EAGAIN by draining pending output before retrying the same input packet, avoiding playback stalls under backpressure.

Co-authored-by: OpenAI Codex <codex@openai.com>
Expose default, coded, and output color aspect parameters and update them from FFmpeg AVFrame metadata when decoded frames carry range, primaries, transfer, or matrix information. Attach the current color aspects to output buffers so HDR/Main10 streams keep their color metadata.

Co-authored-by: OpenAI Codex <codex@openai.com>
@leohearts leohearts changed the title codec2: add P010 output support for HEVC Main10 codec2: add P010 output support for HEVC Main10 and 4k AV May 22, 2026
@leohearts leohearts changed the title codec2: add P010 output support for HEVC Main10 and 4k AV codec2: add P010 output support for HEVC Main10 and 4k AV1 May 22, 2026
@leohearts leohearts marked this pull request as ready for review May 22, 2026 10:01
@leohearts
Copy link
Copy Markdown
Author

leohearts commented May 22, 2026

Test results:
what is working:

  • h264
  • hevc
  • hevc main10 (new!)
    • codec information: Stream #0:0(eng): Video: hevc (Main 10), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 3840x2160 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn
  • vp9 4k
  • vp9 hdr
  • av1 4k (new!)
  • av1 4k hdr (Youtube)
  • av1 4k main10 (VLC, not emby)
Screenshot_20260522_175308 Screenshot_20260522_175404 Screenshot_20260522_175553 Screenshot_20260522_175836 Screenshot_20260522_175906 Screenshot_20260522_180029 Screenshot_20260522_180045

what is NOT working well:

  • hevc main10 4k dolby vision profile 5 without legacy hdr profile (can play, has a green tint. this is not working either before my patch, at least in Emby. need software color remapping, which is slow on 4k (12fps on my device))
    • codec information: Video: hevc (Main 10) (dvhe / 0x65687664), yuv420p10le(pc), 3840x1634 [SAR 1:1 DAR 1920:817], 6236 kb/s, 25 fps, 25 tbr, 25 tbn (default) this turned to be a problem of my host, not related to waydroid ~~
Screenshot_20260522_175644
  • av1 main10 (Emby)
    • codec information: av1 (Main), yuv420p10le(tv, bt2020nc/bt2020/smpte2084), 1920x1080, Film Grain, SAR 1:1 DAR 16:9, 23.98 fps, 23.98 tbr, 1k tbn (default)
    • MediaCodec(emby) renders first few frames, then stuck. don't know why because...
    • it works well in VLC, unlike hevc 4k dolby. possibly an Emby problem.
    • Screenshot_20260522_182147

@leohearts
Copy link
Copy Markdown
Author

additional works i did but not in this pr:
software Dolby Vision SDR conversion
https://github.com/leohearts/android_external_stagefright-plugins/tree/dovi-libplacebo-experiment

@leohearts
Copy link
Copy Markdown
Author

responsible vibe-coding:
This work is co-authored by several AI agents. I confirm every line of code has been reviewed by me, and this exact commit has been tested on local machine (see above).

if (shouldUseP010Output(hwfc)) {
return VA_FOURCC_P010;
}
return mUtils->getVAFOURCCFormat();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Modify getVAFOURCCFormat/getVAFormat/getPixelFormat instead of creating a new function?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ok I'll change that to add a line into getVAFOURCCFormat

struct SwsContext* currentImgConvertCtx = mImgConvertCtx;

if (mUtils->getPixelFormat(false) == HAL_PIXEL_FORMAT_YV12) {
if (getActivePixelFormat(false) == HAL_PIXEL_FORMAT_YCBCR_P010) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe add HAL_PIXEL_FORMAT_NV12 here? This should also works on NV12

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Maybe yes, but I don't have a video / device to test that, so I'll leave that to you and future contributers 😇❤️

Comment thread utils/ffmpeg_hwaccel.c
AVHWFramesContext *hwfc = (AVHWFramesContext *)frame->hw_frames_ctx->data;
if (hwfc && hwfc->sw_format == AV_PIX_FMT_P010) {
sw_format = AV_PIX_FMT_P010;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Write to output->format directly?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

We have output->format = sw_format; later and we may need to use this variable again in the future, for specific cases / hardware support , etc. but if you prefer, it's totally fine to just change that! It's just a future proof.

@supechicken
Copy link
Copy Markdown
Member

supechicken commented May 29, 2026

Thanks for the PR! However Waydroid's hwcomposer doesn't support HDR output yet, so I am not sure whether we need this at this moment

Btw you might open a PR in upstream (https://github.com/android-generic/external_stagefright-plugins) so that other Android x86 projects like BlissOS can share your patches

@leohearts
Copy link
Copy Markdown
Author

leohearts commented May 29, 2026 via email

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.

2 participants