[FFmpeg-cvslog] doc/examples/extract_mvs: make pkt local to the main function

Matthieu Bouron git at videolan.org
Tue Apr 4 13:10:48 EEST 2017


ffmpeg | branch: master | Matthieu Bouron <matthieu.bouron at gmail.com> | Mon Apr  3 16:15:58 2017 +0200| [1cf93196fc6993541194c06a67bd59e45a4b3a44] | committer: Matthieu Bouron

doc/examples/extract_mvs: make pkt local to the main function

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1cf93196fc6993541194c06a67bd59e45a4b3a44
---

 doc/examples/extract_mvs.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/doc/examples/extract_mvs.c b/doc/examples/extract_mvs.c
index d6730db..552a733 100644
--- a/doc/examples/extract_mvs.c
+++ b/doc/examples/extract_mvs.c
@@ -31,13 +31,11 @@ static const char *src_filename = NULL;
 
 static int video_stream_idx = -1;
 static AVFrame *frame = NULL;
-static AVPacket pkt;
 static int video_frame_count = 0;
 
-static int decode_packet(void)
+static int decode_packet(const AVPacket *pkt)
 {
-    if (pkt.stream_index == video_stream_idx) {
-        int ret = avcodec_send_packet(video_dec_ctx, &pkt);
+        int ret = avcodec_send_packet(video_dec_ctx, pkt);
         if (ret < 0) {
             fprintf(stderr, "Error while sending a packet to the decoder: %s\n", av_err2str(ret));
             return ret;
@@ -71,7 +69,6 @@ static int decode_packet(void)
                 av_frame_unref(frame);
             }
         }
-    }
 
     return 0;
 }
@@ -124,6 +121,7 @@ static int open_codec_context(AVFormatContext *fmt_ctx, enum AVMediaType type)
 int main(int argc, char **argv)
 {
     int ret = 0;
+    AVPacket pkt = { 0 };
 
     if (argc != 2) {
         fprintf(stderr, "Usage: %s <video>\n", argv[0]);
@@ -162,21 +160,17 @@ int main(int argc, char **argv)
 
     printf("framenum,source,blockw,blockh,srcx,srcy,dstx,dsty,flags\n");
 
-    /* initialize packet, set data to NULL, let the demuxer fill it */
-    av_init_packet(&pkt);
-
     /* read frames from the file */
     while (av_read_frame(fmt_ctx, &pkt) >= 0) {
-        ret = decode_packet();
+        if (pkt.stream_index == video_stream_idx)
+            ret = decode_packet(&pkt);
         av_packet_unref(&pkt);
         if (ret < 0)
             break;
     }
 
     /* flush cached frames */
-    pkt.data = NULL;
-    pkt.size = 0;
-    decode_packet();
+    decode_packet(NULL);
 
 end:
     avcodec_free_context(&video_dec_ctx);



More information about the ffmpeg-cvslog mailing list