Merge commit 'e0fcad77618a0455ca9c2451ea0aa538597a08c0' into release/1.1
authorMichael Niedermayer <michaelni@gmx.at>
Thu, 19 Jun 2014 23:00:59 +0000 (01:00 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 19 Jun 2014 23:05:46 +0000 (01:05 +0200)
* commit 'e0fcad77618a0455ca9c2451ea0aa538597a08c0':
  avconv: make -shortest work with streamcopy

Conflicts:
ffmpeg.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
ffmpeg.c

diff --cc ffmpeg.c
+++ b/ffmpeg.c
@@@ -996,94 -657,131 +996,107 @@@ static void do_video_stats(OutputStrea
      }
  }
  
 -/*
 - * Read one frame for lavfi output for ost and encode it.
 - */
 -static int poll_filter(OutputStream *ost)
 -{
 -    OutputFile    *of = output_files[ost->file_index];
 -    AVFilterBufferRef *picref;
 -    AVFrame *filtered_frame = NULL;
 -    int frame_size, ret;
 -
 -    if (!ost->filtered_frame && !(ost->filtered_frame = avcodec_alloc_frame())) {
 -        return AVERROR(ENOMEM);
 -    } else
 -        avcodec_get_frame_defaults(ost->filtered_frame);
 -    filtered_frame = ost->filtered_frame;
 -
 -    if (ost->enc->type == AVMEDIA_TYPE_AUDIO &&
 -        !(ost->enc->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE))
 -        ret = av_buffersink_read_samples(ost->filter->filter, &picref,
 -                                         ost->st->codec->frame_size);
 -    else
 -        ret = av_buffersink_read(ost->filter->filter, &picref);
 -
 -    if (ret < 0)
 -        return ret;
 -
 -    avfilter_copy_buf_props(filtered_frame, picref);
 -    if (picref->pts != AV_NOPTS_VALUE) {
 -        filtered_frame->pts = av_rescale_q(picref->pts,
 -                                           ost->filter->filter->inputs[0]->time_base,
 -                                           ost->st->codec->time_base) -
 -                              av_rescale_q(of->start_time,
 -                                           AV_TIME_BASE_Q,
 -                                           ost->st->codec->time_base);
 -
 -        if (of->start_time && filtered_frame->pts < 0) {
 -            avfilter_unref_buffer(picref);
 -            return 0;
 -        }
 -    }
 -
 -    switch (ost->filter->filter->inputs[0]->type) {
 -    case AVMEDIA_TYPE_VIDEO:
 -        if (!ost->frame_aspect_ratio)
 -            ost->st->codec->sample_aspect_ratio = picref->video->pixel_aspect;
 -
 -        do_video_out(of->ctx, ost, filtered_frame, &frame_size);
 -        if (vstats_filename && frame_size)
 -            do_video_stats(ost, frame_size);
 -        break;
 -    case AVMEDIA_TYPE_AUDIO:
 -        do_audio_out(of->ctx, ost, filtered_frame);
 -        break;
 -    default:
 -        // TODO support subtitle filters
 -        av_assert0(0);
 -    }
 -
 -    avfilter_unref_buffer(picref);
 -
 -    return 0;
 -}
 -
