]> git.sesse.net Git - ffmpeg/blobdiff - avconv.c
avconv: rename 'icodec' to 'dec_ctx'
[ffmpeg] / avconv.c
index 5d4daba5cd6e6f5fc9d571780d2e4c8c1abb55b9..1dad8900c7c6c4f8003b057cec6318a7fa37c140 100644 (file)
--- a/avconv.c
+++ b/avconv.c
@@ -145,46 +145,52 @@ static void avconv_cleanup(int ret)
     int i, j;
 
     for (i = 0; i < nb_filtergraphs; i++) {
-        avfilter_graph_free(&filtergraphs[i]->graph);
-        for (j = 0; j < filtergraphs[i]->nb_inputs; j++) {
-            av_freep(&filtergraphs[i]->inputs[j]->name);
-            av_freep(&filtergraphs[i]->inputs[j]);
+        FilterGraph *fg = filtergraphs[i];
+        avfilter_graph_free(&fg->graph);
+        for (j = 0; j < fg->nb_inputs; j++) {
+            av_freep(&fg->inputs[j]->name);
+            av_freep(&fg->inputs[j]);
         }
-        av_freep(&filtergraphs[i]->inputs);
-        for (j = 0; j < filtergraphs[i]->nb_outputs; j++) {
-            av_freep(&filtergraphs[i]->outputs[j]->name);
-            av_freep(&filtergraphs[i]->outputs[j]);
+        av_freep(&fg->inputs);
+        for (j = 0; j < fg->nb_outputs; j++) {
+            av_freep(&fg->outputs[j]->name);
+            av_freep(&fg->outputs[j]);
         }
-        av_freep(&filtergraphs[i]->outputs);
-        av_freep(&filtergraphs[i]->graph_desc);
+        av_freep(&fg->outputs);
+        av_freep(&fg->graph_desc);
+
         av_freep(&filtergraphs[i]);
     }
     av_freep(&filtergraphs);
 
     /* close files */
     for (i = 0; i < nb_output_files; i++) {
-        AVFormatContext *s = output_files[i]->ctx;
+        OutputFile *of = output_files[i];
+        AVFormatContext *s = of->ctx;
         if (s && s->oformat && !(s->oformat->flags & AVFMT_NOFILE) && s->pb)
             avio_close(s->pb);
         avformat_free_context(s);
-        av_dict_free(&output_files[i]->opts);
+        av_dict_free(&of->opts);
+
         av_freep(&output_files[i]);
     }
     for (i = 0; i < nb_output_streams; i++) {
-        AVBitStreamFilterContext *bsfc = output_streams[i]->bitstream_filters;
+        OutputStream *ost = output_streams[i];
+        AVBitStreamFilterContext *bsfc = ost->bitstream_filters;
         while (bsfc) {
             AVBitStreamFilterContext *next = bsfc->next;
             av_bitstream_filter_close(bsfc);
             bsfc = next;
         }
-        output_streams[i]->bitstream_filters = NULL;
-        av_frame_free(&output_streams[i]->filtered_frame);
+        ost->bitstream_filters = NULL;
+        av_frame_free(&ost->filtered_frame);
+
+        av_parser_close(ost->parser);
 
-        av_parser_close(output_streams[i]->parser);
+        av_freep(&ost->forced_keyframes);
+        av_freep(&ost->avfilter);
+        av_freep(&ost->logfile_prefix);
 
-        av_freep(&output_streams[i]->forced_keyframes);
-        av_freep(&output_streams[i]->avfilter);
-        av_freep(&output_streams[i]->logfile_prefix);
         av_freep(&output_streams[i]);
     }
     for (i = 0; i < nb_input_files; i++) {
@@ -192,11 +198,14 @@ static void avconv_cleanup(int ret)
         av_freep(&input_files[i]);
     }
     for (i = 0; i < nb_input_streams; i++) {
-        av_frame_free(&input_streams[i]->decoded_frame);
-        av_frame_free(&input_streams[i]->filter_frame);
-        av_dict_free(&input_streams[i]->opts);
-        av_freep(&input_streams[i]->filters);
-        av_freep(&input_streams[i]->hwaccel_device);
+        InputStream *ist = input_streams[i];
+
+        av_frame_free(&ist->decoded_frame);
+        av_frame_free(&ist->filter_frame);
+        av_dict_free(&ist->decoder_opts);
+        av_freep(&ist->filters);
+        av_freep(&ist->hwaccel_device);
+
         av_freep(&input_streams[i]);
     }
 
@@ -515,7 +524,9 @@ static void do_video_out(AVFormatContext *s,
         in_picture->pts != AV_NOPTS_VALUE &&
         in_picture->pts < ost->sync_opts) {
         nb_frames_drop++;
-        av_log(NULL, AV_LOG_VERBOSE, "*** drop!\n");
+        av_log(NULL, AV_LOG_WARNING,
+               "*** dropping frame %d from stream %d at ts %"PRId64"\n",
+               ost->frame_number, ost->st->index, in_picture->pts);
         return;
     }
 
@@ -1173,10 +1184,9 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
        the decoder could be delaying output by a packet or more. */
     if (decoded_frame->pts != AV_NOPTS_VALUE)
         ist->next_dts = decoded_frame->pts;
-    else if (pkt->pts != AV_NOPTS_VALUE) {
+    else if (pkt->pts != AV_NOPTS_VALUE)
         decoded_frame->pts = pkt->pts;
-        pkt->pts           = AV_NOPTS_VALUE;
-    }
+    pkt->pts           = AV_NOPTS_VALUE;
 
     resample_changed = ist->resample_sample_fmt     != decoded_frame->format         ||
                        ist->resample_channels       != avctx->channels               ||
@@ -1556,9 +1566,9 @@ static int init_input_stream(int ist_index, char *error, int error_len)
 
         av_opt_set_int(ist->st->codec, "refcounted_frames", 1, 0);
 
-        if (!av_dict_get(ist->opts, "threads", NULL, 0))
-            av_dict_set(&ist->opts, "threads", "auto", 0);
-        if ((ret = avcodec_open2(ist->st->codec, codec, &ist->opts)) < 0) {
+        if (!av_dict_get(ist->decoder_opts, "threads", NULL, 0))
+            av_dict_set(&ist->decoder_opts, "threads", "auto", 0);
+        if ((ret = avcodec_open2(ist->st->codec, codec, &ist->decoder_opts)) < 0) {
             char errbuf[128];
             if (ret == AVERROR_EXPERIMENTAL)
                 abort_codec_experimental(codec, 0);
@@ -1571,7 +1581,7 @@ static int init_input_stream(int ist_index, char *error, int error_len)
                      ist->file_index, ist->st->index, errbuf);
             return ret;
         }
-        assert_avoptions(ist->opts);
+        assert_avoptions(ist->decoder_opts);
     }
 
     ist->last_dts = ist->st->avg_frame_rate.num ? - ist->st->codec->has_b_frames * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0;
@@ -1664,7 +1674,7 @@ static int transcode_init(void)
 
     /* for each output stream, we compute the right encoding parameters */
     for (i = 0; i < nb_output_streams; i++) {
-        AVCodecContext *icodec = NULL;
+        AVCodecContext *dec_ctx = NULL;
         ost = output_streams[i];
         oc  = output_files[ost->file_index]->ctx;
         ist = get_input_stream(ost);
@@ -1675,11 +1685,11 @@ static int transcode_init(void)
         codec  = ost->st->codec;
 
         if (ist) {
-            icodec = ist->st->codec;
+            dec_ctx = ist->st->codec;
 
             ost->st->disposition          = ist->st->disposition;
-            codec->bits_per_raw_sample    = icodec->bits_per_raw_sample;
-            codec->chroma_sample_location = icodec->chroma_sample_location;
+            codec->bits_per_raw_sample    = dec_ctx->bits_per_raw_sample;
+            codec->chroma_sample_location = dec_ctx->chroma_sample_location;
         }
 
         if (ost->stream_copy) {
@@ -1688,36 +1698,36 @@ static int transcode_init(void)
 
             av_assert0(ist && !ost->filter);
 
-            extra_size = (uint64_t)icodec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE;
+            extra_size = (uint64_t)dec_ctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE;
 
             if (extra_size > INT_MAX) {
                 return AVERROR(EINVAL);
             }
 
             /* if stream_copy is selected, no need to decode or encode */
-            codec->codec_id   = icodec->codec_id;
-            codec->codec_type = icodec->codec_type;
+            codec->codec_id   = dec_ctx->codec_id;
+            codec->codec_type = dec_ctx->codec_type;
 
             if (!codec->codec_tag) {
                 if (!oc->oformat->codec_tag ||
-                     av_codec_get_id (oc->oformat->codec_tag, icodec->codec_tag) == codec->codec_id ||
-                     av_codec_get_tag(oc->oformat->codec_tag, icodec->codec_id) <= 0)
-                    codec->codec_tag = icodec->codec_tag;
+                     av_codec_get_id (oc->oformat->codec_tag, dec_ctx->codec_tag) == codec->codec_id ||
+                     av_codec_get_tag(oc->oformat->codec_tag, dec_ctx->codec_id) <= 0)
+                    codec->codec_tag = dec_ctx->codec_tag;
             }
 
-            codec->bit_rate       = icodec->bit_rate;
-            codec->rc_max_rate    = icodec->rc_max_rate;
-            codec->rc_buffer_size = icodec->rc_buffer_size;
-            codec->field_order    = icodec->field_order;
+            codec->bit_rate       = dec_ctx->bit_rate;
+            codec->rc_max_rate    = dec_ctx->rc_max_rate;
+            codec->rc_buffer_size = dec_ctx->rc_buffer_size;
+            codec->field_order    = dec_ctx->field_order;
             codec->extradata      = av_mallocz(extra_size);
             if (!codec->extradata) {
                 return AVERROR(ENOMEM);
             }
-            memcpy(codec->extradata, icodec->extradata, icodec->extradata_size);
-            codec->extradata_size = icodec->extradata_size;
+            memcpy(codec->extradata, dec_ctx->extradata, dec_ctx->extradata_size);
+            codec->extradata_size = dec_ctx->extradata_size;
             if (!copy_tb) {
-                codec->time_base      = icodec->time_base;
-                codec->time_base.num *= icodec->ticks_per_frame;
+                codec->time_base      = dec_ctx->time_base;
+                codec->time_base.num *= dec_ctx->ticks_per_frame;
                 av_reduce(&codec->time_base.num, &codec->time_base.den,
                           codec->time_base.num, codec->time_base.den, INT_MAX);
             } else
@@ -1731,29 +1741,29 @@ static int transcode_init(void)
                     av_log(NULL, AV_LOG_FATAL, "-acodec copy and -vol are incompatible (frames are not decoded)\n");
                     exit_program(1);
                 }
-                codec->channel_layout     = icodec->channel_layout;
-                codec->sample_rate        = icodec->sample_rate;
-                codec->channels           = icodec->channels;
-                codec->frame_size         = icodec->frame_size;
-                codec->audio_service_type = icodec->audio_service_type;
-                codec->block_align        = icodec->block_align;
+                codec->channel_layout     = dec_ctx->channel_layout;
+                codec->sample_rate        = dec_ctx->sample_rate;
+                codec->channels           = dec_ctx->channels;
+                codec->frame_size         = dec_ctx->frame_size;
+                codec->audio_service_type = dec_ctx->audio_service_type;
+                codec->block_align        = dec_ctx->block_align;
                 break;
             case AVMEDIA_TYPE_VIDEO:
-                codec->pix_fmt            = icodec->pix_fmt;
-                codec->width              = icodec->width;
-                codec->height             = icodec->height;
-                codec->has_b_frames       = icodec->has_b_frames;
+                codec->pix_fmt            = dec_ctx->pix_fmt;
+                codec->width              = dec_ctx->width;
+                codec->height             = dec_ctx->height;
+                codec->has_b_frames       = dec_ctx->has_b_frames;
                 if (ost->frame_aspect_ratio)
                     sar = av_d2q(ost->frame_aspect_ratio * codec->height / codec->width, 255);
                 else if (ist->st->sample_aspect_ratio.num)
                     sar = ist->st->sample_aspect_ratio;
                 else
-                    sar = icodec->sample_aspect_ratio;
+                    sar = dec_ctx->sample_aspect_ratio;
                 ost->st->sample_aspect_ratio = codec->sample_aspect_ratio = sar;
                 break;
             case AVMEDIA_TYPE_SUBTITLE:
-                codec->width  = icodec->width;
-                codec->height = icodec->height;
+                codec->width  = dec_ctx->width;
+                codec->height = dec_ctx->height;
                 break;
             case AVMEDIA_TYPE_DATA:
             case AVMEDIA_TYPE_ATTACHMENT:
@@ -1841,10 +1851,10 @@ static int transcode_init(void)
                     ost->filter->filter->inputs[0]->sample_aspect_ratio;
                 codec->pix_fmt = ost->filter->filter->inputs[0]->format;
 
-                if (icodec &&
-                    (codec->width   != icodec->width  ||
-                     codec->height  != icodec->height ||
-                     codec->pix_fmt != icodec->pix_fmt)) {
+                if (dec_ctx &&
+                    (codec->width   != dec_ctx->width  ||
+                     codec->height  != dec_ctx->height ||
+                     codec->pix_fmt != dec_ctx->pix_fmt)) {
                     codec->bits_per_raw_sample = 0;
                 }