[FFmpeg-cvslog] examples/filtering_video: Don't use stack packet

Andreas Rheinhardt git at videolan.org
Sun Oct 3 23:48:34 EEST 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Fri Sep  3 23:18:14 2021 +0200| [86ec1093ebb488b3c07b0ba5a2e5962f4612477e] | committer: Andreas Rheinhardt

examples/filtering_video: Don't use stack packet

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

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

 doc/examples/filtering_video.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/doc/examples/filtering_video.c b/doc/examples/filtering_video.c
index 88394530ab..7b3e16c40c 100644
--- a/doc/examples/filtering_video.c
+++ b/doc/examples/filtering_video.c
@@ -210,7 +210,7 @@ static void display_frame(const AVFrame *frame, AVRational time_base)
 int main(int argc, char **argv)
 {
     int ret;
-    AVPacket packet;
+    AVPacket *packet;
     AVFrame *frame;
     AVFrame *filt_frame;
 
@@ -221,8 +221,9 @@ int main(int argc, char **argv)
 
     frame = av_frame_alloc();
     filt_frame = av_frame_alloc();
-    if (!frame || !filt_frame) {
-        perror("Could not allocate frame");
+    packet = av_packet_alloc();
+    if (!frame || !filt_frame || !packet) {
+        fprintf(stderr, "Could not allocate frame or packet\n");
         exit(1);
     }
 
@@ -233,11 +234,11 @@ int main(int argc, char **argv)
 
     /* read all packets */
     while (1) {
-        if ((ret = av_read_frame(fmt_ctx, &packet)) < 0)
+        if ((ret = av_read_frame(fmt_ctx, packet)) < 0)
             break;
 
-        if (packet.stream_index == video_stream_index) {
-            ret = avcodec_send_packet(dec_ctx, &packet);
+        if (packet->stream_index == video_stream_index) {
+            ret = avcodec_send_packet(dec_ctx, packet);
             if (ret < 0) {
                 av_log(NULL, AV_LOG_ERROR, "Error while sending a packet to the decoder\n");
                 break;
@@ -273,7 +274,7 @@ int main(int argc, char **argv)
                 av_frame_unref(frame);
             }
         }
-        av_packet_unref(&packet);
+        av_packet_unref(packet);
     }
 end:
     avfilter_graph_free(&filter_graph);
@@ -281,6 +282,7 @@ end:
     avformat_close_input(&fmt_ctx);
     av_frame_free(&frame);
     av_frame_free(&filt_frame);
+    av_packet_free(&packet);
 
     if (ret < 0 && ret != AVERROR_EOF) {
         fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));



More information about the ffmpeg-cvslog mailing list