Merge commit '4754345027eb85cfa51aeb88beec68d7b036c11e'
authorMichael Niedermayer <michaelni@gmx.at>
Mon, 24 Mar 2014 15:40:35 +0000 (16:40 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Mon, 24 Mar 2014 15:40:35 +0000 (16:40 +0100)
* commit '4754345027eb85cfa51aeb88beec68d7b036c11e':
  avconv: print verbose per-stream transcoding statistics

Conflicts:
ffmpeg.c

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

diff --cc ffmpeg.c
+++ b/ffmpeg.c
@@@ -646,19 -368,9 +646,20 @@@ static void write_frame(AVFormatContex
      ost->last_mux_dts = pkt->dts;
  
      ost->data_size += pkt->size;
+     ost->packets_written++;
  
      pkt->stream_index = ost->index;
 +
 +    if (debug_ts) {
 +        av_log(NULL, AV_LOG_INFO, "muxer <- type:%s "
 +                "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s size:%d\n",
 +                av_get_media_type_string(ost->st->codec->codec_type),
 +                av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ost->st->time_base),
 +                av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ost->st->time_base),
 +                pkt->size
 +              );
 +    }
 +
      ret = av_interleaved_write_frame(s, pkt);
      if (ret < 0) {
          print_error("av_interleaved_write_frame()", ret);
@@@ -708,20 -405,14 +709,23 @@@ static void do_audio_out(AVFormatContex
      if (frame->pts == AV_NOPTS_VALUE || audio_sync_method < 0)
          frame->pts = ost->sync_opts;
      ost->sync_opts = frame->pts + frame->nb_samples;
 -
+     ost->samples_encoded += frame->nb_samples;
+     ost->frames_encoded++;
  
 +    av_assert0(pkt.size || !pkt.data);
 +    update_benchmark(NULL);
 +    if (debug_ts) {
 +        av_log(NULL, AV_LOG_INFO, "encoder <- type:audio "
 +               "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n",
 +               av_ts2str(frame->pts), av_ts2timestr(frame->pts, &enc->time_base),
 +               enc->time_base.num, enc->time_base.den);
 +    }
++
      if (avcodec_encode_audio2(enc, &pkt, frame, &got_packet) < 0) {
 -        av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
 +        av_log(NULL, AV_LOG_FATAL, "Audio encoding failed (avcodec_encode_audio2)\n");
          exit_program(1);
      }
 +    update_benchmark("encode_audio %d.%d", ost->file_index, ost->index);
  
      if (got_packet) {
          if (pkt.pts != AV_NOPTS_VALUE)
@@@ -790,8 -469,9 +794,11 @@@ static void do_subtitle_out(AVFormatCon
          sub->pts               += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q);
          sub->end_display_time  -= sub->start_display_time;
          sub->start_display_time = 0;
 +        if (i == 1)
 +            sub->num_rects = 0;
+         ost->frames_encoded++;
          subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out,
                                                      subtitle_out_max_size, sub);
          if (subtitle_out_size < 0) {
@@@ -952,51 -557,15 +959,54 @@@ static void do_video_out(AVFormatContex
          in_picture->quality = ost->st->codec->global_quality;
          if (!enc->me_threshold)
              in_picture->pict_type = 0;
 +
 +        pts_time = in_picture->pts != AV_NOPTS_VALUE ?
 +            in_picture->pts * av_q2d(enc->time_base) : NAN;
          if (ost->forced_kf_index < ost->forced_kf_count &&
              in_picture->pts >= ost->forced_kf_pts[ost->forced_kf_index]) {
 -            in_picture->pict_type = AV_PICTURE_TYPE_I;
              ost->forced_kf_index++;
 +            forced_keyframe = 1;
 +        } else if (ost->forced_keyframes_pexpr) {
 +            double res;
 +            ost->forced_keyframes_expr_const_values[FKF_T] = pts_time;
 +            res = av_expr_eval(ost->forced_keyframes_pexpr,
 +                               ost->forced_keyframes_expr_const_values, NULL);
 +            av_dlog(NULL, "force_key_frame: n:%f n_forced:%f prev_forced_n:%f t:%f prev_forced_t:%f -> res:%f\n",
 +                    ost->forced_keyframes_expr_const_values[FKF_N],
 +                    ost->forced_keyframes_expr_const_values[FKF_N_FORCED],
 +                    ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N],
 +                    ost->forced_keyframes_expr_const_values[FKF_T],
 +                    ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T],
 +                    res);
 +            if (res) {
 +                forced_keyframe = 1;
 +                ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] =
 +                    ost->forced_keyframes_expr_const_values[FKF_N];
 +                ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T] =
 +                    ost->forced_keyframes_expr_const_values[FKF_T];
 +                ost->forced_keyframes_expr_const_values[FKF_N_FORCED] += 1;
 +            }
 +
 +            ost->forced_keyframes_expr_const_values[FKF_N] += 1;
 +        }