+ static void finish_output_stream(OutputStream *ost)
+ {
+     OutputFile *of = output_files[ost->file_index];
+     int i;
+     ost->finished = 1;
+     if (of->shortest) {
+         for (i = 0; i < of->ctx->nb_streams; i++)
+             output_streams[of->ost_index + i]->finished = 1;
+     }
+ }
 -/*
 - * Read as many frames from possible from lavfi and encode them.
 +/**
 + * Get and encode new output from any of the filtergraphs, without causing
 + * activity.
   *
 - * Always read from the active stream with the lowest timestamp. If no frames
 - * are available for it then return EAGAIN and wait for more input. This way we
 - * can use lavfi sources that generate unlimited amount of frames without memory
 - * usage exploding.
 + * @return  0 for success, <0 for severe errors
   */
 -static int poll_filters(void)
 +static int reap_filters(void)
  {
 -    int i, ret = 0;
 -
 -    while (ret >= 0 && !received_sigterm) {
 -        OutputStream *ost = NULL;
 -        int64_t min_pts = INT64_MAX;
 +    AVFilterBufferRef *picref;
 +    AVFrame *filtered_frame = NULL;
 +    int i;
 +    int64_t frame_pts;
  
 -        /* choose output stream with the lowest timestamp */
 -        for (i = 0; i < nb_output_streams; i++) {
 -            int64_t pts = output_streams[i]->sync_opts;
 +    /* Reap all buffers present in the buffer sinks */
 +    for (i = 0; i < nb_output_streams; i++) {
 +        OutputStream *ost = output_streams[i];
 +        OutputFile    *of = output_files[ost->file_index];
 +        int ret = 0;
  
 -            if (!output_streams[i]->filter || output_streams[i]->finished)
 -                continue;
 +        if (!ost->filter)
 +            continue;
  
 -            pts = av_rescale_q(pts, output_streams[i]->st->codec->time_base,
 -                               AV_TIME_BASE_Q);
 -            if (pts < min_pts) {
 -                min_pts = pts;
 -                ost = output_streams[i];
 +        if (!ost->filtered_frame && !(ost->filtered_frame = avcodec_alloc_frame())) {
 +            return AVERROR(ENOMEM);
 +        } else
 +            avcodec_get_frame_defaults(ost->filtered_frame);
 +        filtered_frame = ost->filtered_frame;
 +
 +        while (1) {
 +            ret = av_buffersink_get_buffer_ref(ost->filter->filter, &picref,
 +                                               AV_BUFFERSINK_FLAG_NO_REQUEST);
 +            if (ret < 0) {
 +                if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
 +                    char buf[256];
 +                    av_strerror(ret, buf, sizeof(buf));
 +                    av_log(NULL, AV_LOG_WARNING,
 +                           "Error in av_buffersink_get_buffer_ref(): %s\n", buf);
 +                }
 +                break;
              }
 -        }
 +            frame_pts = AV_NOPTS_VALUE;
 +            if (picref->pts != AV_NOPTS_VALUE) {
 +                filtered_frame->pts = frame_pts = av_rescale_q(picref->pts,
 +                                                ost->filter->filter->inputs[0]->time_base,
 +                                                ost->st->codec->time_base) -
 +                                    av_rescale_q(of->start_time,
 +                                                AV_TIME_BASE_Q,
 +                                                ost->st->codec->time_base);
 +
 +                if (of->start_time && filtered_frame->pts < 0) {
 +                    avfilter_unref_buffer(picref);
 +                    continue;
 +                }
 +            }
 +            //if (ost->source_index >= 0)
 +            //    *filtered_frame= *input_streams[ost->source_index]->decoded_frame; //for me_threshold
  
 -        if (!ost)
 -            break;
  
 -        ret = poll_filter(ost);
 +            switch (ost->filter->filter->inputs[0]->type) {
 +            case AVMEDIA_TYPE_VIDEO:
 +                avfilter_copy_buf_props(filtered_frame, picref);
 +                filtered_frame->pts = frame_pts;
 +                if (!ost->frame_aspect_ratio)
 +                    ost->st->codec->sample_aspect_ratio = picref->video->sample_aspect_ratio;
  
 -        if (ret == AVERROR_EOF) {
 -            finish_output_stream(ost);
 -            ret = 0;
 -        } else if (ret == AVERROR(EAGAIN))
 -            return 0;
 +                do_video_out(of->ctx, ost, filtered_frame);
 +                break;
 +            case AVMEDIA_TYPE_AUDIO:
 +                avfilter_copy_buf_props(filtered_frame, picref);
 +                filtered_frame->pts = frame_pts;
 +                do_audio_out(of->ctx, ost, filtered_frame);
 +                break;
 +            default:
 +                // TODO support subtitle filters
 +                av_assert0(0);
 +            }
 +
 +            avfilter_unref_buffer(picref);
 +        }
      }
  
 -    return ret;
 +    return 0;
  }
  
 -static void print_report(int is_last_report, int64_t timer_start)
 +static void print_report(int is_last_report, int64_t timer_start, int64_t cur_time)
  {
      char buf[1024];
 +    AVBPrint buf_script;
      OutputStream *ost;
      AVFormatContext *oc;
      int64_t total_size;