From 4d24827a24822b08be5e2d3821a6787afa4c2f29 Mon Sep 17 00:00:00 2001 From: v0lt Date: Mon, 8 Jul 2024 20:56:30 +0300 Subject: [PATCH] =?UTF-8?q?MPCVideoDec:=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BE=D0=BF=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20pix=5Ffmt=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20FFV1.=20FFmpeg:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F?= =?UTF-8?q?=20ff=5Fffv1=5Fparse=5Fextra=5Fdata=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?pAVCtx->priv=5Fdata.=20=D0=9F=D0=BE=20=D0=BA=D0=B0=D0=BA=D0=BE?= =?UTF-8?q?=D0=B9-=D1=82=D0=BE=20=D0=BF=D1=80=D0=B8=D1=87=D0=B8=D0=BD?= =?UTF-8?q?=D0=B5=20FFmpeg=20=D0=BF=D0=B5=D1=80=D0=B5=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D0=BB=20=D1=8D=D1=82=D0=BE=20=D0=B4=D0=B5=D0=BB=D0=B0=D1=82?= =?UTF-8?q?=D1=8C.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ExtLib/ffmpeg/libavcodec/ffv1.h | 4 +++ src/ExtLib/ffmpeg/libavcodec/ffv1dec.c | 16 ++++++++++++ .../transform/MPCVideoDec/ffmpegContext.cpp | 25 ++++++++++++------- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/ExtLib/ffmpeg/libavcodec/ffv1.h b/src/ExtLib/ffmpeg/libavcodec/ffv1.h index acec22e83e..39eef8087c 100644 --- a/src/ExtLib/ffmpeg/libavcodec/ffv1.h +++ b/src/ExtLib/ffmpeg/libavcodec/ffv1.h @@ -181,4 +181,8 @@ static inline void update_vlc_state(VlcState *const state, const int v) state->count = count; } +// ==> Start patch MPC +int ff_ffv1_parse_extra_data(AVCodecContext* avctx); +// ==> End patch MPC + #endif /* AVCODEC_FFV1_H */ diff --git a/src/ExtLib/ffmpeg/libavcodec/ffv1dec.c b/src/ExtLib/ffmpeg/libavcodec/ffv1dec.c index 7a0d1909aa..32d2d58ca4 100644 --- a/src/ExtLib/ffmpeg/libavcodec/ffv1dec.c +++ b/src/ExtLib/ffmpeg/libavcodec/ffv1dec.c @@ -1118,3 +1118,19 @@ const FFCodec ff_ffv1_decoder = { .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_USES_PROGRESSFRAMES, }; + +// ==> Start patch MPC +int ff_ffv1_parse_extra_data(AVCodecContext* avctx) +{ + FFV1Context* f = avctx->priv_data; + int ret; + + if ((ret = ff_ffv1_common_init(avctx)) < 0) + return ret; + + if (avctx->extradata_size > 0 && (ret = read_extra_header(f)) < 0) + return ret; + + return 0; +} +// ==> End patch MPC diff --git a/src/filters/transform/MPCVideoDec/ffmpegContext.cpp b/src/filters/transform/MPCVideoDec/ffmpegContext.cpp index df8621ae2f..8ba33dfa32 100644 --- a/src/filters/transform/MPCVideoDec/ffmpegContext.cpp +++ b/src/filters/transform/MPCVideoDec/ffmpegContext.cpp @@ -269,11 +269,18 @@ void FillAVCodecProps(struct AVCodecContext* pAVCtx, BITMAPINFOHEADER* pBMI) break; case AV_CODEC_ID_FFV1: if (pAVCtx->priv_data) { - const FFV1Context* h = (FFV1Context*)pAVCtx->priv_data; - if (h->version > 0) { // extra data has been parse - if (h->colorspace == 0) { + auto f = static_cast(pAVCtx->priv_data); + if (!f->version) { + if (ff_ffv1_parse_extra_data(pAVCtx) < 0) { + break; + } + } + if (f->version > 0) { // extra data has been parse + if (f->colorspace == 0) { + auto chorma_shift = 16 * f->chroma_h_shift + f->chroma_v_shift; + if (pAVCtx->bits_per_raw_sample <= 8) { // <=8 bit and transparency - switch (16 * h->chroma_h_shift + h->chroma_v_shift) { + switch (chorma_shift) { case 0x00: pAVCtx->pix_fmt = AV_PIX_FMT_YUV444P; break; case 0x01: pAVCtx->pix_fmt = AV_PIX_FMT_YUV440P; break; case 0x10: pAVCtx->pix_fmt = AV_PIX_FMT_YUV422P; break; @@ -283,21 +290,21 @@ void FillAVCodecProps(struct AVCodecContext* pAVCtx, BITMAPINFOHEADER* pBMI) } } else if (pAVCtx->bits_per_raw_sample <= 10) { // 9, 10 bit and transparency - switch (16 * h->chroma_h_shift + h->chroma_v_shift) { + switch (chorma_shift) { case 0x00: pAVCtx->pix_fmt = AV_PIX_FMT_YUV444P10; break; case 0x10: pAVCtx->pix_fmt = AV_PIX_FMT_YUV422P10; break; case 0x11: pAVCtx->pix_fmt = AV_PIX_FMT_YUV420P10; break; } } else if (pAVCtx->bits_per_raw_sample <= 16) { // 12, 14, 16 bit and transparency - switch (16 * h->chroma_h_shift + h->chroma_v_shift) { + switch (chorma_shift) { case 0x00: pAVCtx->pix_fmt = AV_PIX_FMT_YUV444P16; break; case 0x10: pAVCtx->pix_fmt = AV_PIX_FMT_YUV422P16; break; case 0x11: pAVCtx->pix_fmt = AV_PIX_FMT_YUV420P16; break; } } } - else if (h->colorspace == 1) { + else if (f->colorspace == 1) { pAVCtx->pix_fmt = AV_PIX_FMT_RGBA; // and other RGB formats, but it is not important here } } @@ -318,7 +325,7 @@ void FillAVCodecProps(struct AVCodecContext* pAVCtx, BITMAPINFOHEADER* pBMI) case AV_CODEC_ID_DXTORY: pAVCtx->pix_fmt = AV_PIX_FMT_RGB24; // and other RGB formats, but it is not important here break; - /* + /* case AV_CODEC_ID_VVC: { auto s = reinterpret_cast(pAVCtx->priv_data); @@ -370,7 +377,7 @@ void FillAVCodecProps(struct AVCodecContext* pAVCtx, BITMAPINFOHEADER* pBMI) } } break; - */ + */ } if (pAVCtx->pix_fmt == AV_PIX_FMT_NONE) {