[FFmpeg-cvslog] Merge commit '7295b7373862ee54903b33d6ef3335531dfa93ad'

Rodger Combs git at videolan.org
Tue Sep 26 20:33:20 EEST 2017


ffmpeg | branch: master | Rodger Combs <rodger.combs at gmail.com> | Tue Sep 26 14:13:09 2017 -0300| [1b8ef01f04ab2210a26b59d3a1a62daed52ce88a] | committer: James Almer

Merge commit '7295b7373862ee54903b33d6ef3335531dfa93ad'

* commit '7295b7373862ee54903b33d6ef3335531dfa93ad':
  dashenc: add webm support

Merged-by: Rodger Combs <rodger.combs at gmail.com>

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

 libavformat/dashenc.c | 101 ++++++++++++++++++++++++++++++++++++++++----------
 libavformat/version.h |   2 +-
 2 files changed, 82 insertions(+), 21 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index bde938f587..240ff41380 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -61,6 +61,7 @@ typedef struct OutputStream {
     AVFormatContext *ctx;
     int ctx_inited, as_idx;
     AVIOContext *out;
+    char format_name[8];
     int packets_written;
     char initfile[1024];
     int64_t init_start_pos, pos;
@@ -101,12 +102,32 @@ typedef struct DASHContext {
     const char *utc_timing_url;
 } DASHContext;
 
-// RFC 6381
+static struct codec_string {
+    int id;
+    const char *str;
+} codecs[] = {
+    { AV_CODEC_ID_VP8, "vp8" },
+    { AV_CODEC_ID_VP9, "vp9" },
+    { AV_CODEC_ID_VORBIS, "vorbis" },
+    { AV_CODEC_ID_OPUS, "opus" },
+    { 0, NULL }
+};
+
 static void set_codec_str(AVFormatContext *s, AVCodecParameters *par,
                           char *str, int size)
 {
     const AVCodecTag *tags[2] = { NULL, NULL };
     uint32_t tag;
+    int i;
+
+    // common Webm codecs are not part of RFC 6381
+    for (i = 0; codecs[i].id; i++)
+        if (codecs[i].id == par->codec_id) {
+            av_strlcpy(str, codecs[i].str, size);
+            return;
+        }
+
+    // for codecs part of RFC 6381
     if (par->codec_type == AVMEDIA_TYPE_VIDEO)
         tags[0] = ff_codec_movvideo_tags;
     else if (par->codec_type == AVMEDIA_TYPE_AUDIO)
@@ -189,6 +210,21 @@ static int flush_dynbuf(OutputStream *os, int *range_length)
     return avio_open_dyn_buf(&os->ctx->pb);
 }
 
+static int flush_init_segment(AVFormatContext *s, OutputStream *os)
+{
+    DASHContext *c = s->priv_data;
+    int ret, range_length;
+
+    ret = flush_dynbuf(os, &range_length);
+    if (ret < 0)
+        return ret;
+
+    os->pos = os->init_range_length = range_length;
+    if (!c->single_file)
+        ff_format_io_close(s, &os->out);
+    return 0;
+}
+
 static void dash_free(AVFormatContext *s)
 {
     DASHContext *c = s->priv_data;
@@ -376,14 +412,14 @@ static int write_adaptation_set(AVFormatContext *s, AVIOContext *out, int as_ind
 
         if (as->media_type == AVMEDIA_TYPE_VIDEO) {
             AVStream *st = s->streams[i];
-            avio_printf(out, "\t\t\t<Representation id=\"%d\" mimeType=\"video/mp4\" codecs=\"%s\"%s width=\"%d\" height=\"%d\"",
-                i, os->codec_str, os->bandwidth_str, s->streams[i]->codecpar->width, s->streams[i]->codecpar->height);
+            avio_printf(out, "\t\t\t<Representation id=\"%d\" mimeType=\"video/%s\" codecs=\"%s\"%s width=\"%d\" height=\"%d\"",
+                i, os->format_name, os->codec_str, os->bandwidth_str, s->streams[i]->codecpar->width, s->streams[i]->codecpar->height);
             if (st->avg_frame_rate.num)
                 avio_printf(out, " frameRate=\"%d/%d\"", st->avg_frame_rate.num, st->avg_frame_rate.den);
             avio_printf(out, ">\n");
         } else {
-            avio_printf(out, "\t\t\t<Representation id=\"%d\" mimeType=\"audio/mp4\" codecs=\"%s\"%s audioSamplingRate=\"%d\">\n",
-                i, os->codec_str, os->bandwidth_str, s->streams[i]->codecpar->sample_rate);
+            avio_printf(out, "\t\t\t<Representation id=\"%d\" mimeType=\"audio/%s\" codecs=\"%s\"%s audioSamplingRate=\"%d\">\n",
+                i, os->format_name, os->codec_str, os->bandwidth_str, s->streams[i]->codecpar->sample_rate);
             avio_printf(out, "\t\t\t\t<AudioChannelConfiguration schemeIdUri=\"urn:mpeg:dash:23003:3:audio_channel_configuration:2011\" value=\"%d\" />\n",
                 s->streams[i]->codecpar->channels);
         }
@@ -628,11 +664,18 @@ static int dict_copy_entry(AVDictionary **dst, const AVDictionary *src, const ch
     return 0;
 }
 
+static int dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
+{
+    char valuestr[22];
+    snprintf(valuestr, sizeof(valuestr), "%"PRId64, value);
+    flags &= ~AV_DICT_DONT_STRDUP_VAL;
+    return av_dict_set(pm, key, valuestr, flags);
+}
+
 static int dash_init(AVFormatContext *s)
 {
     DASHContext *c = s->priv_data;
     int ret = 0, i;
-    AVOutputFormat *oformat;
     char *ptr;
     char basename[1024];
 
@@ -656,10 +699,6 @@ static int dash_init(AVFormatContext *s)
     if (ptr)
         *ptr = '\0';
 
-    oformat = av_guess_format("mp4", NULL, NULL);
-    if (!oformat)
-        return AVERROR_MUXER_NOT_FOUND;
-
     c->streams = av_mallocz(sizeof(*c->streams) * s->nb_streams);
     if (!c->streams)
         return AVERROR(ENOMEM);
@@ -694,8 +733,22 @@ static int dash_init(AVFormatContext *s)
         ctx = avformat_alloc_context();
         if (!ctx)
             return AVERROR(ENOMEM);
+
+        // choose muxer based on codec: webm for VP8/9 and opus, mp4 otherwise
+        // note: os->format_name is also used as part of the mimetype of the
+        //       representation, e.g. video/<format_name>
+        if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_VP8 ||
+            s->streams[i]->codecpar->codec_id == AV_CODEC_ID_VP9 ||
+            s->streams[i]->codecpar->codec_id == AV_CODEC_ID_OPUS ||
+            s->streams[i]->codecpar->codec_id == AV_CODEC_ID_VORBIS) {
+            snprintf(os->format_name, sizeof(os->format_name), "webm");
+        } else {
+            snprintf(os->format_name, sizeof(os->format_name), "mp4");
+        }
+        ctx->oformat = av_guess_format(os->format_name, NULL, NULL);
+        if (!ctx->oformat)
+            return AVERROR_MUXER_NOT_FOUND;
         os->ctx = ctx;
-        ctx->oformat = oformat;
         ctx->interrupt_callback = s->interrupt_callback;
         ctx->opaque             = s->opaque;
         ctx->io_close           = s->io_close;
@@ -726,8 +779,13 @@ static int dash_init(AVFormatContext *s)
             return ret;
         os->init_start_pos = 0;
 
-        av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov", 0);
-        if ((ret = avformat_init_output(ctx, &opts)) < 0)
+        if (!strcmp(os->format_name, "mp4")) {
+            av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov", 0);
+        } else {
+            dict_set_int(&opts, "cluster_time_limit", c->min_seg_duration / 1000, 0);
+            dict_set_int(&opts, "cluster_size_limit", 5 * 1024 * 1024, 0); // set a large cluster size limit
+        }
+        if ((ret = avformat_write_header(ctx, &opts)) < 0)
             return ret;
         os->ctx_inited = 1;
         avio_flush(ctx->pb);
@@ -735,6 +793,13 @@ static int dash_init(AVFormatContext *s)
 
         av_log(s, AV_LOG_VERBOSE, "Representation %d init segment will be written to: %s\n", i, filename);
 
+        // Flush init segment
+        // except for mp4, since delay_moov is set and the init segment
+        // is then flushed after the first packets
+        if (strcmp(os->format_name, "mp4")) {
+            flush_init_segment(s, os);
+        }
+
         s->streams[i]->time_base = st->time_base;
         // If the muxer wants to shift timestamps, request to have them shifted
         // already before being handed to this muxer, so we don't have mismatches
@@ -907,12 +972,7 @@ static int dash_flush(AVFormatContext *s, int final, int stream)
         }
 
         if (!os->init_range_length) {
-            ret = flush_dynbuf(os, &range_length);
-            if (ret < 0)
-                break;
-            os->pos = os->init_range_length = range_length;
-            if (!c->single_file)
-                ff_format_io_close(s, &os->out);
+            flush_init_segment(s, os);
         }
 
         if (!c->single_file) {
@@ -922,7 +982,8 @@ static int dash_flush(AVFormatContext *s, int final, int stream)
             ret = s->io_open(s, &os->out, temp_path, AVIO_FLAG_WRITE, NULL);
             if (ret < 0)
                 break;
-            write_styp(os->ctx->pb);
+            if (!strcmp(os->format_name, "mp4"))
+                write_styp(os->ctx->pb);
         } else {
             snprintf(full_path, sizeof(full_path), "%s%s", c->dirname, os->initfile);
         }
diff --git a/libavformat/version.h b/libavformat/version.h
index 499aecf6c7..ac6edf7ea9 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -33,7 +33,7 @@
 // Also please add any ticket numbers that you believe might be affected here
 #define LIBAVFORMAT_VERSION_MAJOR  57
 #define LIBAVFORMAT_VERSION_MINOR  82
-#define LIBAVFORMAT_VERSION_MICRO 101
+#define LIBAVFORMAT_VERSION_MICRO 102
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \


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

diff --cc libavformat/dashenc.c
index bde938f587,7134af4978..240ff41380
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@@ -375,15 -527,11 +411,15 @@@ static int write_adaptation_set(AVForma
              continue;
  
          if (as->media_type == AVMEDIA_TYPE_VIDEO) {
 -            avio_printf(out, "\t\t\t<Representation id=\"%d\" mimeType=\"video/%s\" codecs=\"%s\"%s width=\"%d\" height=\"%d\">\n",
 +            AVStream *st = s->streams[i];
-             avio_printf(out, "\t\t\t<Representation id=\"%d\" mimeType=\"video/mp4\" codecs=\"%s\"%s width=\"%d\" height=\"%d\"",
-                 i, os->codec_str, os->bandwidth_str, s->streams[i]->codecpar->width, s->streams[i]->codecpar->height);
++            avio_printf(out, "\t\t\t<Representation id=\"%d\" mimeType=\"video/%s\" codecs=\"%s\"%s width=\"%d\" height=\"%d\"",
+                 i, os->format_name, os->codec_str, os->bandwidth_str, s->streams[i]->codecpar->width, s->streams[i]->codecpar->height);
 +            if (st->avg_frame_rate.num)
 +                avio_printf(out, " frameRate=\"%d/%d\"", st->avg_frame_rate.num, st->avg_frame_rate.den);
 +            avio_printf(out, ">\n");
          } else {
-             avio_printf(out, "\t\t\t<Representation id=\"%d\" mimeType=\"audio/mp4\" codecs=\"%s\"%s audioSamplingRate=\"%d\">\n",
-                 i, os->codec_str, os->bandwidth_str, s->streams[i]->codecpar->sample_rate);
+             avio_printf(out, "\t\t\t<Representation id=\"%d\" mimeType=\"audio/%s\" codecs=\"%s\"%s audioSamplingRate=\"%d\">\n",
+                 i, os->format_name, os->codec_str, os->bandwidth_str, s->streams[i]->codecpar->sample_rate);
              avio_printf(out, "\t\t\t\t<AudioChannelConfiguration schemeIdUri=\"urn:mpeg:dash:23003:3:audio_channel_configuration:2011\" value=\"%d\" />\n",
                  s->streams[i]->codecpar->channels);
          }
@@@ -628,7 -766,15 +664,15 @@@ static int dict_copy_entry(AVDictionar
      return 0;
  }
  
+ static int dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
+ {
+     char valuestr[22];
+     snprintf(valuestr, sizeof(valuestr), "%"PRId64, value);
+     flags &= ~AV_DICT_DONT_STRDUP_VAL;
+     return av_dict_set(pm, key, valuestr, flags);
+ }
+ 
 -static int dash_write_header(AVFormatContext *s)
 +static int dash_init(AVFormatContext *s)
  {
      DASHContext *c = s->priv_data;
      int ret = 0, i;
@@@ -656,16 -800,14 +699,12 @@@
      if (ptr)
          *ptr = '\0';
  
-     oformat = av_guess_format("mp4", NULL, NULL);
-     if (!oformat)
-         return AVERROR_MUXER_NOT_FOUND;
- 
      c->streams = av_mallocz(sizeof(*c->streams) * s->nb_streams);
 -    if (!c->streams) {
 -        ret = AVERROR(ENOMEM);
 -        goto fail;
 -    }
 +    if (!c->streams)
 +        return AVERROR(ENOMEM);
  
      if ((ret = parse_adaptation_sets(s)) < 0)
 -        goto fail;
 +        return ret;
  
      for (i = 0; i < s->nb_streams; i++) {
          OutputStream *os = &c->streams[i];
@@@ -692,10 -836,28 +731,24 @@@
          dict_copy_entry(&as->metadata, s->streams[i]->metadata, "role");
  
          ctx = avformat_alloc_context();
 -        if (!ctx) {
 -            ret = AVERROR(ENOMEM);
 -            goto fail;
 -        }
 +        if (!ctx)
 +            return AVERROR(ENOMEM);
+ 
+         // choose muxer based on codec: webm for VP8/9 and opus, mp4 otherwise
+         // note: os->format_name is also used as part of the mimetype of the
+         //       representation, e.g. video/<format_name>
+         if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_VP8 ||
+             s->streams[i]->codecpar->codec_id == AV_CODEC_ID_VP9 ||
+             s->streams[i]->codecpar->codec_id == AV_CODEC_ID_OPUS ||
+             s->streams[i]->codecpar->codec_id == AV_CODEC_ID_VORBIS) {
+             snprintf(os->format_name, sizeof(os->format_name), "webm");
+         } else {
+             snprintf(os->format_name, sizeof(os->format_name), "mp4");
+         }
+         ctx->oformat = av_guess_format(os->format_name, NULL, NULL);
 -        if (!ctx->oformat) {
 -            ret = AVERROR_MUXER_NOT_FOUND;
 -            goto fail;
 -        }
++        if (!ctx->oformat)
++            return AVERROR_MUXER_NOT_FOUND;
          os->ctx = ctx;
-         ctx->oformat = oformat;
          ctx->interrupt_callback = s->interrupt_callback;
          ctx->opaque             = s->opaque;
          ctx->io_close           = s->io_close;
@@@ -723,12 -886,18 +776,17 @@@
          snprintf(filename, sizeof(filename), "%s%s", c->dirname, os->initfile);
          ret = s->io_open(s, &os->out, filename, AVIO_FLAG_WRITE, NULL);
          if (ret < 0)
 -            goto fail;
 +            return ret;
          os->init_start_pos = 0;
  
-         av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov", 0);
-         if ((ret = avformat_init_output(ctx, &opts)) < 0)
+         if (!strcmp(os->format_name, "mp4")) {
+             av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov", 0);
+         } else {
+             dict_set_int(&opts, "cluster_time_limit", c->min_seg_duration / 1000, 0);
+             dict_set_int(&opts, "cluster_size_limit", 5 * 1024 * 1024, 0); // set a large cluster size limit
+         }
 -        if ((ret = avformat_write_header(ctx, &opts)) < 0) {
 -             goto fail;
 -        }
++        if ((ret = avformat_write_header(ctx, &opts)) < 0)
 +            return ret;
          os->ctx_inited = 1;
          avio_flush(ctx->pb);
          av_dict_free(&opts);
diff --cc libavformat/version.h
index 499aecf6c7,65d5754630..ac6edf7ea9
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@@ -29,11 -29,9 +29,11 @@@
  
  #include "libavutil/version.h"
  
 -#define LIBAVFORMAT_VERSION_MAJOR 57
 -#define LIBAVFORMAT_VERSION_MINOR 10
 -#define LIBAVFORMAT_VERSION_MICRO  3
 +// Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
 +// Also please add any ticket numbers that you believe might be affected here
 +#define LIBAVFORMAT_VERSION_MAJOR  57
 +#define LIBAVFORMAT_VERSION_MINOR  82
- #define LIBAVFORMAT_VERSION_MICRO 101
++#define LIBAVFORMAT_VERSION_MICRO 102
  
  #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                 LIBAVFORMAT_VERSION_MINOR, \



More information about the ffmpeg-cvslog mailing list