]> git.sesse.net Git - ffmpeg/commitdiff
fftools/ffmpeg: fix for all forced key frames when 'copyts' is enabled
authorVishwanath Dixit <vdixit@akamai.com>
Sun, 6 May 2018 17:08:59 +0000 (22:38 +0530)
committerMichael Niedermayer <michael@niedermayer.cc>
Mon, 4 Jun 2018 20:26:55 +0000 (22:26 +0200)
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.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
fftools/ffmpeg.c
fftools/ffmpeg.h
fftools/ffmpeg_opt.c

index 5a19a09d9a63ccfcb4967c0eba85d1e47203b531..10f3012cdcb05ea2d57d8c4123fc6ec322083e45 100644 (file)
@@ -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++;
index d44b7a5c72a52e843fb84131c35d773b6d639b97..eb1eaf63633bcf284055bb647322d068d0a9e19b 100644 (file)
@@ -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;
index 8ae68aec0e01947b2301b10df6572248ea819617..36bce4465ac2b7da293a2e51dadf7354203847fa 100644 (file)
@@ -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);