[FFmpeg-devel] [PATCH 6/8] avformat/mux: do not destroy packets of av_write_frame on bitstream filtering

Marton Balint cus at passwd.hu
Sat Mar 28 20:15:13 EET 2020


av_write_frame() does not take ownership of the packet.

Signed-off-by: Marton Balint <cus at passwd.hu>
---
 libavformat/mux.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavformat/mux.c b/libavformat/mux.c
index 3054ab8644..706fdcbbf4 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -935,7 +935,16 @@ static int write_packets_common(AVFormatContext *s, AVStream *st, AVPacket *pkt,
             if (ret < 0) {
                 if (ret == AVERROR(EAGAIN) && !consumed_packet) {
                     av_assert2(sti->bsfcs_idx == 0);
-                    ret = av_bsf_send_packet(sti->bsfcs[0], pkt);
+                    if (!interleaved && pkt) {
+                        AVPacket tmp;
+                        ret = av_packet_ref(&tmp, pkt);
+                        if (ret < 0)
+                            goto fail;
+                        ret = av_bsf_send_packet(sti->bsfcs[0], &tmp);
+                        av_packet_unref(&tmp);
+                    } else {
+                        ret = av_bsf_send_packet(sti->bsfcs[0], pkt);
+                    }
                     av_assert2(ret != AVERROR(EAGAIN));
                     if (ret >= 0) {
                         consumed_packet = 1;
-- 
2.16.4



More information about the ffmpeg-devel mailing list