]> git.sesse.net Git - ffmpeg/blobdiff - avconv.c
vaapi_h264: Convert to use the new VAAPI hwaccel code
[ffmpeg] / avconv.c
index 4eae0151c6f08cf063e4ec11f92a901c34c030ec..59eb3009b1458d2c4d6740ff5e6a9eee7a1c001a 100644 (file)
--- a/avconv.c
+++ b/avconv.c
@@ -203,13 +203,15 @@ static void avconv_cleanup(int ret)
 
         avcodec_free_context(&ost->enc_ctx);
 
-        while (av_fifo_size(ost->muxing_queue)) {
-            AVPacket pkt;
-            av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL);
-            av_packet_unref(&pkt);
+        if (ost->muxing_queue) {
+            while (av_fifo_size(ost->muxing_queue)) {
+                AVPacket pkt;
+                av_log(NULL, AV_LOG_INFO, "after av_fifo_size()\n");
+                av_fifo_generic_read(ost->muxing_queue, &pkt, sizeof(pkt), NULL);
+                av_packet_unref(&pkt);
+            }
+            av_fifo_free(ost->muxing_queue);
         }
-        av_fifo_free(ost->muxing_queue);
-
         av_freep(&output_streams[i]);
     }
     for (i = 0; i < nb_input_files; i++) {
@@ -764,6 +766,15 @@ static int poll_filters(void)
         for (i = 0; i < nb_output_streams; i++) {
             int64_t pts = output_streams[i]->sync_opts;
 
+            if (output_streams[i]->filter && !output_streams[i]->filter->graph->graph &&
+                !output_streams[i]->filter->graph->nb_inputs) {
+                ret = configure_filtergraph(output_streams[i]->filter->graph);
+                if (ret < 0) {
+                    av_log(NULL, AV_LOG_ERROR, "Error reinitializing filters!\n");
+                    return ret;
+                }
+            }
+
             if (!output_streams[i]->filter || output_streams[i]->finished ||
                 !output_streams[i]->filter->graph->graph)
                 continue;
@@ -1231,17 +1242,6 @@ static int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame)
             av_log(NULL, AV_LOG_ERROR, "Error reinitializing filters!\n");
             return ret;
         }
-
-        for (i = 0; i < fg->nb_inputs; i++) {
-            while (av_fifo_size(fg->inputs[i]->frame_queue)) {
-                AVFrame *tmp;
-                av_fifo_generic_read(fg->inputs[i]->frame_queue, &tmp, sizeof(tmp), NULL);
-                ret = av_buffersrc_add_frame(fg->inputs[i]->filter, tmp);
-                av_frame_free(&tmp);
-                if (ret < 0)
-                    return ret;
-            }
-        }
     }
 
     ret = av_buffersrc_add_frame(ifilter->filter, frame);
@@ -1253,6 +1253,34 @@ static int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame)
     return 0;
 }
 
+static int ifilter_send_eof(InputFilter *ifilter)
+{
+    int i, j, ret;
+
+    ifilter->eof = 1;
+
+    if (ifilter->filter) {
+        ret = av_buffersrc_add_frame(ifilter->filter, NULL);
+        if (ret < 0)
+            return ret;
+    } else {
+        // the filtergraph was never configured
+        FilterGraph *fg = ifilter->graph;
+        for (i = 0; i < fg->nb_inputs; i++)
+            if (!fg->inputs[i]->eof)
+                break;
+        if (i == fg->nb_inputs) {
+            // All the input streams have finished without the filtergraph
+            // ever being configured.
+            // Mark the output streams as finished.
+            for (j = 0; j < fg->nb_outputs; j++)
+                finish_output_stream(fg->outputs[j]->ost);
+        }
+    }
+
+    return 0;
+}
+
 // This does not quite work like avcodec_decode_audio4/avcodec_decode_video2.
 // There is the following difference: if you got a frame, you must call
 // it again with pkt=NULL. pkt==NULL is treated differently from pkt.size==0
@@ -1375,6 +1403,8 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output)
 
     decoded_frame->pts = guess_correct_pts(&ist->pts_ctx, decoded_frame->pts,
                                            decoded_frame->pkt_dts);
+    if (ist->framerate.num)
+        decoded_frame->pts = ist->cfr_next_pts++;
 
     if (ist->st->sample_aspect_ratio.num)
         decoded_frame->sample_aspect_ratio = ist->st->sample_aspect_ratio;
