ffmpeg: pass reference counted packet on codec copy when possible
authorJames Almer <jamrial@gmail.com>
Wed, 21 Mar 2018 14:43:04 +0000 (11:43 -0300)
committerJames Almer <jamrial@gmail.com>
Sat, 24 Mar 2018 01:05:25 +0000 (22:05 -0300)
Should prevent unnecessary copy of data in cases where new references
to the packet are created within the muxer or a bitstream filter.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
fftools/ffmpeg.c

index ec9ce29..1b2e37b 100644 (file)
@@ -2049,6 +2049,11 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
 
     opkt.flags    = pkt->flags;
 
+    if (pkt->buf) {
+        opkt.buf = av_buffer_ref(pkt->buf);
+        if (!opkt.buf)
+            exit_program(1);
+    }
     opkt.data = pkt->data;
     opkt.size = pkt->size;