[PATCH] hlsenc: added floating point time support.
Necessary for HLS version 3 and above. Fixes ticket #3505. Signed-off-by: Senthilnathan M <senthil.codr@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..274fb7c 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -33,7 +33,7 @@ typedef struct ListEntry { char name[1024]; - int duration; + float 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 + float 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, float 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:%f,\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 = (float)(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
On 02.04.2014, at 05:29, Senthil <senthil.codr@gmail.com> wrote:
Necessary for HLS version 3 and above. Fixes ticket #3505.
Haven't read the ticket, so I kind of don't really see how it could be required, it just increases precision?! 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.
On Wed, Apr 2, 2014 at 10:56 AM, Reimar Döffinger <Reimar.Doeffinger@gmx.de>wrote:
On 02.04.2014, at 05:29, Senthil <senthil.codr@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@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
On Thu, Apr 03, 2014 at 12:57:44AM +0530, Senthil wrote:
On Wed, Apr 2, 2014 at 10:56 AM, Reimar Döffinger <Reimar.Doeffinger@gmx.de>wrote:
On 02.04.2014, at 05:29, Senthil <senthil.codr@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@gmail.com>
applied thanks [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB You can kill me, but you cannot change the truth.
On 03.04.2014, at 00:39, Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, Apr 03, 2014 at 12:57:44AM +0530, Senthil wrote:
On Wed, Apr 2, 2014 at 10:56 AM, Reimar Döffinger <Reimar.Doeffinger@gmx.de>wrote:
On 02.04.2014, at 05:29, Senthil <senthil.codr@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@gmail.com>
applied
Sorry, but I disagree. The specification says _should_ use float, so it is absolutely _not_ in any way necessary for HLS3. At the same time it is _not_ allowed for HLS2, so unless I missed a check this breaks anything that only supports HLS2. Lastly, the latest change did nothing to address the very limited precision of the %f format specifier (even though it might not be that relevant). Lastly, the ticket does not even mention what the point/advantage of sub-second precision would be. In summary: It looks to me like the patch break things without actually fixing anything at all.
On Thu, Apr 03, 2014 at 08:20:56AM +0200, Reimar Döffinger wrote:
On 03.04.2014, at 00:39, Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, Apr 03, 2014 at 12:57:44AM +0530, Senthil wrote:
On Wed, Apr 2, 2014 at 10:56 AM, Reimar Döffinger <Reimar.Doeffinger@gmx.de>wrote:
On 02.04.2014, at 05:29, Senthil <senthil.codr@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@gmail.com>
applied
Sorry, but I disagree. The specification says _should_ use float, so it is absolutely _not_ in any way necessary for HLS3. At the same time it is _not_ allowed for HLS2, so unless I missed a check this breaks anything that only supports HLS2. Lastly, the latest change did nothing to address the very limited precision of the %f format specifier (even though it might not be that relevant). Lastly, the ticket does not even mention what the point/advantage of sub-second precision would be. In summary: It looks to me like the patch break things without actually fixing anything at all.
our hls code unconditionally adds "#EXT-X-VERSION:3" thus these files are not version 2 compatible and i would expect version 2 players to not even try to play them but i might be wrong or miss something [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB If a bugfix only changes things apparently unrelated to the bug with no further explanation, that is a good sign that the bugfix is wrong.
On Thu, Apr 03, 2014 at 12:28:49PM +0200, Michael Niedermayer wrote:
On Thu, Apr 03, 2014 at 08:20:56AM +0200, Reimar Döffinger wrote:
On 03.04.2014, at 00:39, Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, Apr 03, 2014 at 12:57:44AM +0530, Senthil wrote:
On Wed, Apr 2, 2014 at 10:56 AM, Reimar Döffinger <Reimar.Doeffinger@gmx.de>wrote:
On 02.04.2014, at 05:29, Senthil <senthil.codr@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@gmail.com>
applied
Sorry, but I disagree. The specification says _should_ use float, so it is absolutely _not_ in any way necessary for HLS3. At the same time it is _not_ allowed for HLS2, so unless I missed a check this breaks anything that only supports HLS2. Lastly, the latest change did nothing to address the very limited precision of the %f format specifier (even though it might not be that relevant). Lastly, the ticket does not even mention what the point/advantage of sub-second precision would be. In summary: It looks to me like the patch break things without actually fixing anything at all.
our hls code unconditionally adds "#EXT-X-VERSION:3" thus these files are not version 2 compatible and i would expect version 2 players to not even try to play them but i might be wrong or miss something
I missed that we only do version 3. I guess it's fine then. I still have some concerns about the %f specifier, though since it's used elsewhere it might be a bit pointless to care about it. The concerns I have are 1) It is highly locale-dependent, it would be nice to be able to use this muxer even in an application that uses e.g. de_DE as locale... 2) Its implementations regularly give different output. For example Microsoft's implementation will use round-to-nearest, current libc uses round-to-nearest-even, and older libc if I remember right do something that would best be described as "kind of wrong".
On Thu, Apr 03, 2014 at 09:29:12PM +0200, Reimar Döffinger wrote:
On Thu, Apr 03, 2014 at 12:28:49PM +0200, Michael Niedermayer wrote:
On Thu, Apr 03, 2014 at 08:20:56AM +0200, Reimar Döffinger wrote:
On 03.04.2014, at 00:39, Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, Apr 03, 2014 at 12:57:44AM +0530, Senthil wrote:
On Wed, Apr 2, 2014 at 10:56 AM, Reimar Döffinger <Reimar.Doeffinger@gmx.de>wrote:
On 02.04.2014, at 05:29, Senthil <senthil.codr@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@gmail.com>
applied
Sorry, but I disagree. The specification says _should_ use float, so it is absolutely _not_ in any way necessary for HLS3. At the same time it is _not_ allowed for HLS2, so unless I missed a check this breaks anything that only supports HLS2. Lastly, the latest change did nothing to address the very limited precision of the %f format specifier (even though it might not be that relevant). Lastly, the ticket does not even mention what the point/advantage of sub-second precision would be. In summary: It looks to me like the patch break things without actually fixing anything at all.
our hls code unconditionally adds "#EXT-X-VERSION:3" thus these files are not version 2 compatible and i would expect version 2 players to not even try to play them but i might be wrong or miss something
I missed that we only do version 3. I guess it's fine then. I still have some concerns about the %f specifier, though since it's used elsewhere it might be a bit pointless to care about it.
i dont think its pointless if theres an issue, that would just means theres one elsewhere too maybe we could just provide our own double to ascii implementation
The concerns I have are 1) It is highly locale-dependent, it would be nice to be able to use this muxer even in an application that uses e.g. de_DE as locale...
2) Its implementations regularly give different output. For example Microsoft's implementation will use round-to-nearest, current libc uses round-to-nearest-even, and older libc if I remember right do something that would best be described as "kind of wrong".
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
-- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Concerning the gods, I have no means of knowing whether they exist or not or of what sort they may be, because of the obscurity of the subject, and the brevity of human life -- Protagoras
participants (3)
-
Michael Niedermayer -
Reimar Döffinger -
Senthil