Quoting Luca Barbato (2016-01-04 23:32:25)
> Now the report is printed even if poll_filters() does not
> return often.
> ---
I think we can now safely make avconv depend on threading, it should be
available everywhere we care about.
>
> avconv.c | 108
> +++++++++++++++++++++++++++++++++++++--------------------------
> 1 file changed, 64 insertions(+), 44 deletions(-)
>
> diff --git a/avconv.c b/avconv.c
> index 6b37d6e..676e81d 100644
> --- a/avconv.c
> +++ b/avconv.c
> @@ -699,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;
> @@ -802,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;
> @@ -813,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;
> @@ -863,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);
> @@ -883,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;
> @@ -923,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)
> @@ -2243,6 +2240,25 @@ 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);
This looks like about three million races.
--
Anton Khirnov
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel