diff mbox

[FFmpeg-devel] avformat/hlsenc: fix the bug when the largest segment duration pointer right value is 0

Message ID 20170110152829.14039-1-lq@chinaffmpeg.org
State Accepted
Commit daff04bd1837442286fcb6b58546a2cc7f5b589d
Headers show

Commit Message

Liu Steven Jan. 10, 2017, 3:28 p.m. UTC
when the segments largest duration value is look like 4.000000, the
EXT-X-TARGETDURATION value should equ 4.
it's wrong when hlsenc use ceil, so fix it.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
---
 libavformat/hlsenc.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Steven Liu Jan. 10, 2017, 8:41 p.m. UTC | #1
2017-01-10 23:28 GMT+08:00 Steven Liu <lq@chinaffmpeg.org>:

> when the segments largest duration value is look like 4.000000, the
> EXT-X-TARGETDURATION value should equ 4.
> it's wrong when hlsenc use ceil, so fix it.
>
> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
> ---
>  libavformat/hlsenc.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 3d2d41a..a2c606c 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -141,6 +141,11 @@ typedef struct HLSContext {
>      char current_segment_final_filename_fmt[1024]; // when renaming
> segments
>  } HLSContext;
>
> +static int get_int_from_double(double val)
> +{
> +    return (int)((val - (int)val) >= 0.001) ? (int)(val + 1) : (int)val;
> +}
> +
>  static int mkdir_p(const char *path) {
>      int ret = 0;
>      char *temp = av_strdup(path);
> @@ -668,8 +673,8 @@ static int hls_window(AVFormatContext *s, int last)
>          goto fail;
>
>      for (en = hls->segments; en; en = en->next) {
> -        if (target_duration < en->duration)
> -            target_duration = ceil(en->duration);
> +        if (target_duration <= en->duration)
> +            target_duration = get_int_from_double(en->duration);
>      }
>
>      hls->discontinuity_set = 0;
> --
> 2.10.1 (Apple Git-78)
>
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

applied!



Thanks
diff mbox

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 3d2d41a..a2c606c 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -141,6 +141,11 @@  typedef struct HLSContext {
     char current_segment_final_filename_fmt[1024]; // when renaming segments
 } HLSContext;
 
+static int get_int_from_double(double val)
+{
+    return (int)((val - (int)val) >= 0.001) ? (int)(val + 1) : (int)val;
+}
+
 static int mkdir_p(const char *path) {
     int ret = 0;
     char *temp = av_strdup(path);
@@ -668,8 +673,8 @@  static int hls_window(AVFormatContext *s, int last)
         goto fail;
 
     for (en = hls->segments; en; en = en->next) {
-        if (target_duration < en->duration)
-            target_duration = ceil(en->duration);
+        if (target_duration <= en->duration)
+            target_duration = get_int_from_double(en->duration);
     }
 
     hls->discontinuity_set = 0;