[FFmpeg-devel] [PATCH 6/8] libavformat/dashenc: use avformat_alloc_output_context2 for initializing context

Peter Große pegro at friiks.de
Sat Jan 21 16:39:07 EET 2017


Also copy stream metadata to output stream.

Signed-off-by: Peter Große <pegro at friiks.de>
---
 libavformat/dashenc.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index fd1a304..0c0248f 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -572,7 +572,6 @@ static int dash_init(AVFormatContext *s)
 {
     DASHContext *c = s->priv_data;
     int ret = 0, i;
-    AVOutputFormat *oformat;
     char *ptr;
     char basename[1024];
 
@@ -596,10 +595,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);
@@ -623,23 +618,25 @@ static int dash_init(AVFormatContext *s)
                 return AVERROR(EINVAL);
         }
 
-        ctx = avformat_alloc_context();
-        if (!ctx)
+        ret = avformat_alloc_output_context2(&ctx, NULL, "mp4", NULL);
+        if (ret < 0)
             return AVERROR(ENOMEM);
         os->ctx = ctx;
-        ctx->oformat = oformat;
         ctx->interrupt_callback = s->interrupt_callback;
         ctx->opaque             = s->opaque;
         ctx->io_close           = s->io_close;
         ctx->io_open            = s->io_open;
+        av_dict_copy(&ctx->metadata, s->metadata, 0);
 
         if (!(st = avformat_new_stream(ctx, NULL)))
             return AVERROR(ENOMEM);
         avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar);
         st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
         st->time_base = s->streams[i]->time_base;
+        st->avg_frame_rate = s->streams[i]->avg_frame_rate;
         ctx->avoid_negative_ts = s->avoid_negative_ts;
         ctx->flags = s->flags;
+        ctx->max_delay = s->max_delay;
 
         ret = avio_open_dyn_buf(&ctx->pb);
         if (ret < 0)
-- 
2.10.2



More information about the ffmpeg-devel mailing list