diff mbox series

[FFmpeg-devel] avformat/hlsenc: compute segment duration use current pts minus last segment end pts

Message ID 20200429044400.29529-1-lq@chinaffmpeg.org
State Superseded
Headers show
Series [FFmpeg-devel] avformat/hlsenc: compute segment duration use current pts minus last segment end pts | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Liu Steven April 29, 2020, 4:44 a.m. UTC
segment duration is using vs duration which compute by frame per second,
that can not fix problem of VFR video stream, so compute the duration
when split the segment, set the segment target duration use
current packet pts minus the prev segment end pts and plus current
packet's duration.

Reported-by: Zhao Jun <barryjzhao@tencent.com>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
---
 libavformat/hlsenc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

mypopy@gmail.com April 29, 2020, 7:07 a.m. UTC | #1
On Wed, Apr 29, 2020 at 12:44 PM Steven Liu <lq@chinaffmpeg.org> wrote:
>
> segment duration is using vs duration which compute by frame per second,
> that can not fix problem of VFR video stream, so compute the duration
> when split the segment, set the segment target duration use
> current packet pts minus the prev segment end pts and plus current
> packet's duration.
>
> Reported-by: Zhao Jun <barryjzhao@tencent.com>
> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
> ---
>  libavformat/hlsenc.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index d75684741f..9e8b34d83c 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -2460,7 +2460,8 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
>          }
>
>          if (vs->start_pos || hls->segment_type != SEGMENT_TYPE_FMP4) {
> -            ret = hls_append_segment(s, hls, vs, vs->duration, vs->start_pos, vs->size);
> +            double cur_duration =  (double)(pkt->pts - vs->end_pts) * st->time_base.num / st->time_base.den + vs->dpp;
> +            ret = hls_append_segment(s, hls, vs, cur_duration, vs->start_pos, vs->size);
>              vs->end_pts = pkt->pts;
>              vs->duration = 0;
>              if (ret < 0) {
> --
> 2.25.0
>
>
LGTM, Tested and verified, tks the quick fix.
Liu Steven April 29, 2020, 12:33 p.m. UTC | #2
> 2020年4月29日 下午3:07,mypopy@gmail.com 写道:
> 
> On Wed, Apr 29, 2020 at 12:44 PM Steven Liu <lq@chinaffmpeg.org> wrote:
>> 
>> segment duration is using vs duration which compute by frame per second,
>> that can not fix problem of VFR video stream, so compute the duration
>> when split the segment, set the segment target duration use
>> current packet pts minus the prev segment end pts and plus current
>> packet's duration.
>> 
>> Reported-by: Zhao Jun <barryjzhao@tencent.com>
>> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
>> ---
>> libavformat/hlsenc.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>> 
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index d75684741f..9e8b34d83c 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -2460,7 +2460,8 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
>>         }
>> 
>>         if (vs->start_pos || hls->segment_type != SEGMENT_TYPE_FMP4) {
>> -            ret = hls_append_segment(s, hls, vs, vs->duration, vs->start_pos, vs->size);
>> +            double cur_duration =  (double)(pkt->pts - vs->end_pts) * st->time_base.num / st->time_base.den + vs->dpp;
>> +            ret = hls_append_segment(s, hls, vs, cur_duration, vs->start_pos, vs->size);
>>             vs->end_pts = pkt->pts;
>>             vs->duration = 0;
>>             if (ret < 0) {
>> --
>> 2.25.0
>> 
>> 
> LGTM, Tested and verified, tks the quick fix.
Sorry I make a mistake, the pkt should not in current segment, it should in the next segment, so just remove the + vs->dpp
I will submit version 2 patch
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

Thanks

Steven Liu
diff mbox series

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index d75684741f..9e8b34d83c 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2460,7 +2460,8 @@  static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
         }
 
         if (vs->start_pos || hls->segment_type != SEGMENT_TYPE_FMP4) {
-            ret = hls_append_segment(s, hls, vs, vs->duration, vs->start_pos, vs->size);
+            double cur_duration =  (double)(pkt->pts - vs->end_pts) * st->time_base.num / st->time_base.den + vs->dpp;
+            ret = hls_append_segment(s, hls, vs, cur_duration, vs->start_pos, vs->size);
             vs->end_pts = pkt->pts;
             vs->duration = 0;
             if (ret < 0) {