PR #22670 opened by James Almer (jamrial) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22670 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22670.patch
From 935ffd72ed55f7281eae74b89e563b39395fc00e Mon Sep 17 00:00:00 2001 From: James Almer <[email protected]> Date: Sun, 29 Mar 2026 11:03:33 -0300 Subject: [PATCH 1/3] avcodec/lcevc_parser: move pixel format table to a shared file Signed-off-by: James Almer <[email protected]> --- libavcodec/lcevc.h | 30 ++++++++++++++++++++++++++++++ libavcodec/lcevc_parser.c | 13 +------------ libavcodec/lcevctab.c | 12 ++++++++++++ libavcodec/lcevctab.h | 3 +++ 4 files changed, 46 insertions(+), 12 deletions(-) diff --git a/libavcodec/lcevc.h b/libavcodec/lcevc.h index cfe4c1e6e1..27d0c4eb22 100644 --- a/libavcodec/lcevc.h +++ b/libavcodec/lcevc.h @@ -81,4 +81,34 @@ enum { LCEVC_ADDITIONAL_INFO_TYPE_VUI = 1, }; +/* + * Table 21 — Colour format for the decoded picture + */ +enum { + LCEVC_CHROMA_SAMPLING_TYPE_400 = 0, + LCEVC_CHROMA_SAMPLING_TYPE_420 = 1, + LCEVC_CHROMA_SAMPLING_TYPE_422 = 2, + LCEVC_CHROMA_SAMPLING_TYPE_444 = 3, +}; + +/* + * Table 23 — Bit depth of the decoded base picture + */ +enum { + LCEVC_BASE_DEPTH_TYPE_8 = 0, + LCEVC_BASE_DEPTH_TYPE_10 = 1, + LCEVC_BASE_DEPTH_TYPE_12 = 2, + LCEVC_BASE_DEPTH_TYPE_14 = 3, +}; + +/* + * Table 24 — Bit depth of the decoded picture + */ +enum { + LCEVC_ENHANCEMENT_DEPTH_TYPE_8 = 0, + LCEVC_ENHANCEMENT_DEPTH_TYPE_10 = 1, + LCEVC_ENHANCEMENT_DEPTH_TYPE_12 = 2, + LCEVC_ENHANCEMENT_DEPTH_TYPE_14 = 3, +}; + #endif /* AVCODEC_LCEVC_H */ diff --git a/libavcodec/lcevc_parser.c b/libavcodec/lcevc_parser.c index 8564fbb528..ce1635edb9 100644 --- a/libavcodec/lcevc_parser.c +++ b/libavcodec/lcevc_parser.c @@ -72,17 +72,6 @@ static int lcevc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf, return END_NOT_FOUND; } -static const enum AVPixelFormat pix_fmts[4][4] = { - { AV_PIX_FMT_GRAY8, AV_PIX_FMT_YUV420P, - AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, }, - { AV_PIX_FMT_GRAY10, AV_PIX_FMT_YUV420P10, - AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10, }, - { AV_PIX_FMT_GRAY12, AV_PIX_FMT_YUV420P12, - AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12, }, - { AV_PIX_FMT_GRAY14, AV_PIX_FMT_YUV420P14, - AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14, }, -}; - static int parse_nal_unit(AVCodecParserContext *s, AVCodecContext *avctx, const H2645NAL *nal) { @@ -131,7 +120,7 @@ static int parse_nal_unit(AVCodecParserContext *s, AVCodecContext *avctx, skip_bits(&gb, 2); bit_depth = get_bits(&gb, 2); // enhancement_depth_type - s->format = pix_fmts[bit_depth][chroma_format_idc]; + s->format = ff_lcevc_depth_type[bit_depth][chroma_format_idc]; if (resolution_type < 63) { s->width = ff_lcevc_resolution_type[resolution_type].width; diff --git a/libavcodec/lcevctab.c b/libavcodec/lcevctab.c index 045fc718e4..f07d599592 100644 --- a/libavcodec/lcevctab.c +++ b/libavcodec/lcevctab.c @@ -16,6 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "lcevc.h" #include "lcevctab.h" const struct FFLCEVCDim ff_lcevc_resolution_type[63] = { @@ -33,3 +34,14 @@ const struct FFLCEVCDim ff_lcevc_resolution_type[63] = { { 5120, 4096 }, { 6400, 4096 }, { 6400, 4800 }, { 7680, 4320 }, { 7680, 4800 }, }; + +const enum AVPixelFormat ff_lcevc_depth_type[4][4] = { + [LCEVC_BASE_DEPTH_TYPE_8] = { AV_PIX_FMT_GRAY8, AV_PIX_FMT_YUV420P, + AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P }, + [LCEVC_BASE_DEPTH_TYPE_10] = { AV_PIX_FMT_GRAY10, AV_PIX_FMT_YUV420P10, + AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10 }, + [LCEVC_BASE_DEPTH_TYPE_12] = { AV_PIX_FMT_GRAY12, AV_PIX_FMT_YUV420P12, + AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12 }, + [LCEVC_BASE_DEPTH_TYPE_14] = { AV_PIX_FMT_GRAY14, AV_PIX_FMT_YUV420P14, + AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14 }, +}; diff --git a/libavcodec/lcevctab.h b/libavcodec/lcevctab.h index 3bbca2e52b..033c3271f0 100644 --- a/libavcodec/lcevctab.h +++ b/libavcodec/lcevctab.h @@ -22,10 +22,13 @@ #include <stdint.h> #include "libavutil/attributes_internal.h" +#include "libavutil/pixfmt.h" EXTERN const struct FFLCEVCDim { uint16_t width; uint16_t height; } ff_lcevc_resolution_type[63]; +EXTERN const enum AVPixelFormat ff_lcevc_depth_type[4][4]; + #endif /* AVCODEC_LCEVCTAB_H */ -- 2.52.0 From 05cff088b99a3e5edc41c39241a4e98efaf4f597 Mon Sep 17 00:00:00 2001 From: James Almer <[email protected]> Date: Tue, 31 Mar 2026 10:23:37 -0300 Subject: [PATCH 2/3] avcodec/lcevcdec: add 14bit pixel formats Signed-off-by: James Almer <[email protected]> --- libavcodec/lcevcdec.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libavcodec/lcevcdec.c b/libavcodec/lcevcdec.c index d9e8b0b76d..0e665fbe31 100644 --- a/libavcodec/lcevcdec.c +++ b/libavcodec/lcevcdec.c @@ -39,18 +39,24 @@ static LCEVC_ColorFormat map_format(int format) return LCEVC_I420_10_LE; case AV_PIX_FMT_YUV420P12: return LCEVC_I420_12_LE; + case AV_PIX_FMT_YUV420P14: + return LCEVC_I420_14_LE; case AV_PIX_FMT_YUV422P: return LCEVC_I422_8; case AV_PIX_FMT_YUV422P10: return LCEVC_I422_10_LE; case AV_PIX_FMT_YUV422P12: return LCEVC_I422_12_LE; + case AV_PIX_FMT_YUV422P14: + return LCEVC_I422_14_LE; case AV_PIX_FMT_YUV444P: return LCEVC_I444_8; case AV_PIX_FMT_YUV444P10: return LCEVC_I444_10_LE; case AV_PIX_FMT_YUV444P12: return LCEVC_I444_12_LE; + case AV_PIX_FMT_YUV444P14: + return LCEVC_I444_14_LE; case AV_PIX_FMT_NV12: return LCEVC_NV12_8; case AV_PIX_FMT_NV21: @@ -61,6 +67,8 @@ static LCEVC_ColorFormat map_format(int format) return LCEVC_GRAY_10_LE; case AV_PIX_FMT_GRAY12LE: return LCEVC_GRAY_12_LE; + case AV_PIX_FMT_GRAY14LE: + return LCEVC_GRAY_14_LE; } return LCEVC_ColorFormat_Unknown; -- 2.52.0 From 4ae3ff1de91d43eab7518c707e63cfc196203de7 Mon Sep 17 00:00:00 2001 From: James Almer <[email protected]> Date: Sun, 29 Mar 2026 11:05:38 -0300 Subject: [PATCH 3/3] avcodec/lcevcdec: support differing base and enhancement bitdepths Signed-off-by: James Almer <[email protected]> --- libavcodec/decode.c | 9 ++++++--- libavcodec/lcevcdec.c | 4 +++- libavcodec/lcevcdec.h | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 6ddf469663..206b711390 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -98,6 +98,7 @@ typedef struct DecodeContext { struct { FFLCEVCContext *ctx; int frame; + enum AVPixelFormat format; int base_width; int base_height; int width; @@ -1629,7 +1630,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame) av_frame_get_side_data(frame, AV_FRAME_DATA_LCEVC); if (dc->lcevc.frame) { - int ret = ff_lcevc_parse_frame(dc->lcevc.ctx, frame, + int ret = ff_lcevc_parse_frame(dc->lcevc.ctx, frame, &dc->lcevc.format, &dc->lcevc.width, &dc->lcevc.height, avctx); if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE)) return ret; @@ -1704,7 +1705,7 @@ int ff_attach_decode_data(AVCodecContext *avctx, AVFrame *frame) av_frame_get_side_data(frame, AV_FRAME_DATA_LCEVC); if (dc->lcevc.frame) { - int ret = ff_lcevc_parse_frame(dc->lcevc.ctx, frame, + int ret = ff_lcevc_parse_frame(dc->lcevc.ctx, frame, &dc->lcevc.format, &dc->lcevc.width, &dc->lcevc.height, avctx); if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE)) return ret; @@ -1738,7 +1739,8 @@ int ff_attach_decode_data(AVCodecContext *avctx, AVFrame *frame) frame_ctx->lcevc = av_refstruct_ref(dc->lcevc.ctx); frame_ctx->frame->width = dc->lcevc.width; frame_ctx->frame->height = dc->lcevc.height; - frame_ctx->frame->format = frame->format; + frame_ctx->frame->format = dc->lcevc.format; + avctx->bits_per_raw_sample = av_pix_fmt_desc_get(dc->lcevc.format)->comp[0].depth; frame->width = dc->lcevc.base_width; frame->height = dc->lcevc.base_height; @@ -2370,6 +2372,7 @@ av_cold void ff_decode_internal_sync(AVCodecContext *dst, const AVCodecContext * av_refstruct_replace(&dst_dc->lcevc.ctx, src_dc->lcevc.ctx); dst_dc->lcevc.width = src_dc->lcevc.width; dst_dc->lcevc.height = src_dc->lcevc.height; + dst_dc->lcevc.format = src_dc->lcevc.format; #endif } diff --git a/libavcodec/lcevcdec.c b/libavcodec/lcevcdec.c index 0e665fbe31..013cae9147 100644 --- a/libavcodec/lcevcdec.c +++ b/libavcodec/lcevcdec.c @@ -358,7 +358,7 @@ int ff_lcevc_process(void *logctx, AVFrame *frame) } int ff_lcevc_parse_frame(FFLCEVCContext *lcevc, const AVFrame *frame, - int *width, int *height, void *logctx) + enum AVPixelFormat *format, int *width, int *height, void *logctx) { LCEVCRawProcessBlock *block = NULL; LCEVCRawGlobalConfig *gc = NULL; @@ -379,6 +379,8 @@ int ff_lcevc_parse_frame(FFLCEVCContext *lcevc, const AVFrame *frame, } gc = block->payload; + + *format = ff_lcevc_depth_type[gc->enhancement_depth_type][gc->chroma_sampling_type]; if (gc->resolution_type < 63) { *width = ff_lcevc_resolution_type[gc->resolution_type].width; *height = ff_lcevc_resolution_type[gc->resolution_type].height; diff --git a/libavcodec/lcevcdec.h b/libavcodec/lcevcdec.h index a65214344d..0a255d2951 100644 --- a/libavcodec/lcevcdec.h +++ b/libavcodec/lcevcdec.h @@ -48,6 +48,6 @@ typedef struct FFLCEVCFrame { int ff_lcevc_alloc(FFLCEVCContext **plcevc, void *logctx); int ff_lcevc_process(void *logctx, struct AVFrame *frame); int ff_lcevc_parse_frame(FFLCEVCContext *lcevc, const struct AVFrame *frame, - int *width, int *height, void *logctx); + enum AVPixelFormat *format, int *width, int *height, void *logctx); void ff_lcevc_unref(void *opaque); #endif /* AVCODEC_LCEVCDEC_H */ -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
