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

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


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Fri Sep  3 22:48:45 2021 +0200| [53f374c08d5cc97158c17ea34b1c8ee0116c0578] | committer: Andreas Rheinhardt

examples/remuxing: 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=53f374c08d5cc97158c17ea34b1c8ee0116c0578
---

 doc/examples/remuxing.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/doc/examples/remuxing.c b/doc/examples/remuxing.c
index 3697e488a8..9ffffded91 100644
--- a/doc/examples/remuxing.c
+++ b/doc/examples/remuxing.c
@@ -47,7 +47,7 @@ int main(int argc, char **argv)
 {
     const AVOutputFormat *ofmt = NULL;
     AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
-    AVPacket pkt;
+    AVPacket *pkt = NULL;
     const char *in_filename, *out_filename;
     int ret, i;
     int stream_index = 0;
@@ -65,6 +65,12 @@ int main(int argc, char **argv)
     in_filename  = argv[1];
     out_filename = argv[2];
 
+    pkt = av_packet_alloc();
+    if (!pkt) {
+        fprintf(stderr, "Could not allocate AVPacket\n");
+        goto end;
+    }
+
     if ((ret = avformat_open_input(&ifmt_ctx, in_filename, 0, 0)) < 0) {
         fprintf(stderr, "Could not open input file '%s'", in_filename);
         goto end;
@@ -140,27 +146,27 @@ int main(int argc, char **argv)
     while (1) {
         AVStream *in_stream, *out_stream;
 
-        ret = av_read_frame(ifmt_ctx, &pkt);
+        ret = av_read_frame(ifmt_ctx, pkt);
         if (ret < 0)
             break;
 
-        in_stream  = ifmt_ctx->streams[pkt.stream_index];
-        if (pkt.stream_index >= stream_mapping_size ||
-            stream_mapping[pkt.stream_index] < 0) {
-            av_packet_unref(&pkt);
+        in_stream  = ifmt_ctx->streams[pkt->stream_index];
+        if (pkt->stream_index >= stream_mapping_size ||
+            stream_mapping[pkt->stream_index] < 0) {
+            av_packet_unref(pkt);
             continue;
         }
 
-        pkt.stream_index = stream_mapping[pkt.stream_index];
-        out_stream = ofmt_ctx->streams[pkt.stream_index];
-        log_packet(ifmt_ctx, &pkt, "in");
+        pkt->stream_index = stream_mapping[pkt->stream_index];
+        out_stream = ofmt_ctx->streams[pkt->stream_index];
+        log_packet(ifmt_ctx, pkt, "in");
 
         /* copy packet */
-        av_packet_rescale_ts(&pkt, in_stream->time_base, out_stream->time_base);
-        pkt.pos = -1;
-        log_packet(ofmt_ctx, &pkt, "out");
+        av_packet_rescale_ts(pkt, in_stream->time_base, out_stream->time_base);
+        pkt->pos = -1;
+        log_packet(ofmt_ctx, pkt, "out");
 
-        ret = av_interleaved_write_frame(ofmt_ctx, &pkt);
+        ret = av_interleaved_write_frame(ofmt_ctx, pkt);
         /* pkt is now blank (av_interleaved_write_frame() takes ownership of
          * its contents and resets pkt), so that no unreferencing is necessary.
          * This would be different if one used av_write_frame(). */
@@ -172,6 +178,7 @@ int main(int argc, char **argv)
 
     av_write_trailer(ofmt_ctx);
 end:
+    av_packet_free(&pkt);
 
     avformat_close_input(&ifmt_ctx);
 



More information about the ffmpeg-cvslog mailing list