* [FFmpeg-devel] [PATCH] avformat/hlsenc: calculate bitrate for segments with duration < 0.5
@ 2025-03-23 23:13 Jack Lau via ffmpeg-devel
2025-03-24 0:11 ` Steven Liu
0 siblings, 1 reply; 3+ messages in thread
From: Jack Lau via ffmpeg-devel @ 2025-03-23 23:13 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Jack Lau
The previous code sets the bitrate to be calculated only when duration>0.5, which is obviously not general enough.
In some scenarios, we may need to set hls_time<0.5, then the generated segments are all <0.5. At this time, because the bitrate is not calculated, max_bitrate is empty, and ff_hls_write_stream_info cannot write stream info normally, causing master_pl to be unavailable.
Signed-off-by: Jack Lau <jacklau1222@qq.com>
---
libavformat/hlsenc.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index c6ffdb99e5..223c516103 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1150,9 +1150,7 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls,
vs->total_size += size;
vs->total_duration += duration;
- if (duration > 0.5) {
- // Don't include the final, possibly very short segment in the
- // calculation of the max bitrate.
+ if (duration > 0) {
int cur_bitrate = (int)(8 * size / duration);
if (cur_bitrate > vs->max_bitrate)
vs->max_bitrate = cur_bitrate;
--
2.47.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: calculate bitrate for segments with duration < 0.5
2025-03-23 23:13 [FFmpeg-devel] [PATCH] avformat/hlsenc: calculate bitrate for segments with duration < 0.5 Jack Lau via ffmpeg-devel
@ 2025-03-24 0:11 ` Steven Liu
2025-03-24 0:18 ` Jack Lau
0 siblings, 1 reply; 3+ messages in thread
From: Steven Liu @ 2025-03-24 0:11 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: Jack Lau
Jack Lau via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> 于2025年3月24日周一 07:13写道:
>
> The previous code sets the bitrate to be calculated only when duration>0.5, which is obviously not general enough.
>
> In some scenarios, we may need to set hls_time<0.5, then the generated segments are all <0.5. At this time, because the bitrate is not calculated, max_bitrate is empty, and ff_hls_write_stream_info cannot write stream info normally, causing master_pl to be unavailable.
>
> Signed-off-by: Jack Lau <jacklau1222@qq.com>
> ---
> libavformat/hlsenc.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index c6ffdb99e5..223c516103 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -1150,9 +1150,7 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls,
>
> vs->total_size += size;
> vs->total_duration += duration;
> - if (duration > 0.5) {
> - // Don't include the final, possibly very short segment in the
> - // calculation of the max bitrate.
> + if (duration > 0) {
I'm not sure if this will work well in llhls mode,
but when the network conditions are even slightly poor,
severe stuttering or even an inability to continue playback occurs.
This is because the segments are so small that the network overhead
exceeds the time it takes to play them.
> int cur_bitrate = (int)(8 * size / duration);
> if (cur_bitrate > vs->max_bitrate)
> vs->max_bitrate = cur_bitrate;
> --
> 2.47.1
>
> _______________________________________________
> 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
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: calculate bitrate for segments with duration < 0.5
2025-03-24 0:11 ` Steven Liu
@ 2025-03-24 0:18 ` Jack Lau
0 siblings, 0 replies; 3+ messages in thread
From: Jack Lau @ 2025-03-24 0:18 UTC (permalink / raw)
To: FFmpeg development discussions and patches
> On Mar 24, 2025, at 08:11, Steven Liu <lingjiujianke@gmail.com> wrote:
>
> Jack Lau via ffmpeg-devel <ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>> 于2025年3月24日周一 07:13写道:
>>
>> The previous code sets the bitrate to be calculated only when duration>0.5, which is obviously not general enough.
>>
>> In some scenarios, we may need to set hls_time<0.5, then the generated segments are all <0.5. At this time, because the bitrate is not calculated, max_bitrate is empty, and ff_hls_write_stream_info cannot write stream info normally, causing master_pl to be unavailable.
>>
>> Signed-off-by: Jack Lau <jacklau1222@qq.com>
>> ---
>> libavformat/hlsenc.c | 4 +---
>> 1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index c6ffdb99e5..223c516103 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -1150,9 +1150,7 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls,
>>
>> vs->total_size += size;
>> vs->total_duration += duration;
>> - if (duration > 0.5) {
>> - // Don't include the final, possibly very short segment in the
>> - // calculation of the max bitrate.
>> + if (duration > 0) {
>
> I'm not sure if this will work well in llhls mode,
> but when the network conditions are even slightly poor,
> severe stuttering or even an inability to continue playback occurs.
> This is because the segments are so small that the network overhead
> exceeds the time it takes to play them.
Thanks for your reply, It seems that the actual situation requires more complex considerations. I will study it further.
>
>> int cur_bitrate = (int)(8 * size / duration);
>> if (cur_bitrate > vs->max_bitrate)
>> vs->max_bitrate = cur_bitrate;
>> --
>> 2.47.1
>>
>> _______________________________________________
>> 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
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org <mailto:ffmpeg-devel-request@ffmpeg.org> with subject "unsubscribe”.
Regards
Jack
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-24 0:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-23 23:13 [FFmpeg-devel] [PATCH] avformat/hlsenc: calculate bitrate for segments with duration < 0.5 Jack Lau via ffmpeg-devel
2025-03-24 0:11 ` Steven Liu
2025-03-24 0:18 ` Jack Lau
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git