From 6ba36deee93f01cf7e89db4172f8e3dc7d56d997 Mon Sep 17 00:00:00 2001 From: JPikachu Date: Wed, 9 Apr 2025 19:36:24 +0100 Subject: [PATCH] Fix green fmv videos Credit: Antique - Sudachi Dev --- src/video_core/host1x/ffmpeg/ffmpeg.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/video_core/host1x/ffmpeg/ffmpeg.cpp b/src/video_core/host1x/ffmpeg/ffmpeg.cpp index 7e955223db..4aa3c27264 100644 --- a/src/video_core/host1x/ffmpeg/ffmpeg.cpp +++ b/src/video_core/host1x/ffmpeg/ffmpeg.cpp @@ -227,8 +227,10 @@ bool DecoderContext::SendPacket(const Packet& packet) { #ifndef ANDROID if (!m_codec_context->hw_device_ctx && m_codec_context->codec_id == AV_CODEC_ID_H264) { m_decode_order = true; - const int ret = avcodec_send_frame(m_codec_context, m_temp_frame->GetFrame()); - if (ret < 0) { + auto* codec{ffcodec(m_decoder.GetCodec())}; + if (const int ret = codec->cb.decode(m_codec_context, m_temp_frame->GetFrame(), + &m_got_frame, packet.GetPacket()); + ret < 0) { LOG_DEBUG(Service_NVDRV, "avcodec_send_packet error {}", AVError(ret)); return false; } @@ -250,6 +252,7 @@ std::shared_ptr DecoderContext::ReceiveFrame() { #ifndef ANDROID if (!m_codec_context->hw_device_ctx && m_codec_context->codec_id == AV_CODEC_ID_H264) { m_decode_order = true; + auto* codec{ffcodec(m_decoder.GetCodec())}; int ret{0}; if (m_got_frame == 0) { @@ -257,7 +260,7 @@ std::shared_ptr DecoderContext::ReceiveFrame() { auto* pkt = packet.GetPacket(); pkt->data = nullptr; pkt->size = 0; - ret = avcodec_receive_packet(m_codec_context, pkt); + ret = codec->cb.decode(m_codec_context, m_temp_frame->GetFrame(), &m_got_frame, pkt); m_codec_context->has_b_frames = 0; } @@ -303,8 +306,12 @@ std::shared_ptr DecoderContext::ReceiveFrame() { } #if defined(FF_API_INTERLACED_FRAME) || LIBAVUTIL_VERSION_MAJOR >= 59 - m_temp_frame->GetFrame()->interlaced_frame = - (m_temp_frame->GetFrame()->flags & AV_FRAME_FLAG_INTERLACED) != 0; + if (m_temp_frame->GetFrame()->flags & AV_FRAME_FLAG_INTERLACED) + m_temp_frame->GetFrame()->flags &= ~AV_FRAME_FLAG_INTERLACED; + else + m_temp_frame->GetFrame()->flags |= AV_FRAME_FLAG_INTERLACED; +#else + m_temp_frame->GetFrame()->interlaced_frame = !m_temp_frame->GetFrame()->interlaced_frame; #endif return std::move(m_temp_frame); }