++
 +        if (forced_keyframe) {
 +            in_picture->pict_type = AV_PICTURE_TYPE_I;
 +            av_log(NULL, AV_LOG_DEBUG, "Forced keyframe at time %f\n", pts_time);
 +        }
 +
 +        update_benchmark(NULL);
 +        if (debug_ts) {
 +            av_log(NULL, AV_LOG_INFO, "encoder <- type:video "
 +                   "frame_pts:%s frame_pts_time:%s time_base:%d/%d\n",
 +                   av_ts2str(in_picture->pts), av_ts2timestr(in_picture->pts, &enc->time_base),
 +                   enc->time_base.num, enc->time_base.den);
          }
  
+         ost->frames_encoded++;
          ret = avcodec_encode_video2(enc, &pkt, in_picture, &got_packet);
 +        update_benchmark("encode_video %d.%d", ost->file_index, ost->index);
          if (ret < 0) {
              av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
              exit_program(1);
@@@ -1181,10 -749,9 +1191,10 @@@ static int reap_filters(void
  static void print_final_stats(int64_t total_size)
  {
      uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
 +    uint64_t subtitle_size = 0;
      uint64_t data_size = 0;
      float percent = -1.0;
-     int i;
+     int i, j;
  
      for (i = 0; i < nb_output_streams; i++) {
          OutputStream *ost = output_streams[i];
      else
          av_log(NULL, AV_LOG_INFO, "unknown");
      av_log(NULL, AV_LOG_INFO, "\n");
+     /* print verbose per-stream stats */
+     for (i = 0; i < nb_input_files; i++) {
+         InputFile *f = input_files[i];
+         uint64_t total_packets = 0, total_size = 0;
+         av_log(NULL, AV_LOG_VERBOSE, "Input file #%d (%s):\n",
+                i, f->ctx->filename);
+         for (j = 0; j < f->nb_streams; j++) {
+             InputStream *ist = input_streams[f->ist_index + j];
+             enum AVMediaType type = ist->st->codec->codec_type;
+             total_size    += ist->data_size;
+             total_packets += ist->nb_packets;
+             av_log(NULL, AV_LOG_VERBOSE, "  Input stream #%d:%d (%s): ",
+                    i, j, media_type_string(type));
+             av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets read (%"PRIu64" bytes); ",
+                    ist->nb_packets, ist->data_size);
+             if (ist->decoding_needed) {
+                 av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames decoded",
+                        ist->frames_decoded);
+                 if (type == AVMEDIA_TYPE_AUDIO)
+                     av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ist->samples_decoded);
+                 av_log(NULL, AV_LOG_VERBOSE, "; ");
+             }
+             av_log(NULL, AV_LOG_VERBOSE, "\n");
+         }
+         av_log(NULL, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
+                total_packets, total_size);
+     }
+     for (i = 0; i < nb_output_files; i++) {
+         OutputFile *of = output_files[i];
+         uint64_t total_packets = 0, total_size = 0;
+         av_log(NULL, AV_LOG_VERBOSE, "Output file #%d (%s):\n",
+                i, of->ctx->filename);
+         for (j = 0; j < of->ctx->nb_streams; j++) {
+             OutputStream *ost = output_streams[of->ost_index + j];
+             enum AVMediaType type = ost->st->codec->codec_type;
+             total_size    += ost->data_size;
+             total_packets += ost->packets_written;
+             av_log(NULL, AV_LOG_VERBOSE, "  Output stream #%d:%d (%s): ",
+                    i, j, media_type_string(type));
+             if (ost->encoding_needed) {
+                 av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" frames encoded",
+                        ost->frames_encoded);
+                 if (type == AVMEDIA_TYPE_AUDIO)
+                     av_log(NULL, AV_LOG_VERBOSE, " (%"PRIu64" samples)", ost->samples_encoded);
+                 av_log(NULL, AV_LOG_VERBOSE, "; ");
+             }
+             av_log(NULL, AV_LOG_VERBOSE, "%"PRIu64" packets muxed (%"PRIu64" bytes); ",
+                    ost->packets_written, ost->data_size);
+             av_log(NULL, AV_LOG_VERBOSE, "\n");
+         }
+         av_log(NULL, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) muxed\n",
+                total_packets, total_size);
+     }
 +    if(video_size + data_size + audio_size + subtitle_size + extra_size == 0){
 +        av_log(NULL, AV_LOG_WARNING, "Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)\n");
 +    }
  }
  
 -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;
