[FFmpeg-cvslog] matroskaenc: write updated STREAMINFO metadata for FLAC streams if available

James Almer git at videolan.org
Fri Mar 31 21:17:54 EEST 2017


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Wed Nov  9 18:38:24 2016 -0300| [98cae966c77875e26c5958206a6cfe7eba6269e8] | committer: Anton Khirnov

matroskaenc: write updated STREAMINFO metadata for FLAC streams if available

FLAC streams originating from the FLAC encoder send updated and more
complete STREAMINFO metadata as part of the last packet, so write that
to CodecPrivate instead of the incomplete one available in extradata
during init.

Signed-off-by: James Almer <jamrial at gmail.com>
Signed-off-by: Anton Khirnov <anton at khirnov.net>

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

 libavformat/matroskaenc.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 5593237..e951a0f 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -83,6 +83,7 @@ typedef struct mkv_track {
     int             write_dts;
     int             sample_rate;
     int64_t         sample_rate_offset;
+    int64_t         codecpriv_offset;
     int64_t         ts_offset;
 } mkv_track;
 
@@ -931,6 +932,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
         break;
     }
 
+    mkv->tracks[i].codecpriv_offset = avio_tell(pb);
     ret = mkv_write_codecprivate(s, pb, par, native_id, qt_id);
     if (ret < 0)
         return ret;
@@ -1586,6 +1588,31 @@ static int mkv_check_new_extra_data(AVFormatContext *s, AVPacket *pkt)
             return AVERROR(EINVAL);
         }
         break;
+    case AV_CODEC_ID_FLAC:
+        if (side_data_size && (s->pb->seekable & AVIO_SEEKABLE_NORMAL)) {
+            AVCodecParameters *codecpriv_par;
+            int64_t curpos;
+            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);
+            curpos = avio_tell(s->pb);
+            avio_seek(s->pb, track->codecpriv_offset, SEEK_SET);
+            mkv_write_codecprivate(s, s->pb, codecpriv_par, 1, 0);
+            avio_seek(s->pb, curpos, SEEK_SET);
+            avcodec_parameters_free(&codecpriv_par);
+        }
+        break;
     default:
         if (side_data_size)
             av_log(s, AV_LOG_DEBUG, "Ignoring new extradata in a packet for stream %d.\n", pkt->stream_index);



More information about the ffmpeg-cvslog mailing list