avformat/hlsplaylist: fix byte offsets for single_file+iframes_only

fix ticket: 8636

video_keyframe_size and video_keyframe_pos tracked the end of the
previous P/B frame. In the case of I-frame only videos, this would
result in byteoffsets always being 0@0 in the case of fmp4. For
mpegts, the size would be correct but the pos still always be @0.

Since size and pos already correctly track the start of a segment,
we can re-use them even in I-frame only mode.
This commit is contained in:
Stefan Breunig
2026-04-26 09:19:44 +02:00
committed by stevenliu
parent e999ea73bc
commit ea3d417d90
4 changed files with 4 additions and 7 deletions

View File

@@ -436,7 +436,7 @@ static void write_hls_media_playlist(OutputStream *os, AVFormatContext *s,
(double) seg->duration / timescale, 0,
seg->range_length, seg->start_pos, NULL,
c->single_file ? os->initfile : seg->file,
&prog_date_time, 0, 0, 0);
&prog_date_time, 0);
if (ret < 0) {
av_log(os->ctx, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n");
}

View File

@@ -1620,7 +1620,7 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs)
en->size, en->pos, hls->baseurl,
en->filename,
en->discont_program_date_time ? &en->discont_program_date_time : prog_date_time_p,
en->keyframe_size, en->keyframe_pos, hls->flags & HLS_I_FRAMES_ONLY);
hls->flags & HLS_I_FRAMES_ONLY);
if (en->discont_program_date_time)
en->discont_program_date_time -= en->duration;
if (ret < 0) {
@@ -1644,7 +1644,7 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs)
for (en = vs->segments; en; en = en->next) {
ret = ff_hls_write_file_entry(hls->sub_m3u8_out, en->discont, byterange_mode,
en->duration, 0, en->size, en->pos,
hls->baseurl, en->sub_filename, NULL, 0, 0, 0);
hls->baseurl, en->sub_filename, NULL, 0);
if (ret < 0) {
av_log(s, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n");
}

View File

@@ -147,7 +147,6 @@ int ff_hls_write_file_entry(AVIOContext *out, int insert_discont,
int64_t pos /* Used only if HLS_SINGLE_FILE flag is set */,
const char *baseurl /* Ignored if NULL */,
const char *filename, double *prog_date_time,
int64_t video_keyframe_size, int64_t video_keyframe_pos,
int iframe_mode)
{
if (!out || !filename)
@@ -161,8 +160,7 @@ int ff_hls_write_file_entry(AVIOContext *out, int insert_discont,
else
avio_printf(out, "#EXTINF:%f,\n", duration);
if (byterange_mode)
avio_printf(out, "#EXT-X-BYTERANGE:%"PRId64"@%"PRId64"\n", iframe_mode ? video_keyframe_size : size,
iframe_mode ? video_keyframe_pos : pos);
avio_printf(out, "#EXT-X-BYTERANGE:%"PRId64"@%"PRId64"\n", size, pos);
if (prog_date_time) {
time_t tt, wrongsecs;

View File

@@ -58,7 +58,6 @@ int ff_hls_write_file_entry(AVIOContext *out, int insert_discont,
int64_t pos /* Used only if HLS_SINGLE_FILE flag is set */,
const char *baseurl /* Ignored if NULL */,
const char *filename, double *prog_date_time,
int64_t video_keyframe_size, int64_t video_keyframe_pos,
int iframe_mode);
void ff_hls_write_end_list (AVIOContext *out);