[FFmpeg-cvslog] avformat/matroskaenc: Don't needlessly copy AVCodecParameters

Andreas Rheinhardt git at videolan.org
Tue Apr 21 09:36:13 EEST 2020


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Wed Jan 22 20:03:15 2020 +0100| [75e50c3141c5e3f96110fcab5fb819736dcdc62e] | committer: Andreas Rheinhardt

avformat/matroskaenc: Don't needlessly copy AVCodecParameters

At the end of encoding, the FLAC encoder sends a packet whose side data
contains updated extradata (e.g. a correct md5 checksum). The Matroska
muxer uses this to update the CodecPrivate.

In doing so, the stream's codecpar was copied. But given that writing
a FLAC CodecPrivate does not modify the used AVCodecParameters at all,
there is no need to do so and this commit changes this.

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

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

 libavformat/matroskaenc.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index bdb768209d..71b6b6cc91 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -2173,24 +2173,16 @@ static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt)
         break;
     case AV_CODEC_ID_FLAC:
         if (side_data_size && (s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) {
-            AVCodecParameters *codecpriv_par;
+            uint8_t *old_extradata = par->extradata;
             if (side_data_size != par->extradata_size) {
                 av_log(s, AV_LOG_ERROR, "Invalid FLAC STREAMINFO metadata for output stream %d\n",
                        pkt->stream_index);
                 return AVERROR(EINVAL);
             }
-            codecpriv_par = avcodec_parameters_alloc();
-            if (!codecpriv_par)
-                return AVERROR(ENOMEM);
-            ret = avcodec_parameters_copy(codecpriv_par, par);
-            if (ret < 0) {
-                avcodec_parameters_free(&codecpriv_par);
-                return ret;
-            }
-            memcpy(codecpriv_par->extradata, side_data, side_data_size);
+            par->extradata = side_data;
             avio_seek(mkv->tracks_bc, track->codecpriv_offset, SEEK_SET);
-            mkv_write_codecprivate(s, mkv->tracks_bc, codecpriv_par, 1, 0);
-            avcodec_parameters_free(&codecpriv_par);
+            mkv_write_codecprivate(s, mkv->tracks_bc, par, 1, 0);
+            par->extradata = old_extradata;
         }
         break;
     // FIXME: Remove the following once libaom starts propagating extradata during init()



More information about the ffmpeg-cvslog mailing list