[FFmpeg-cvslog] Merge commit '71852a1ba89abc8749e309d9d662c49d47e19531'

Matthieu Bouron git at videolan.org
Thu Jun 23 18:01:30 CEST 2016


ffmpeg | branch: master | Matthieu Bouron <matthieu.bouron at stupeflix.com> | Thu Jun 23 17:57:34 2016 +0200| [dc62016c4b77a48284b24ad927eb68035b133925] | committer: Matthieu Bouron

Merge commit '71852a1ba89abc8749e309d9d662c49d47e19531'

* commit '71852a1ba89abc8749e309d9d662c49d47e19531':
  matroskaenc: Provide output bytestream markers

Merged-by: Matthieu Bouron <matthieu.bouron at stupeflix.com>

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

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

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 6252de8..53353bd 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -119,6 +119,7 @@ typedef struct MatroskaMuxContext {
     AVPacket        cur_audio_pkt;
 
     int have_attachments;
+    int have_video;
 
     int reserve_cues_space;
     int cluster_size_limit;
@@ -1055,6 +1056,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
 
     switch (par->codec_type) {
     case AVMEDIA_TYPE_VIDEO:
+        mkv->have_video = 1;
         put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_VIDEO);
 
         if(   st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0
@@ -2035,6 +2037,11 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
         mkv_start_new_cluster(s, pkt);
     }
 
+    if (!mkv->cluster_pos)
+        avio_write_marker(s->pb,
+                          av_rescale_q(pkt->dts, s->streams[pkt->stream_index]->time_base, AV_TIME_BASE_Q),
+                          keyframe && (mkv->have_video ? codec_type == AVMEDIA_TYPE_VIDEO : 1) ? AVIO_DATA_MARKER_SYNC_POINT : AVIO_DATA_MARKER_BOUNDARY_POINT);
+
     // check if we have an audio packet cached
     if (mkv->cur_audio_pkt.size > 0) {
         // for DASH audio, a CuePoint has to be added when there is a new cluster.


======================================================================

diff --cc libavformat/matroskaenc.c
index 6252de8,dd5552c..53353bd
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@@ -1055,13 -844,10 +1056,14 @@@ static int mkv_write_track(AVFormatCont
  
      switch (par->codec_type) {
      case AVMEDIA_TYPE_VIDEO:
+         mkv->have_video = 1;
          put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_VIDEO);
 -        if (st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0)
 -            put_ebml_uint(pb, MATROSKA_ID_TRACKDEFAULTDURATION, 1E9 / av_q2d(st->avg_frame_rate));
 +
 +        if(   st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0
 +           && av_cmp_q(av_inv_q(st->avg_frame_rate), st->time_base) > 0)
 +            put_ebml_uint(pb, MATROSKA_ID_TRACKDEFAULTDURATION, 1000000000LL * st->avg_frame_rate.den / st->avg_frame_rate.num);
 +        else
 +            put_ebml_uint(pb, MATROSKA_ID_TRACKDEFAULTDURATION, 1000000000LL * st->time_base.num / st->time_base.den);
  
          if (!native_id &&
              ff_codec_get_tag(ff_codec_movvideo_tags, par->codec_id) &&
@@@ -2006,40 -1614,37 +2008,45 @@@ static int mkv_write_packet(AVFormatCon
      // start a new cluster every 5 MB or 5 sec, or 32k / 1 sec for streaming or
      // after 4k and on a keyframe
      if (s->pb->seekable) {
 -        pb = s->pb;
 -        cluster_size = avio_tell(pb) - mkv->cluster_pos;
 +        cluster_size = avio_tell(s->pb) - mkv->cluster_pos;
      } else {
 -        pb = mkv->dyn_bc;
 -        cluster_size = avio_tell(pb);
 -    }
 -
 -    if (mkv->cluster_pos &&
 -        (cluster_size > mkv->cluster_size_limit ||
 -         cluster_time > mkv->cluster_time_limit ||
 -         (codec_type == AVMEDIA_TYPE_VIDEO && keyframe &&
 -          cluster_size > 4 * 1024))) {
 -        av_log(s, AV_LOG_DEBUG,
 -               "Starting new cluster at offset %" PRIu64 " bytes, "
 -               "pts %" PRIu64 "dts %" PRIu64 "\n",
 -               avio_tell(pb), pkt->pts, pkt->dts);
 -        end_ebml_master(pb, mkv->cluster);
 -        mkv->cluster_pos = 0;
 -        if (mkv->dyn_bc)
 -            mkv_flush_dynbuf(s);
 -        avio_flush(s->pb);
 +        cluster_size = avio_tell(mkv->dyn_bc);
 +    }
 +
 +    if (mkv->is_dash && codec_type == AVMEDIA_TYPE_VIDEO) {
 +        // WebM DASH specification states that the first block of every cluster
 +        // has to be a key frame. So for DASH video, we only create a cluster
 +        // on seeing key frames.
 +        start_new_cluster = keyframe;
 +    } else if (mkv->is_dash && codec_type == AVMEDIA_TYPE_AUDIO &&
 +               (mkv->cluster_pos == -1 ||
 +                cluster_time > mkv->cluster_time_limit)) {
 +        // For DASH audio, we create a Cluster based on cluster_time_limit
 +        start_new_cluster = 1;
 +    } else if (!mkv->is_dash &&
 +               (cluster_size > mkv->cluster_size_limit ||
 +                cluster_time > mkv->cluster_time_limit ||
 +                (codec_type == AVMEDIA_TYPE_VIDEO && keyframe &&
 +                 cluster_size > 4 * 1024))) {
 +        start_new_cluster = 1;
 +    } else {
 +        start_new_cluster = 0;
 +    }
 +
 +    if (mkv->cluster_pos != -1 && start_new_cluster) {
 +        mkv_start_new_cluster(s, pkt);
      }
  
+     if (!mkv->cluster_pos)
+         avio_write_marker(s->pb,
+                           av_rescale_q(pkt->dts, s->streams[pkt->stream_index]->time_base, AV_TIME_BASE_Q),
+                           keyframe && (mkv->have_video ? codec_type == AVMEDIA_TYPE_VIDEO : 1) ? AVIO_DATA_MARKER_SYNC_POINT : AVIO_DATA_MARKER_BOUNDARY_POINT);
+ 
      // check if we have an audio packet cached
      if (mkv->cur_audio_pkt.size > 0) {
 -        ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt);
 +        // for DASH audio, a CuePoint has to be added when there is a new cluster.
 +        ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt,
 +                                        mkv->is_dash ? start_new_cluster : 0);
          av_packet_unref(&mkv->cur_audio_pkt);
          if (ret < 0) {
              av_log(s, AV_LOG_ERROR,



More information about the ffmpeg-cvslog mailing list