Skip to content

Commit

Permalink
MPCVideoDec: исправлено определение pix_fmt для FFV1.
Browse files Browse the repository at this point in the history
FFmpeg: добавлена функция ff_ffv1_parse_extra_data для заполнения pAVCtx->priv_data. По какой-то причине FFmpeg перестал это делать.
  • Loading branch information
v0lt committed Jul 8, 2024
1 parent d79aa4a commit 4d24827
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/ExtLib/ffmpeg/libavcodec/ffv1.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
16 changes: 16 additions & 0 deletions src/ExtLib/ffmpeg/libavcodec/ffv1dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 16 additions & 9 deletions src/filters/transform/MPCVideoDec/ffmpegContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FFV1Context*>(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;
Expand All @@ -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
}
}
Expand All @@ -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<VVCContext*>(pAVCtx->priv_data);
Expand Down Expand Up @@ -370,7 +377,7 @@ void FillAVCodecProps(struct AVCodecContext* pAVCtx, BITMAPINFOHEADER* pBMI)
}
}
break;
*/
*/
}

if (pAVCtx->pix_fmt == AV_PIX_FMT_NONE) {
Expand Down

0 comments on commit 4d24827

Please sign in to comment.