From 2d6dfc09e11ca5f42f0d0aec2815b81cac939aa2 Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Sat, 15 Jun 2019 18:33:08 +0800 Subject: [PATCH] fix:recording with old decoding/encoding API The deprecated avcodec_decode_video2() should always the whole packet, so there is no need to loop (cf doc/examples/demuxing_decoding.c in FFmpeg). This hack changed the packet size and data pointer. This broke recording which used the same packet. --- QtScrcpy/decoder/decoder.cpp | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/QtScrcpy/decoder/decoder.cpp b/QtScrcpy/decoder/decoder.cpp index 9407772..f698466 100644 --- a/QtScrcpy/decoder/decoder.cpp +++ b/QtScrcpy/decoder/decoder.cpp @@ -367,23 +367,19 @@ void Decoder::run() av_packet_unref(&packet); goto runQuit; } -#else - while (packet.size > 0) { - int gotPicture = 0; - int len = -1; - if (decodingFrame) { - len = avcodec_decode_video2(codecCtx, decodingFrame, &gotPicture, &packet); - } - if (len < 0) { - qCritical("Could not decode video packet: %d", len); - av_packet_unref(&packet); - goto runQuit; - } - if (gotPicture) { - pushFrame(); - } - packet.size -= len; - packet.data += len; +#else + int gotPicture = 0; + int len = -1; + if (decodingFrame) { + len = avcodec_decode_video2(codecCtx, decodingFrame, &gotPicture, &packet); + } + if (len < 0) { + qCritical("Could not decode video packet: %d", len); + av_packet_unref(&packet); + goto runQuit; + } + if (gotPicture) { + pushFrame(); } #endif if (m_recorder) {