@@@ -1641,14 -1166,17 +1720,17 @@@ static int decode_audio(InputStream *is
          return ret;
      }
  
 -    /* if the decoder provides a pts, use it instead of the last packet pts.
 -       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) {
 -        decoded_frame->pts = pkt->pts;
 -        pkt->pts           = AV_NOPTS_VALUE;
 -    }
+     ist->samples_decoded += decoded_frame->nb_samples;
+     ist->frames_decoded++;
 +#if 1
 +    /* increment next_dts to use for the case where the input stream does not
 +       have timestamps or there are multiple frames in the packet */
 +    ist->next_pts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
 +                     avctx->sample_rate;
 +    ist->next_dts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
 +                     avctx->sample_rate;
 +#endif
  
      resample_changed = ist->resample_sample_fmt     != decoded_frame->format         ||
                         ist->resample_channels       != avctx->channels               ||
@@@ -1778,9 -1263,8 +1860,11 @@@ static int decode_video(InputStream *is
          return ret;
      }
  
 +    if(ist->top_field_first>=0)
 +        decoded_frame->top_field_first = ist->top_field_first;
 +
+     ist->frames_decoded++;
      if (ist->hwaccel_retrieve_data && decoded_frame->format == ist->hwaccel_pix_fmt) {
          err = ist->hwaccel_retrieve_data(ist->st->codec, decoded_frame);
          if (err < 0)
@@@ -1897,11 -1335,8 +1981,13 @@@ static int transcode_subtitles(InputStr
      if (!*got_output)
          return ret;
  
 +    sub2video_update(ist, &subtitle);
 +
 +    if (!subtitle.num_rects)
 +        goto out;
 +
+     ist->frames_decoded++;
      for (i = 0; i < nb_output_streams; i++) {
          OutputStream *ost = output_streams[i];
  
@@@ -3171,13 -2314,14 +3257,16 @@@ static int process_input(int file_index
      }
      /* the following test is needed in case new streams appear
         dynamically in stream : we ignore them */
 -    if (pkt.stream_index >= ifile->nb_streams)
 +    if (pkt.stream_index >= ifile->nb_streams) {
 +        report_new_stream(file_index, &pkt);
          goto discard_packet;
 +    }
  
      ist = input_streams[ifile->ist_index + pkt.stream_index];
+     ist->data_size += pkt.size;
      ist->nb_packets++;
      if (ist->discard)
          goto discard_packet;
  
diff --cc ffmpeg.h
+++ b/ffmpeg.h
@@@ -259,12 -232,7 +259,9 @@@ typedef struct InputStream 
      int showed_multi_packet_warning;
      AVDictionary *opts;
      AVRational framerate;               /* framerate forced with -r */
 +    int top_field_first;
 +    int guess_layout_max;
  
-     /* number of packets successfully read for this stream */
-     uint64_t nb_packets;
      int resample_height;
      int resample_width;
      int resample_pix_fmt;