[FFmpeg-devel] [PATCH] hlsenc: added floating point time support.

Senthil senthil.codr at gmail.com
Wed Apr 2 21:27:44 CEST 2014


On Wed, Apr 2, 2014 at 10:56 AM, Reimar Döffinger
<Reimar.Doeffinger at gmx.de>wrote:

> On 02.04.2014, at 05:29, Senthil <senthil.codr at gmail.com> wrote:
> > Necessary for HLS version 3 and above.  Fixes ticket #3505.
>
Either way, both float itself and %f have very limited precision.
> I'd suggest going with double and explicitly specifying a higher precision
> in the format string.
> Possibly even going with %e if the spec allows for it and there are no
> compatibility issues.
>
Here is the relevant portion in the spec:
http://tools.ietf.org/html/draft-pantos-http-live-streaming-12#section-3.3.2

Though it does not mention about double precision, I have produced a double
version of the patch below.

Necessary for HLS version 3 and above.  Fixes ticket #3505.

Signed-off-by: Senthilnathan M <senthil.codr at gmail.com>
---
 libavformat/hlsenc.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 1b5ef0e..e7e67c6 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -33,7 +33,7 @@

 typedef struct ListEntry {
     char  name[1024];
-    int   duration;
+    double   duration;
     struct ListEntry *next;
 } ListEntry;

@@ -50,7 +50,7 @@ typedef struct HLSContext {
     int has_video;
     int64_t start_pts;
     int64_t end_pts;
-    int64_t duration;      // last segment duration computed so far, in
seconds
+    double duration;      // last segment duration computed so far, in
seconds
     int nb_entries;
     ListEntry *list;
     ListEntry *end_list;
@@ -83,7 +83,7 @@ static int hls_mux_init(AVFormatContext *s)
     return 0;
 }

-static int append_entry(HLSContext *hls, uint64_t duration)
+static int append_entry(HLSContext *hls, double duration)
 {
     ListEntry *en = av_malloc(sizeof(*en));

@@ -138,7 +138,7 @@ static int hls_window(AVFormatContext *s, int last)

     for (en = hls->list; en; en = en->next) {
         if (target_duration < en->duration)
-            target_duration = en->duration;
+            target_duration = (int) floor(en->duration + 0.5);
     }

     avio_printf(hls->pb, "#EXTM3U\n");
@@ -148,7 +148,7 @@ static int hls_window(AVFormatContext *s, int last)
                 FFMAX(0, hls->sequence - hls->nb_entries));

     for (en = hls->list; en; en = en->next) {
-        avio_printf(hls->pb, "#EXTINF:%d,\n", en->duration);
+        avio_printf(hls->pb, "#EXTINF:%lf,\n", en->duration);
         avio_printf(hls->pb, "%s\n", en->name);
     }

@@ -270,8 +270,8 @@ static int hls_write_packet(AVFormatContext *s,
AVPacket *pkt)
         is_ref_pkt = can_split = 0;

     if (is_ref_pkt)
-        hls->duration = av_rescale(pkt->pts - hls->end_pts,
-                                   st->time_base.num, st->time_base.den);
+        hls->duration = (double)(pkt->pts - hls->end_pts)
+                                   * st->time_base.num / st->time_base.den;

     if (can_split && av_compare_ts(pkt->pts - hls->start_pts,
st->time_base,
                                    end_pts, AV_TIME_BASE_Q) >= 0) {
-- 
1.7.9.5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-hlsenc-added-floating-point-time-support.patch
Type: text/x-patch
Size: 2592 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140403/363e4135/attachment.bin>


More information about the ffmpeg-devel mailing list