[FFmpeg-devel] ffmpeg: add new forced_keyframes option -hls:time

Submitted by Miroslav Slugeň on Feb. 12, 2017, 6:12 p.m.

Details

Message ID 58A0A58F.5030403@email.cz
State New
Headers show

Commit Message

Miroslav Slugeň Feb. 12, 2017, 6:12 p.m.
If we are using copyts parameter it is not possible to inserting key 
frames same way as hlsenc requests, this will lead to different hls 
segments length.

-copyts is required for long period audio/video sync

Small modification to hlsenc.c is also required and will arrive in next 
patch.

Comments

Michael Niedermayer Feb. 14, 2017, 11:18 a.m.
On Sun, Feb 12, 2017 at 07:12:31PM +0100, Miroslav Slugeň wrote:
> If we are using copyts parameter it is not possible to inserting key
> frames same way as hlsenc requests, this will lead to different hls
> segments length.
> 
> -copyts is required for long period audio/video sync
> 
> Small modification to hlsenc.c is also required and will arrive in
> next patch.
> 
> -- 
> Miroslav Slugeň
> 
> 
> 
> 
> 
> 
> 
> 
> 

>  ffmpeg.c |   19 +++++++++++++++++++
>  ffmpeg.h |    4 ++++
>  2 files changed, 23 insertions(+)
> 77d7894d66a6195b7ed7c3e1f1998ec8289f66a2  0001-ffmpeg-add-new-forced_keyframes-option-hls-time-for-.patch
> From 90d0636ea6cd34c9b51e4b568bb9e8aa461fa615 Mon Sep 17 00:00:00 2001
> From: Miroslav Slugen <thunder.m@email.cz>
> Date: Sun, 12 Feb 2017 19:08:27 +0100
> Subject: [PATCH 1/1] ffmpeg: add new forced_keyframes option -hls:time for
>  inserting keyframes exactly athlsenc position compatible with copyts
> 
> ---
>  ffmpeg.c | 19 +++++++++++++++++++
>  ffmpeg.h |  4 ++++
>  2 files changed, 23 insertions(+)

Missing update to documentation

[...]
Steven Liu Feb. 14, 2017, 11:33 a.m.
2017-02-14 19:18 GMT+08:00 Michael Niedermayer <michael@niedermayer.cc>:

> On Sun, Feb 12, 2017 at 07:12:31PM +0100, Miroslav Slugeň wrote:
> > If we are using copyts parameter it is not possible to inserting key
> > frames same way as hlsenc requests, this will lead to different hls
> > segments length.
> >
> > -copyts is required for long period audio/video sync
> >
> > Small modification to hlsenc.c is also required and will arrive in
> > next patch.
> >
> > --
> > Miroslav Slugeň
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
> >  ffmpeg.c |   19 +++++++++++++++++++
> >  ffmpeg.h |    4 ++++
> >  2 files changed, 23 insertions(+)
> > 77d7894d66a6195b7ed7c3e1f1998ec8289f66a2  0001-ffmpeg-add-new-forced_
> keyframes-option-hls-time-for-.patch
> > From 90d0636ea6cd34c9b51e4b568bb9e8aa461fa615 Mon Sep 17 00:00:00 2001
> > From: Miroslav Slugen <thunder.m@email.cz>
> > Date: Sun, 12 Feb 2017 19:08:27 +0100
> > Subject: [PATCH 1/1] ffmpeg: add new forced_keyframes option -hls:time
> for
> >  inserting keyframes exactly athlsenc position compatible with copyts
> >
> > ---
> >  ffmpeg.c | 19 +++++++++++++++++++
> >  ffmpeg.h |  4 ++++
> >  2 files changed, 23 insertions(+)
>
> Missing update to documentation
>
> [...]
>
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> You can kill me, but you cannot change the truth.
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
BTW, Add FATE please.

Patch hide | download patch | download mbox

From 90d0636ea6cd34c9b51e4b568bb9e8aa461fa615 Mon Sep 17 00:00:00 2001
From: Miroslav Slugen <thunder.m@email.cz>
Date: Sun, 12 Feb 2017 19:08:27 +0100
Subject: [PATCH 1/1] ffmpeg: add new forced_keyframes option -hls:time for
 inserting keyframes exactly athlsenc position compatible with copyts

---
 ffmpeg.c | 19 +++++++++++++++++++
 ffmpeg.h |  4 ++++
 2 files changed, 23 insertions(+)

diff --git a/ffmpeg.c b/ffmpeg.c
index 06570c0..6ba5771 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -1237,6 +1237,20 @@  static void do_video_out(OutputFile *of,
             }
 
             ost->forced_keyframes_expr_const_values[FKF_N] += 1;
+        } else if (ost->forced_keyframes_hls_interval) {
+            if (in_picture->pts != AV_NOPTS_VALUE) {
+                int64_t pts_out = av_rescale_q(in_picture->pts, enc->time_base, ost->st->time_base);
+
+                if (ost->forced_keyframes_hls_start_pts == AV_NOPTS_VALUE) {
+                    ost->forced_keyframes_hls_start_pts = pts_out;
+                }
+
+                if (av_compare_ts(pts_out - ost->forced_keyframes_hls_start_pts, ost->st->time_base, ost->forced_keyframes_hls_end_pts, AV_TIME_BASE_Q) >= 0) {
+                    ost->forced_keyframes_hls_number++;
+                    ost->forced_keyframes_hls_end_pts+= ost->forced_keyframes_hls_interval;
+                    forced_keyframe = 1;
+                }
+            }
         } else if (   ost->forced_keyframes
                    && !strncmp(ost->forced_keyframes, "source", 6)
                    && in_picture->key_frame==1) {
@@ -3224,6 +3238,11 @@  static int init_output_stream_encode(OutputStream *ost)
                 ost->forced_keyframes_expr_const_values[FKF_N_FORCED] = 0;
                 ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] = NAN;
                 ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T] = NAN;
+            } else if (!strncmp(ost->forced_keyframes, "hls:", 4)) {
+                ost->forced_keyframes_hls_interval = atof(ost->forced_keyframes+4) * AV_TIME_BASE;
+                ost->forced_keyframes_hls_number = 1;
+                ost->forced_keyframes_hls_start_pts = AV_NOPTS_VALUE;
+                ost->forced_keyframes_hls_end_pts = ost->forced_keyframes_hls_interval;
 
             // Don't parse the 'forced_keyframes' in case of 'keep-source-keyframes',
             // parse it only for static kf timings
diff --git a/ffmpeg.h b/ffmpeg.h
index 458bb8a..85a8f18 100644
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -478,6 +478,10 @@  typedef struct OutputStream {
     char *forced_keyframes;
     AVExpr *forced_keyframes_pexpr;
     double forced_keyframes_expr_const_values[FKF_NB];
+    int forced_keyframes_hls_interval;
+    int64_t forced_keyframes_hls_number;
+    int64_t forced_keyframes_hls_start_pts;
+    int64_t forced_keyframes_hls_end_pts;
 
     /* audio only */
     int *audio_channels_map;             /* list of the channels id to pick from the source stream */
-- 
2.1.4