diff mbox

[FFmpeg-devel,2/2] ffmpeg: handling copyts use case in progress report computation

Message ID 1524719040-30542-2-git-send-email-vdixit@akamai.com
State New
Headers show

Commit Message

Dixit, Vishwanath April 26, 2018, 5:04 a.m. UTC
From: Vishwanath Dixit <vdixit@akamai.com>

Progress report computation functionality was assuming the first
PTS value to be zero, but, when 'copyts' is enalbed, the first PTS
can be any big number. This was eventually causing display of
weird statistics during execution of an ffmpeg command. To overcome
this issue, the actual first PTS value has to be considered.
---
 fftools/ffmpeg.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer April 27, 2018, 5:54 p.m. UTC | #1
On Thu, Apr 26, 2018 at 10:34:00AM +0530, vdixit@akamai.com wrote:
> From: Vishwanath Dixit <vdixit@akamai.com>
> 
> Progress report computation functionality was assuming the first
> PTS value to be zero, but, when 'copyts' is enalbed, the first PTS
> can be any big number. This was eventually causing display of
> weird statistics during execution of an ffmpeg command. To overcome
> this issue, the actual first PTS value has to be considered.
> ---
>  fftools/ffmpeg.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index d9bb78a..9b71525 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -1646,7 +1646,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
>      int frame_number, vid, i;
>      double bitrate;
>      double speed;
> -    int64_t pts = INT64_MIN + 1;
> +    int64_t pts = INT64_MIN + 1, first_pts = INT64_MAX;
>      static int64_t last_time = -1;
>      static int qp_histogram[52];
>      int hours, mins, secs, us;
> @@ -1744,6 +1744,11 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
>              }
>              vid = 1;
>          }
> +
> +        /* Find the first written PTS among all the output streams */
> +        first_pts = FFMIN(first_pts, av_rescale_q(ost->first_pts,
> +                                                  ost->enc_ctx->time_base,
> +                                                  AV_TIME_BASE_Q));
>          /* compute min output value */
>          if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE)
>              pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st),
> @@ -1752,6 +1757,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
>              nb_frames_drop += ost->last_dropped;
>      }
>  
> +    pts -= first_pts;
>      secs = FFABS(pts) / AV_TIME_BASE;
>      us = FFABS(pts) % AV_TIME_BASE;
>      mins = secs / 60;

there is a check later for pts to be equal AV_NOPTS_VALUE
that will not work with a "first pts" offset

[...]
diff mbox

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index d9bb78a..9b71525 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1646,7 +1646,7 @@  static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
     int frame_number, vid, i;
     double bitrate;
     double speed;
-    int64_t pts = INT64_MIN + 1;
+    int64_t pts = INT64_MIN + 1, first_pts = INT64_MAX;
     static int64_t last_time = -1;
     static int qp_histogram[52];
     int hours, mins, secs, us;
@@ -1744,6 +1744,11 @@  static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
             }
             vid = 1;
         }
+
+        /* Find the first written PTS among all the output streams */
+        first_pts = FFMIN(first_pts, av_rescale_q(ost->first_pts,
+                                                  ost->enc_ctx->time_base,
+                                                  AV_TIME_BASE_Q));
         /* compute min output value */
         if (av_stream_get_end_pts(ost->st) != AV_NOPTS_VALUE)
             pts = FFMAX(pts, av_rescale_q(av_stream_get_end_pts(ost->st),
@@ -1752,6 +1757,7 @@  static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti
             nb_frames_drop += ost->last_dropped;
     }
 
+    pts -= first_pts;
     secs = FFABS(pts) / AV_TIME_BASE;
     us = FFABS(pts) % AV_TIME_BASE;
     mins = secs / 60;