Compare commits

...

9 Commits

Author SHA1 Message Date
cclecle
bcb4eae8ec revert 2023-11-18 02:53:36 +00:00
cclecle
6d47344920 test without endlist 2023-11-18 02:51:13 +00:00
cclecle
57b5ab4e62 keep writing manifest in VOD mode. 2023-11-18 02:35:06 +00:00
cclecle
a57ae9bb4b fix hls version header if EXT-X-START used 2023-11-18 01:59:06 +00:00
cclecle
40b17d736f fix 2023-11-18 01:33:30 +00:00
cclecle
1ed220fc58 fix 2023-11-18 01:32:51 +00:00
cclecle
f0a1445b30 fix 2023-11-18 01:26:18 +00:00
cclecle
0a0c5752ff fix regression on dashenc 2023-11-18 01:22:31 +00:00
cclecle
1a024815af Feature EXT-X-START
Re-apply [FFmpeg-devel] [PATCH] lavf/hlsenc: add -hls_start_time to emit
EXT-X-START:TIME-OFFSET
2023-11-18 00:55:39 +00:00
5 changed files with 18 additions and 8 deletions

View File

@@ -1125,6 +1125,9 @@ are always written into temporary file regardless of this flag if @code{master_p
Emit @code{#EXT-X-PLAYLIST-TYPE:EVENT} in the m3u8 header. Forces
@option{hls_list_size} to 0; the playlist can only be appended to.
@item hls_start_time @var{offset}
Emit @code{#EXT-X-START:TIME-OFFSET} in the m3u8 header.
@item hls_playlist_type vod
Emit @code{#EXT-X-PLAYLIST-TYPE:VOD} in the m3u8 header. Forces
@option{hls_list_size} to 0; the playlist must not change.

View File

@@ -540,7 +540,7 @@ static void write_hls_media_playlist(OutputStream *os, AVFormatContext *s,
}
ff_hls_write_playlist_header(c->m3u8_out, 6, -1, target_duration,
start_number, PLAYLIST_TYPE_NONE, 0);
start_number, PLAYLIST_TYPE_NONE, 0, -1);
ff_hls_write_init_file(c->m3u8_out, os->initfile, c->single_file,
os->init_range_length, os->init_start_pos);

View File

@@ -22,6 +22,7 @@
#include "config.h"
#include "config_components.h"
#include <float.h>
#include <stdint.h>
#include <time.h>
#if HAVE_UNISTD_H
@@ -194,6 +195,8 @@ typedef struct HLSContext {
const AVClass *class; // Class for private options.
int64_t start_sequence;
uint32_t start_sequence_source_type; // enum StartSequenceSourceType
double start_offset;
int64_t time; // Set by a private option.
int64_t init_time; // Set by a private option.
@@ -1574,7 +1577,7 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs)
hls->version = 4;
}
if (hls->flags & HLS_INDEPENDENT_SEGMENTS) {
if ((hls->flags & HLS_INDEPENDENT_SEGMENTS) || (hls->start_offset>=0)) {
hls->version = 6;
}
@@ -1602,7 +1605,7 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs)
vs->discontinuity_set = 0;
ff_hls_write_playlist_header(byterange_mode ? hls->m3u8_out : vs->out, hls->version, hls->allowcache,
target_duration, sequence, hls->pl_type, hls->flags & HLS_I_FRAMES_ONLY);
target_duration, sequence, hls->pl_type, hls->flags & HLS_I_FRAMES_ONLY,hls->start_offset);
if ((hls->flags & HLS_DISCONT_START) && sequence==hls->start_sequence && vs->discontinuity_set==0) {
avio_printf(byterange_mode ? hls->m3u8_out : vs->out, "#EXT-X-DISCONTINUITY\n");
@@ -1654,7 +1657,7 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs)
goto fail;
}
ff_hls_write_playlist_header(hls->sub_m3u8_out, hls->version, hls->allowcache,
target_duration, sequence, PLAYLIST_TYPE_NONE, 0);
target_duration, sequence, PLAYLIST_TYPE_NONE, 0,hls->start_offset);
for (en = vs->segments; en; en = en->next) {
ret = ff_hls_write_file_entry(hls->sub_m3u8_out, 0, byterange_mode,
en->duration, 0, en->size, en->pos,
@@ -2627,7 +2630,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
}
// if we're building a VOD playlist, skip writing the manifest multiple times, and just wait until the end
if (hls->pl_type != PLAYLIST_TYPE_VOD) {
//if (hls->pl_type != PLAYLIST_TYPE_VOD) {
if ((ret = hls_window(s, 0, vs)) < 0) {
av_log(s, AV_LOG_WARNING, "upload playlist failed, will retry with a new http session.\n");
ff_format_io_close(s, &vs->out);
@@ -2636,7 +2639,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
return ret;
}
}
}
//}
if (hls->resend_init_file && hls->segment_type == SEGMENT_TYPE_FMP4) {
ret = hls_init_file_resend(s, vs);
@@ -3126,6 +3129,7 @@ static const AVOption options[] = {
{"hls_list_size", "set maximum number of playlist entries", OFFSET(max_nb_segments), AV_OPT_TYPE_INT, {.i64 = 5}, 0, INT_MAX, E},
{"hls_delete_threshold", "set number of unreferenced segments to keep before deleting", OFFSET(hls_delete_threshold), AV_OPT_TYPE_INT, {.i64 = 1}, 1, INT_MAX, E},
{"hls_vtt_options","set hls vtt list of options for the container format used for hls", OFFSET(vtt_format_options_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
{"hls_start_time", "set EXT-X-START:TIME-OFFSET", OFFSET(start_offset), AV_OPT_TYPE_DOUBLE, {.dbl = -1}, -1, DBL_MAX, E},
{"hls_allow_cache", "explicitly set whether the client MAY (1) or MUST NOT (0) cache media segments", OFFSET(allowcache), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, E},
{"hls_base_url", "url to prepend to each playlist entry", OFFSET(baseurl), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},
{"hls_segment_filename", "filename template for segment files", OFFSET(segment_filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E},

View File

@@ -101,7 +101,7 @@ void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth,
void ff_hls_write_playlist_header(AVIOContext *out, int version, int allowcache,
int target_duration, int64_t sequence,
uint32_t playlist_type, int iframe_mode)
uint32_t playlist_type, int iframe_mode, double start_offset)
{
if (!out)
return;
@@ -109,6 +109,9 @@ void ff_hls_write_playlist_header(AVIOContext *out, int version, int allowcache,
if (allowcache == 0 || allowcache == 1) {
avio_printf(out, "#EXT-X-ALLOW-CACHE:%s\n", allowcache == 0 ? "NO" : "YES");
}
if(start_offset>=0){
avio_printf(out, "#EXT-X-START:TIME-OFFSET=%f\n", start_offset);
}
avio_printf(out, "#EXT-X-TARGETDURATION:%d\n", target_duration);
avio_printf(out, "#EXT-X-MEDIA-SEQUENCE:%"PRId64"\n", sequence);
av_log(NULL, AV_LOG_VERBOSE, "EXT-X-MEDIA-SEQUENCE:%"PRId64"\n", sequence);

View File

@@ -48,7 +48,7 @@ void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth,
const char *sgroup);
void ff_hls_write_playlist_header(AVIOContext *out, int version, int allowcache,
int target_duration, int64_t sequence,
uint32_t playlist_type, int iframe_mode);
uint32_t playlist_type, int iframe_mode, double start_offset);
void ff_hls_write_init_file(AVIOContext *out, const char *filename,
int byterange_mode, int64_t size, int64_t pos);
int ff_hls_write_file_entry(AVIOContext *out, int insert_discont,