diff mbox series

[FFmpeg-devel,07/11] examples/extract_mvs: Do not use stack packet

Message ID AM7PR03MB66606DAFAF2DB513575511668FCF9@AM7PR03MB6660.eurprd03.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,01/11] avformat/mux: Sanitize packets without data and side-data
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 3, 2021, 11:18 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 doc/examples/extract_mvs.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/doc/examples/extract_mvs.c b/doc/examples/extract_mvs.c
index 84f071075a..cc1311da91 100644
--- a/doc/examples/extract_mvs.c
+++ b/doc/examples/extract_mvs.c
@@ -124,7 +124,7 @@  static int open_codec_context(AVFormatContext *fmt_ctx, enum AVMediaType type)
 int main(int argc, char **argv)
 {
     int ret = 0;
-    AVPacket pkt = { 0 };
+    AVPacket *pkt = NULL;
 
     if (argc != 2) {
         fprintf(stderr, "Usage: %s <video>\n", argv[0]);
@@ -159,13 +159,20 @@  int main(int argc, char **argv)
         goto end;
     }
 
+    pkt = av_packet_alloc();
+    if (!pkt) {
+        fprintf(stderr, "Could not allocate AVPacket\n");
+        ret = AVERROR(ENOMEM);
+        goto end;
+    }
+
     printf("framenum,source,blockw,blockh,srcx,srcy,dstx,dsty,flags\n");
 
     /* read frames from the file */
-    while (av_read_frame(fmt_ctx, &pkt) >= 0) {
-        if (pkt.stream_index == video_stream_idx)
-            ret = decode_packet(&pkt);
-        av_packet_unref(&pkt);
+    while (av_read_frame(fmt_ctx, pkt) >= 0) {
+        if (pkt->stream_index == video_stream_idx)
+            ret = decode_packet(pkt);
+        av_packet_unref(pkt);
         if (ret < 0)
             break;
     }
@@ -177,5 +184,6 @@  end:
     avcodec_free_context(&video_dec_ctx);
     avformat_close_input(&fmt_ctx);
     av_frame_free(&frame);
+    av_packet_free(&pkt);
     return ret < 0;
 }