diff mbox series

[FFmpeg-devel,03/11] fftools/ffmpeg, doc/examples: Remove redundant av_packet_unref

Message ID AM7PR03MB6660D7351668E83850AC4DCF8FCF9@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 8a23159797f8ab60c4e01307e94d2801149617b0
Headers show
Series [FFmpeg-devel,01/11] avformat/mux: Sanitize packets without data and side-data | expand

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
av_interleaved_write_frame() already returns blank packets.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 doc/examples/muxing.c   | 4 +++-
 doc/examples/remuxing.c | 4 +++-
 fftools/ffmpeg.c        | 1 -
 3 files changed, 6 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/doc/examples/muxing.c b/doc/examples/muxing.c
index abc14a8910..879fe06299 100644
--- a/doc/examples/muxing.c
+++ b/doc/examples/muxing.c
@@ -110,7 +110,9 @@  static int write_frame(AVFormatContext *fmt_ctx, AVCodecContext *c,
         /* Write the compressed frame to the media file. */
         log_packet(fmt_ctx, &pkt);
         ret = av_interleaved_write_frame(fmt_ctx, &pkt);
-        av_packet_unref(&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(). */
         if (ret < 0) {
             fprintf(stderr, "Error while writing output packet: %s\n", av_err2str(ret));
             exit(1);
diff --git a/doc/examples/remuxing.c b/doc/examples/remuxing.c
index 13313a1748..9835cc4c00 100644
--- a/doc/examples/remuxing.c
+++ b/doc/examples/remuxing.c
@@ -163,11 +163,13 @@  int main(int argc, char **argv)
         log_packet(ofmt_ctx, &pkt, "out");
 
         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(). */
         if (ret < 0) {
             fprintf(stderr, "Error muxing packet\n");
             break;
         }
-        av_packet_unref(&pkt);
     }
 
     av_write_trailer(ofmt_ctx);
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index c3df955a6a..f681fa2e87 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -869,7 +869,6 @@  static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int u
         main_return_code = 1;
         close_all_output_streams(ost, MUXER_FINISHED | ENCODER_FINISHED, ENCODER_FINISHED);
     }
-    av_packet_unref(pkt);
 }
 
 static void close_output_stream(OutputStream *ost)