]> granicus.if.org Git - handbrake/commitdiff
muxavformat: use alternate API to initialize out context
authorJohn Stebbins <jstebbins.hb@gmail.com>
Fri, 15 Jun 2018 21:51:59 +0000 (14:51 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Fri, 15 Jun 2018 21:51:59 +0000 (14:51 -0700)
avformat_alloc_output_context2 does several things for us that we were
doing in separate steps.  It also allocates AVFormatContext.url for us
so we do not have a case where we alloc something that ffmpeg frees.

libhb/muxavformat.c

index f8a0ab984f179eef148d12bbded4dc50a3452884..f92777097ecedb201558d5aec21f0901aefe1b31 100644 (file)
@@ -132,16 +132,8 @@ static int avformatInit( hb_mux_object_t * m )
 
     max_tracks = 1 + hb_list_count( job->list_audio ) +
                      hb_list_count( job->list_subtitle );
-
     m->tracks = calloc(max_tracks, sizeof(hb_mux_data_t*));
 
-    m->oc = avformat_alloc_context();
-    if (m->oc == NULL)
-    {
-        hb_error( "Could not initialize avformat context." );
-        goto error;
-    }
-
     AVDictionary * av_opts = NULL;
     switch (job->mux)
     {
@@ -176,13 +168,14 @@ static int avformatInit( hb_mux_object_t * m )
             goto error;
         }
     }
-    m->oc->oformat = av_guess_format(muxer_name, NULL, NULL);
-    if(m->oc->oformat == NULL)
+
+    ret = avformat_alloc_output_context2(&m->oc, NULL, muxer_name, job->file);
+    if (ret < 0)
     {
-        hb_error("Could not guess output format %s", muxer_name);
+        hb_error( "Could not initialize avformat context." );
         goto error;
     }
-    m->oc->url = av_strdup(job->file);
+
     ret = avio_open2(&m->oc->pb, job->file, AVIO_FLAG_WRITE,
                      &m->oc->interrupt_callback, NULL);
     if( ret < 0 )