[MPlayer-dev-eng] [PATCH 2/6] gui: Use new lavc decode API for PNG decode.

Ingo Brückl ib at wupperonline.de
Thu Jan 21 14:14:49 EET 2021


Alexander Strasser wrote on Sat, 9 Jan 2021 01:11:53 +0100:

>> -    avcodec_decode_video2(avctx, frame, &decode_ok, &pkt);
>> +    avcodec_send_packet(avctx, &pkt);
>> +    decode_ok = avcodec_receive_frame(avctx, frame);

> I may be gravely misunderstanding things, but I would argue a

>     avcodec_send_packet(avctx, NULL);

> once before trying to receive, would better match the protocol
> of the send/receive API. It may never make a difference here,
> but that's not my point.

Summarizing all information, I favor the following patch:

--- a/gui/util/bitmap.c
+++ b/gui/util/bitmap.c
@@ -124,8 +124,6 @@
         return 6;
     }
 
-    avcodec_register_all();
-
     if (avcodec_open2(avctx, avcodec_find_decoder(AV_CODEC_ID_PNG), NULL) < 0) {
         av_free(frame);
         av_free(avctx);
@@ -139,7 +137,8 @@
     /* HACK: Make PNGs decode normally instead of as CorePNG delta frames. */
     pkt.flags = AV_PKT_FLAG_KEY;
 
-    avcodec_decode_video2(avctx, frame, &decode_ok, &pkt);
+    decode_ok = (avcodec_send_packet(avctx, &pkt) == 0 &&
+                 avcodec_receive_frame(avctx, frame) == 0);
 
     memset(img, 0, sizeof(*img));
     memset(palette, 0, sizeof(palette));
@@ -186,6 +185,8 @@
             decode_ok = False;
     }
 
+    avcodec_send_packet(avctx, NULL);   // flush the decoder
+
     avcodec_close(avctx);
     av_free(frame);
     av_free(avctx);


More information about the MPlayer-dev-eng mailing list