@@ -1426,18 +1456,11 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)
 
 static int send_filter_eof(InputStream *ist)
 {
-    int i, j, ret;
+    int i, ret;
     for (i = 0; i < ist->nb_filters; i++) {
-        if (ist->filters[i]->filter) {
-            ret = av_buffersrc_add_frame(ist->filters[i]->filter, NULL);
-            if (ret < 0)
-                return ret;
-        } else {
-            // the filtergraph was never configured
-            FilterGraph *fg = ist->filters[i]->graph;
-            for (j = 0; j < fg->nb_outputs; j++)
-                finish_output_stream(fg->outputs[j]->ost);
-        }
+        ret = ifilter_send_eof(ist->filters[i]);
+        if (ret < 0)
+            return ret;
     }
     return 0;
 }
@@ -1802,39 +1825,23 @@ static int init_output_stream_streamcopy(OutputStream *ost)
     AVCodecParameters *par_dst = ost->st->codecpar;
     AVCodecParameters *par_src = ist->st->codecpar;
     AVRational sar;
-    int i;
-    uint64_t extra_size;
-
-    extra_size = (uint64_t)par_src->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE;
-    if (extra_size > INT_MAX) {
-        return AVERROR(EINVAL);
-    }
-
-    ost->st->disposition = ist->st->disposition;
-
-    /* if stream_copy is selected, no need to decode or encode */
-    par_dst->codec_id   = par_src->codec_id;
-    par_dst->codec_type = par_src->codec_type;
+    uint32_t codec_tag = par_dst->codec_tag;
+    int i, ret;
 
-    if (!par_dst->codec_tag) {
+    if (!codec_tag) {
         if (!of->ctx->oformat->codec_tag ||
-             av_codec_get_id (of->ctx->oformat->codec_tag, par_src->codec_tag) == par_dst->codec_id ||
+             av_codec_get_id (of->ctx->oformat->codec_tag, par_src->codec_tag) == par_src->codec_id ||
              av_codec_get_tag(of->ctx->oformat->codec_tag, par_src->codec_id) <= 0)
-            par_dst->codec_tag = par_src->codec_tag;
+            codec_tag = par_src->codec_tag;
     }
 
-    par_dst->bit_rate        = par_src->bit_rate;
-    par_dst->field_order     = par_src->field_order;
-    par_dst->chroma_location = par_src->chroma_location;
+    ret = avcodec_parameters_copy(par_dst, par_src);
+    if (ret < 0)
+        return ret;
+
+    par_dst->codec_tag = codec_tag;
 
-    if (par_src->extradata) {
-        par_dst->extradata       = av_mallocz(extra_size);
-        if (!par_dst->extradata) {
-            return AVERROR(ENOMEM);
-        }
-        memcpy(par_dst->extradata, par_src->extradata, par_src->extradata_size);
-        par_dst->extradata_size = par_src->extradata_size;
-    }
+    ost->st->disposition = ist->st->disposition;
 
     ost->st->time_base = ist->st->time_base;
 
@@ -1863,21 +1870,7 @@ static int init_output_stream_streamcopy(OutputStream *ost)
     if (!ost->parser_avctx)
         return AVERROR(ENOMEM);
 
-    switch (par_dst->codec_type) {
-    case AVMEDIA_TYPE_AUDIO:
-        if (audio_volume != 256) {
-            av_log(NULL, AV_LOG_FATAL, "-acodec copy and -vol are incompatible (frames are not decoded)\n");
-            exit_program(1);
-        }
-        par_dst->channel_layout     = par_src->channel_layout;
-        par_dst->sample_rate        = par_src->sample_rate;
-        par_dst->channels           = par_src->channels;
-        par_dst->block_align        = par_src->block_align;
-        break;
-    case AVMEDIA_TYPE_VIDEO:
-        par_dst->format             = par_src->format;
-        par_dst->width              = par_src->width;
-        par_dst->height             = par_src->height;
+    if (par_dst->codec_type == AVMEDIA_TYPE_VIDEO) {
         if (ost->frame_aspect_ratio)
             sar = av_d2q(ost->frame_aspect_ratio * par_dst->height / par_dst->width, 255);
         else if (ist->st->sample_aspect_ratio.num)
@@ -1885,16 +1878,6 @@ static int init_output_stream_streamcopy(OutputStream *ost)
         else
             sar = par_src->sample_aspect_ratio;
         ost->st->sample_aspect_ratio = par_dst->sample_aspect_ratio = sar;
-        break;
-    case AVMEDIA_TYPE_SUBTITLE:
-        par_dst->width  = par_src->width;
-        par_dst->height = par_src->height;
-        break;
-    case AVMEDIA_TYPE_DATA:
-    case AVMEDIA_TYPE_ATTACHMENT:
-        break;
-    default:
-        abort();
     }
 
     return 0;