char iv_string[KEYSIZE*2 + 1];
struct HLSSegment *next;
+ double discont_program_date_time;
} HLSSegment;
typedef enum HLSFlags {
unsigned var_stream_idx;
unsigned number;
int64_t sequence;
- ff_const59 AVOutputFormat *oformat;
- ff_const59 AVOutputFormat *vtt_oformat;
+ const AVOutputFormat *oformat;
+ const AVOutputFormat *vtt_oformat;
AVIOContext *out;
AVIOContext *out_single_file;
int packets_written;
int64_t start_sequence;
uint32_t start_sequence_source_type; // enum StartSequenceSourceType
- float time; // Set by a private option.
- float init_time; // Set by a private option.
+ int64_t time; // Set by a private option.
+ int64_t init_time; // Set by a private option.
int max_nb_segments; // Set by a private option.
int hls_delete_threshold; // Set by a private option.
#if FF_API_HLS_WRAP
int has_video_m3u8; /* has video stream m3u8 list */
} HLSContext;
+static int strftime_expand(const char *fmt, char **dest)
+{
+ int r = 1;
+ time_t now0;
+ struct tm *tm, tmpbuf;
+ char *buf;
+
+ buf = av_mallocz(MAX_URL_SIZE);
+ if (!buf)
+ return AVERROR(ENOMEM);
+
+ time(&now0);
+ tm = localtime_r(&now0, &tmpbuf);
+ r = strftime(buf, MAX_URL_SIZE, fmt, tm);
+ if (!r) {
+ av_free(buf);
+ return AVERROR(EINVAL);
+ }
+ *dest = buf;
+
+ return r;
+}
+
static int hlsenc_io_open(AVFormatContext *s, AVIOContext **pb, char *filename,
AVDictionary **options)
{
/* check the boundary of data which from current position is small than extradata_size */
while (data && (data - st->codecpar->extradata + 19) < st->codecpar->extradata_size) {
/* get HEVC SPS NAL and seek to profile_tier_level */
- if (!(data[0] | data[1] | data[2]) && data[3] == 1 && ((data[4] & 0x42) == 0x42)) {
+ if (!(data[0] | data[1] | data[2]) && data[3] == 1 && ((data[4] & 0x7E) == 0x42)) {
uint8_t *rbsp_buf;
int remain_size = 0;
int rbsp_size = 0;
en->keyframe_size = vs->video_keyframe_size;
en->next = NULL;
en->discont = 0;
+ en->discont_program_date_time = 0;
if (vs->discontinuity) {
en->discont = 1;
if (hls->max_nb_segments && vs->nb_entries >= hls->max_nb_segments) {
en = vs->segments;
- vs->initial_prog_date_time += en->duration;
+ if (!en->next->discont_program_date_time && !en->discont_program_date_time)
+ vs->initial_prog_date_time += en->duration;
vs->segments = en->next;
if (en && hls->flags & HLS_DELETE_SEGMENTS &&
#if FF_API_HLS_WRAP
char line[MAX_URL_SIZE];
const char *ptr;
const char *end;
+ double discont_program_date_time = 0;
if ((ret = ffio_open_whitelist(&in, url, AVIO_FLAG_READ,
&s->interrupt_callback, NULL,
av_strlcpy(vs->iv_string, ptr, sizeof(vs->iv_string));
}
}
+ } else if (av_strstart(line, "#EXT-X-PROGRAM-DATE-TIME:", &ptr)) {
+ struct tm program_date_time;
+ int y,M,d,h,m,s;
+ double ms;
+ if (sscanf(ptr, "%d-%d-%dT%d:%d:%d.%lf", &y, &M, &d, &h, &m, &s, &ms) != 7) {
+ ret = AVERROR_INVALIDDATA;
+ goto fail;
+ }
+ program_date_time.tm_year = y - 1900;
+ program_date_time.tm_mon = M - 1;
+ program_date_time.tm_mday = d;
+ program_date_time.tm_hour = h;
+ program_date_time.tm_min = m;
+ program_date_time.tm_sec = s;
+ program_date_time.tm_isdst = -1;
+
+ discont_program_date_time = mktime(&program_date_time);
+ discont_program_date_time += (double)(ms / 1000);
} else if (av_strstart(line, "#", NULL)) {
continue;
} else if (line[0]) {
is_segment = 0;
new_start_pos = avio_tell(vs->avf->pb);
vs->size = new_start_pos - vs->start_pos;
- vs->initial_prog_date_time -= vs->duration; // this is a previously existing segment
ret = hls_append_segment(s, hls, vs, vs->duration, vs->start_pos, vs->size);
+ vs->last_segment->discont_program_date_time = discont_program_date_time;
+ discont_program_date_time += vs->duration;
if (ret < 0)
goto fail;
vs->start_pos = new_start_pos;
sequence = 0;
}
+ if (hls->flags & HLS_I_FRAMES_ONLY) {
+ hls->version = 4;
+ }
+
if (hls->flags & HLS_INDEPENDENT_SEGMENTS) {
hls->version = 6;
}
ret = ff_hls_write_file_entry(byterange_mode ? hls->m3u8_out : vs->out, en->discont, byterange_mode,
en->duration, hls->flags & HLS_ROUND_DURATIONS,
en->size, en->pos, hls->baseurl,
- en->filename, prog_date_time_p, en->keyframe_size, en->keyframe_pos, hls->flags & HLS_I_FRAMES_ONLY);
+ 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);
+ if (en->discont_program_date_time)
+ en->discont_program_date_time -= en->duration;
if (ret < 0) {
av_log(s, AV_LOG_WARNING, "ff_hls_write_file_entry get error\n");
}
ff_format_set_url(oc, filename);
} else {
if (c->use_localtime) {
- time_t now0;
- struct tm *tm, tmpbuf;
- int bufsize = strlen(vs->basename) + MAX_URL_SIZE;
- char *buf = av_mallocz(bufsize);
- if (!buf)
- return AVERROR(ENOMEM);
- time(&now0);
- tm = localtime_r(&now0, &tmpbuf);
- ff_format_set_url(oc, buf);
- if (!strftime(oc->url, bufsize, vs->basename, tm)) {
+ int r;
+ char *expanded = NULL;
+
+ r = strftime_expand(vs->basename, &expanded);
+ if (r < 0) {
av_log(oc, AV_LOG_ERROR, "Could not get segment filename with strftime\n");
- return AVERROR(EINVAL);
+ return r;
}
+ ff_format_set_url(oc, expanded);
err = sls_flag_use_localtime_filename(oc, c, vs);
if (err < 0) {
if (vs->sequence - vs->nb_entries > hls->start_sequence && hls->init_time > 0) {
/* reset end_pts, hls->recording_time at end of the init hls list */
- int64_t init_list_dur = hls->init_time * vs->nb_entries * AV_TIME_BASE;
- int64_t after_init_list_dur = (vs->sequence - hls->start_sequence - vs->nb_entries) * (hls->time * AV_TIME_BASE);
- hls->recording_time = hls->time * AV_TIME_BASE;
+ int64_t init_list_dur = hls->init_time * vs->nb_entries;
+ int64_t after_init_list_dur = (vs->sequence - hls->start_sequence - vs->nb_entries) * hls->time;
+ hls->recording_time = hls->time;
end_pts = init_list_dur + after_init_list_dur ;
}
av_log(hls, AV_LOG_DEBUG, "start_number evaluated to %"PRId64"\n", hls->start_sequence);
}
- hls->recording_time = (hls->init_time ? hls->init_time : hls->time) * AV_TIME_BASE;
+ hls->recording_time = hls->init_time ? hls->init_time : hls->time;
if (hls->flags & HLS_SPLIT_BY_TIME && hls->flags & HLS_INDEPENDENT_SEGMENTS) {
// Independent segments cannot be guaranteed when splitting by time
return ret;
}
+ if (hls->use_localtime) {
+ int r;
+ char *expanded = NULL;
+
+ r = strftime_expand(vs->fmp4_init_filename, &expanded);
+ if (r < 0) {
+ av_log(s, AV_LOG_ERROR, "Could not get segment filename with strftime\n");
+ return r;
+ }
+ av_free(vs->fmp4_init_filename);
+ vs->fmp4_init_filename = expanded;
+ }
+
p = strrchr(vs->m3u8_name, '/');
if (p) {
char tmp = *(++p);
av_log(s, AV_LOG_WARNING, "append_list mode does not support hls_init_time,"
" hls_init_time value will have no effect\n");
hls->init_time = 0;
- hls->recording_time = hls->time * AV_TIME_BASE;
+ hls->recording_time = hls->time;
}
}
#define E AV_OPT_FLAG_ENCODING_PARAM
static const AVOption options[] = {
{"start_number", "set first number in the sequence", OFFSET(start_sequence),AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, E},
- {"hls_time", "set segment length in seconds", OFFSET(time), AV_OPT_TYPE_FLOAT, {.dbl = 2}, 0, FLT_MAX, E},
- {"hls_init_time", "set segment length in seconds at init list", OFFSET(init_time), AV_OPT_TYPE_FLOAT, {.dbl = 0}, 0, FLT_MAX, E},
+ {"hls_time", "set segment length", OFFSET(time), AV_OPT_TYPE_DURATION, {.i64 = 2000000}, 0, INT64_MAX, E},
+ {"hls_init_time", "set segment length at init list", OFFSET(init_time), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX, E},
{"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_ts_options","set hls mpegts list of options for the container format used for hls", OFFSET(format_options), AV_OPT_TYPE_DICT, {.str = NULL}, 0, 0, E},