[FFmpeg-devel,1/2] avformat/hlsenc: fix the duration of m4s segment is unusually smaller than expected.

Submitted by Charles Liu on Oct. 9, 2018, 6:56 a.m.

Details

Message ID 20181009065611.10788-1-liuchh83@gmail.com
State Accepted
Commit 3d1b7954933b17fc8ff5204e231f63fcb7ff63a9
Headers show

Commit Message

Charles Liu Oct. 9, 2018, 6:56 a.m.
In fmp4 mode, the duration of the second m4s segment is unusually smaller than the expected segment time.

Signed-off-by: Charles Liu <liuchh83@gmail.com>
---
 libavformat/hlsenc.c | 4 ----
 1 file changed, 4 deletions(-)

Comments

Steven Liu Oct. 9, 2018, 7:17 a.m.
> 在 2018年10月9日,下午2:56,Charles Liu <liuchh83@gmail.com> 写道:
> 
> In fmp4 mode, the duration of the second m4s segment is unusually smaller than the expected segment time.
> 
> Signed-off-by: Charles Liu <liuchh83@gmail.com>
> ---
> libavformat/hlsenc.c | 4 ----
> 1 file changed, 4 deletions(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 28c2dd62fc..3ccd8756f6 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -2233,10 +2233,6 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
>                 }
>         }
> 
> -        if (vs->fmp4_init_mode) {
> -            vs->number--;
> -        }

No, this is reserve, will be used by byterange mode
> -
>         if (hls->segment_type == SEGMENT_TYPE_FMP4) {
>             if (hls->flags & HLS_SINGLE_FILE) {
>                 ret = flush_dynbuf(vs, &range_length);
> -- 
> 2.19.1
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Charles Liu Oct. 9, 2018, 8:05 a.m.
My test clip is big_buck_bunny_1080p_h264.mov with CMD:

./ffmpeg -i ~/Downloads/conversion/big_buck_bunny_1080p_h264.mov -t 50
-flags +cgop -g 30 -preset superfast -f hls -hls_segment_type fmp4
-hls_playlist_type vod -hls_time 10 issue/pl.m3u8

The original result is:

#EXTM3U

#EXT-X-VERSION:7

#EXT-X-TARGETDURATION:10

#EXT-X-MEDIA-SEQUENCE:0

#EXT-X-PLAYLIST-TYPE:VOD

#EXT-X-MAP:URI="init.mp4"

#EXTINF:10.416667,

pl0.m4s

#EXTINF:1.250000,

pl1.m4s

#EXTINF:9.083333,

pl2.m4s

#EXTINF:9.791667,

pl3.m4s

#EXTINF:10.000000,

pl4.m4s

#EXTINF:9.458333,

pl5.m4s

#EXT-X-ENDLIST



After apply the patch, the result become to:

#EXTM3U

#EXT-X-VERSION:7

#EXT-X-TARGETDURATION:10

#EXT-X-MEDIA-SEQUENCE:0

#EXT-X-PLAYLIST-TYPE:VOD

#EXT-X-MAP:URI="init.mp4"

#EXTINF:10.416667,

pl0.m4s

#EXTINF:10.333333,

pl1.m4s

#EXTINF:9.791667,

pl2.m4s

#EXTINF:10.000000,

pl3.m4s

#EXTINF:9.458333,

pl4.m4s

#EXT-X-ENDLIST



Seems that the vs→number in function hls_write_packet() was minus once
more. Then “end_pts = hls->recording_time * vs→number;” was too small.

After having enough buffer (av_compare_ts() around line 2189), we generate
the init.mp4 firstly, then the first segment. It should be generate the
second segment, when we DO have enough buffer for the second time, .
However, the end_pts dons’t grow any, because the vs→number was subtracted
1.

Liu Steven <lq@chinaffmpeg.org> 于2018年10月9日周二 下午3:28写道:

>
>
> > 在 2018年10月9日,下午3:17,Liu Steven <lq@chinaffmpeg.org> 写道:
> >
> >
> >
> >> 在 2018年10月9日,下午2:56,Charles Liu <liuchh83@gmail.com> 写道:
> >>
> >> In fmp4 mode, the duration of the second m4s segment is unusually
> smaller than the expected segment time.
> >>
> >> Signed-off-by: Charles Liu <liuchh83@gmail.com>
> >> ---
> >> libavformat/hlsenc.c | 4 ----
> >> 1 file changed, 4 deletions(-)
> >>
> >> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> >> index 28c2dd62fc..3ccd8756f6 100644
> >> --- a/libavformat/hlsenc.c
> >> +++ b/libavformat/hlsenc.c
> >> @@ -2233,10 +2233,6 @@ static int hls_write_packet(AVFormatContext *s,
> AVPacket *pkt)
> >>                }
> >>        }
> >>
> >> -        if (vs->fmp4_init_mode) {
> >> -            vs->number--;
> >> -        }
> >
> > No, this is reserve, will be used by byterange mode
>
> Ah, sorry my mistake, it is because the when the init.mp4 is not in the
> sequence, so the start number should be 0.
> >> -
> >>        if (hls->segment_type == SEGMENT_TYPE_FMP4) {
> >>            if (hls->flags & HLS_SINGLE_FILE) {
> >>                ret = flush_dynbuf(vs, &range_length);
> >> --
> >> 2.19.1
> >>
> >> _______________________________________________
> >> ffmpeg-devel mailing list
> >> ffmpeg-devel@ffmpeg.org
> >> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> >
> >
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Patch hide | download patch | download mbox

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 28c2dd62fc..3ccd8756f6 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2233,10 +2233,6 @@  static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
                 }
         }
 
-        if (vs->fmp4_init_mode) {
-            vs->number--;
-        }
-
         if (hls->segment_type == SEGMENT_TYPE_FMP4) {
             if (hls->flags & HLS_SINGLE_FILE) {
                 ret = flush_dynbuf(vs, &range_length);