On Wed, Jan 6, 2016 at 9:22 PM, Luca Barbato <[email protected]> wrote:
> Now the report is printed even if poll_filters() does not
> return often.
> ---
>  avconv.c  | 106 
> ++++++++++++++++++++++++++++++++++++--------------------------
>  avconv.h  |   4 +++
>  configure |   3 +-
>  3 files changed, 68 insertions(+), 45 deletions(-)
>
> diff --git a/avconv.c b/avconv.c
> index 25bc264..452a8cf 100644
> --- a/avconv.c
> +++ b/avconv.c
> @@ -69,7 +69,11 @@
>  #include <sys/select.h>
>  #endif
>
> +#if HAVE_PTHREADS
>  #include <pthread.h>
> +#elif HAVE_W32THREADS
> +#include "compat/w32pthreads.h"
> +#endif
>
>  #include <time.h>
>
> @@ -695,8 +699,27 @@ static int poll_filters(void)
>      return ret;
>  }
>
> -static void print_final_stats(int64_t total_size)
> +static uint64_t get_total_size(AVFormatContext *oc)
> +{
> +    int64_t total_size;
> +
> +    total_size = avio_size(oc->pb);
> +    if (total_size <= 0) // FIXME improve avio_size() so it works with non 
> seekable output too
> +        total_size = avio_tell(oc->pb);
> +    if (total_size < 0) {
> +        char errbuf[128];
> +        av_strerror(total_size, errbuf, sizeof(errbuf));
> +        av_log(NULL, AV_LOG_VERBOSE, "Bitrate not available, "
> +               "avio_tell() failed: %s\n", errbuf);
> +        total_size = 0;
> +    }
> +
> +    return total_size;
> +}
> +
> +static void print_final_stats(void)
>  {
> +    uint64_t total_size = get_total_size(output_files[0]->ctx);
>      uint64_t video_size = 0, audio_size = 0, extra_size = 0, other_size = 0;
>      uint64_t data_size = 0;
>      float percent = -1.0;
> @@ -798,7 +821,7 @@ static void print_final_stats(int64_t total_size)
>      }
>  }
>
> -static void print_report(int is_last_report, int64_t timer_start)
> +static void print_report(int64_t timer_start)
>  {
>      char buf[1024];
>      OutputStream *ost;
> @@ -809,36 +832,24 @@ static void print_report(int is_last_report, int64_t 
> timer_start)
>      double bitrate, ti1, pts;
>      static int64_t last_time = -1;
>      static int qp_histogram[52];
> +    int64_t cur_time;
>
> -    if (!print_stats && !is_last_report)
> +    if (!print_stats)
>          return;
>
> -    if (!is_last_report) {
> -        int64_t cur_time;
> -        /* display the report every 0.5 seconds */
> -        cur_time = av_gettime_relative();
> -        if (last_time == -1) {
> -            last_time = cur_time;
> -            return;
> -        }
> -        if ((cur_time - last_time) < 500000)
> -            return;
> +    /* display the report every 0.5 seconds */
> +    cur_time = av_gettime_relative();
> +    if (last_time == -1) {
>          last_time = cur_time;
> +        return;
>      }
> -
> +    if ((cur_time - last_time) < 500000)
> +        return;
> +    last_time = cur_time;
>
>      oc = output_files[0]->ctx;
>
> -    total_size = avio_size(oc->pb);
> -    if (total_size <= 0) // FIXME improve avio_size() so it works with non 
> seekable output too
> -        total_size = avio_tell(oc->pb);
> -    if (total_size < 0) {
> -        char errbuf[128];
> -        av_strerror(total_size, errbuf, sizeof(errbuf));
> -        av_log(NULL, AV_LOG_VERBOSE, "Bitrate not available, "
> -               "avio_tell() failed: %s\n", errbuf);
> -        total_size = 0;
> -    }
> +    total_size = get_total_size(oc);
>
>      buf[0] = '\0';
>      ti1 = 1e10;
> @@ -859,8 +870,6 @@ static void print_report(int is_last_report, int64_t 
> timer_start)
>              frame_number = ost->frame_number;
>              snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), 
> "frame=%5d fps=%3d q=%3.1f ",
>                       frame_number, (t > 1) ? (int)(frame_number / t + 0.5) : 
> 0, q);
> -            if (is_last_report)
> -                snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "L");
>              if (qp_hist) {
>                  int j;
>                  int qp = lrintf(q);
> @@ -879,13 +888,9 @@ FF_DISABLE_DEPRECATION_WARNINGS
>                  char type[3] = { 'Y','U','V' };
>                  snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), 
> "PSNR=");
>                  for (j = 0; j < 3; j++) {
> -                    if (is_last_report) {
> -                        error = enc->error[j];
> -                        scale = enc->width * enc->height * 255.0 * 255.0 * 
> frame_number;
> -                    } else {
> -                        error = enc->coded_frame->error[j];
> -                        scale = enc->width * enc->height * 255.0 * 255.0;
> -                    }
> +                    error = enc->coded_frame->error[j];
> +                    scale = enc->width * enc->height * 255.0 * 255.0;
> +
>                      if (j)
>                          scale /= 4;
>                      error_sum += error;
> @@ -919,10 +924,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
>      av_log(NULL, AV_LOG_INFO, "%s    \r", buf);
>
>      fflush(stderr);
> -
> -    if (is_last_report)
> -        print_final_stats(total_size);
> -
>  }
>
>  static void flush_encoders(void)
> @@ -2239,6 +2240,26 @@ static int get_input_packet_mt(InputFile *f, AVPacket 
> *pkt)
>      return ret;
>  }
>
> +static void *ui_thread(void *unused)
> +{
> +    int64_t start_time = av_gettime_relative();
> +
> +    while (!transcoding_finished) {
> +        print_report(start_time);
> +        av_usleep(500 * 1000);
> +    }
> +
> +    return NULL;
> +}
> +
> +static int init_ui_thread(pthread_t *ui)
> +{
> +    int ret = pthread_create(ui, NULL, ui_thread, NULL);
> +
> +    return AVERROR(ret);
> +}
> +#endif
> +
>  static int get_input_packet(InputFile *f, AVPacket *pkt)
>  {
>      if (f->rate_emu) {
> @@ -2518,7 +2539,7 @@ static int transcode(void)
>      AVFormatContext *os;
>      OutputStream *ost;
>      InputStream *ist;
> -    int64_t timer_start;
> +    pthread_t ui_thread;
>
>      ret = transcode_init();
>      if (ret < 0)
> @@ -2527,10 +2548,10 @@ static int transcode(void)
>      av_log(NULL, AV_LOG_INFO, "Press ctrl-c to stop encoding\n");
>      term_init();
>
> -    timer_start = av_gettime_relative();
> -
>      if ((ret = init_input_threads()) < 0)
>          goto fail;
> +    if ((ret = init_ui_thread(&ui_thread)) < 0)
> +        goto fail;
>
>      while (!received_sigterm) {
>          /* check if there's any stream where output is still needed */
> @@ -2554,9 +2575,6 @@ static int transcode(void)
>              av_log(NULL, AV_LOG_ERROR, "Error while filtering: %s\n", 
> errbuf);
>              break;
>          }
> -
> -        /* dump report by using the output first video and audio streams */
> -        print_report(0, timer_start);
>      }
>
>      free_input_threads();
> @@ -2580,7 +2598,7 @@ static int transcode(void)
>      }
>
>      /* dump report by using the first video and audio streams */
> -    print_report(1, timer_start);
> +    print_final_stats();
>
>      /* close each encoder */
>      for (i = 0; i < nb_output_streams; i++) {
> diff --git a/avconv.h b/avconv.h
> index 779960e..cc6633c 100644
> --- a/avconv.h
> +++ b/avconv.h
> @@ -24,7 +24,11 @@
>  #include <stdint.h>
>  #include <stdio.h>
>
> +#if HAVE_PTHREADS
>  #include <pthread.h>
> +#elif HAVE_W32THREADS
> +#include "compat/w32pthreads.h"
> +#endif
>
>  #include "cmdutils.h"
>
> diff --git a/configure b/configure
> index 299da09..78fa595 100755
> --- a/configure
> +++ b/configure
> @@ -2364,7 +2364,8 @@ avresample_deps="avutil"
>  swscale_deps="avutil"
>
>  # programs
> -avconv_deps="avcodec avfilter avformat avresample swscale pthreads"
> +avconv_deps_any="pthreads w32threads"
> +avconv_deps="avcodec avfilter avformat avresample swscale"
>  avconv_select="aformat_filter anull_filter asyncts_filter atrim_filter 
> format_filter
>                 fps_filter null_filter resample_filter scale_filter
>                 setpts_filter trim_filter"
> --
> 2.6.1

is this still needed?
-- 
Vittorio
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to