diff mbox

[FFmpeg-devel,1/1] fftools/ffmpeg: fix for all forced key frames when 'copyts' is enabled

Message ID 1525626539-30152-1-git-send-email-vdixit@akamai.com
State Accepted
Commit 146cdf7e4bb029c9e457742d82d00d3b396b9ff4
Headers show

Commit Message

Dixit, Vishwanath May 6, 2018, 5:08 p.m. UTC
From: Vishwanath Dixit <vdixit@akamai.com>

Forced key frames generation functionality was assuming the first PTS
value as zero, but, when 'copyts' is enabled, the first PTS can be any
big number. This was eventually forcing all the frames as key frames.
To resolve this issue, update has been made to use first input pts as
reference pts.
---
 fftools/ffmpeg.c     | 6 +++++-
 fftools/ffmpeg.h     | 1 +
 fftools/ffmpeg_opt.c | 1 +
 3 files changed, 7 insertions(+), 1 deletion(-)

Comments

Dixit, Vishwanath June 4, 2018, 5:38 a.m. UTC | #1
On 5/6/18 10:38 PM, vdixit@akamai.com wrote:
> From: Vishwanath Dixit <vdixit@akamai.com>

>

> Forced key frames generation functionality was assuming the first PTS

> value as zero, but, when 'copyts' is enabled, the first PTS can be any

> big number. This was eventually forcing all the frames as key frames.

> To resolve this issue, update has been made to use first input pts as

> reference pts.

> ---

>  fftools/ffmpeg.c     | 6 +++++-

>  fftools/ffmpeg.h     | 1 +

>  fftools/ffmpeg_opt.c | 1 +

>  3 files changed, 7 insertions(+), 1 deletion(-)

>

> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c

> index 5a19a09..10f3012 100644

> --- a/fftools/ffmpeg.c

> +++ b/fftools/ffmpeg.c

> @@ -1236,8 +1236,12 @@ static void do_video_out(OutputFile *of,

>          in_picture->quality = enc->global_quality;

>          in_picture->pict_type = 0;

>  

> +        if (ost->forced_kf_ref_pts == AV_NOPTS_VALUE &&

> +            in_picture->pts != AV_NOPTS_VALUE)

> +            ost->forced_kf_ref_pts = in_picture->pts;

> +

>          pts_time = in_picture->pts != AV_NOPTS_VALUE ?

> -            in_picture->pts * av_q2d(enc->time_base) : NAN;

> +            (in_picture->pts - ost->forced_kf_ref_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]) {

>              ost->forced_kf_index++;

> diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h

> index d44b7a5..eb1eaf6 100644

> --- a/fftools/ffmpeg.h

> +++ b/fftools/ffmpeg.h

> @@ -484,6 +484,7 @@ typedef struct OutputStream {

>      AVRational frame_aspect_ratio;

>  

>      /* forced key frames */

> +    int64_t forced_kf_ref_pts;

>      int64_t *forced_kf_pts;

>      int forced_kf_count;

>      int forced_kf_index;

> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c

> index 8ae68ae..36bce44 100644

> --- a/fftools/ffmpeg_opt.c

> +++ b/fftools/ffmpeg_opt.c

> @@ -1324,6 +1324,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e

>      ost->file_index = nb_output_files - 1;

>      ost->index      = idx;

>      ost->st         = st;

> +    ost->forced_kf_ref_pts = AV_NOPTS_VALUE;

>      st->codecpar->codec_type = type;

>  

>      ret = choose_encoder(o, oc, ost);


Hi Michael Niedermayer

Could you please push this patch? I had sent this revised patch based on your review comments earlier.	

Regards,
Vishwanath
Michael Niedermayer June 4, 2018, 8:39 p.m. UTC | #2
On Sun, May 06, 2018 at 10:38:59PM +0530, vdixit@akamai.com wrote:
> From: Vishwanath Dixit <vdixit@akamai.com>
> 
> Forced key frames generation functionality was assuming the first PTS
> value as zero, but, when 'copyts' is enabled, the first PTS can be any
> big number. This was eventually forcing all the frames as key frames.
> To resolve this issue, update has been made to use first input pts as
> reference pts.
> ---
>  fftools/ffmpeg.c     | 6 +++++-
>  fftools/ffmpeg.h     | 1 +
>  fftools/ffmpeg_opt.c | 1 +
>  3 files changed, 7 insertions(+), 1 deletion(-)

will apply

thx

[...]
Dixit, Vishwanath June 6, 2018, 7:51 a.m. UTC | #3
On 6/5/18 2:09 AM, Michael Niedermayer wrote:
> On Sun, May 06, 2018 at 10:38:59PM +0530, vdixit@akamai.com wrote:

>> From: Vishwanath Dixit <vdixit@akamai.com>

>>

>> Forced key frames generation functionality was assuming the first PTS

>> value as zero, but, when 'copyts' is enabled, the first PTS can be any

>> big number. This was eventually forcing all the frames as key frames.

>> To resolve this issue, update has been made to use first input pts as

>> reference pts.

>> ---

>>  fftools/ffmpeg.c     | 6 +++++-

>>  fftools/ffmpeg.h     | 1 +

>>  fftools/ffmpeg_opt.c | 1 +

>>  3 files changed, 7 insertions(+), 1 deletion(-)

>

> will apply

Thanks for applying the patch...
>

> thx

>

> [...]

>

>

> _______________________________________________

> ffmpeg-devel mailing list

> ffmpeg-devel@ffmpeg.org

> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
diff mbox

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5a19a09..10f3012 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1236,8 +1236,12 @@  static void do_video_out(OutputFile *of,
         in_picture->quality = enc->global_quality;
         in_picture->pict_type = 0;
 
+        if (ost->forced_kf_ref_pts == AV_NOPTS_VALUE &&
+            in_picture->pts != AV_NOPTS_VALUE)
+            ost->forced_kf_ref_pts = in_picture->pts;
+
         pts_time = in_picture->pts != AV_NOPTS_VALUE ?
-            in_picture->pts * av_q2d(enc->time_base) : NAN;
+            (in_picture->pts - ost->forced_kf_ref_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]) {
             ost->forced_kf_index++;
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index d44b7a5..eb1eaf6 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -484,6 +484,7 @@  typedef struct OutputStream {
     AVRational frame_aspect_ratio;
 
     /* forced key frames */
+    int64_t forced_kf_ref_pts;
     int64_t *forced_kf_pts;
     int forced_kf_count;
     int forced_kf_index;
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 8ae68ae..36bce44 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1324,6 +1324,7 @@  static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
     ost->file_index = nb_output_files - 1;
     ost->index      = idx;
     ost->st         = st;
+    ost->forced_kf_ref_pts = AV_NOPTS_VALUE;
     st->codecpar->codec_type = type;
 
     ret = choose_encoder(o, oc, ost);