Skip to content
Snippets Groups Projects
Commit 33cffd5e authored by Auri's avatar Auri
Browse files

skip_to_segment

parent 80154b1b
No related branches found
No related tags found
No related merge requests found
......@@ -100,6 +100,7 @@ typedef struct DASHContext {
AVRational min_frame_rate, max_frame_rate;
int ambiguous_frame_rate;
const char *utc_timing_url;
int skip_to_segment;
} DASHContext;
static struct codec_string {
......@@ -780,7 +781,10 @@ static int dash_init(AVFormatContext *s)
os->init_start_pos = 0;
if (!strcmp(os->format_name, "mp4")) {
av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov", 0);
if (c->skip_to_segment > 1)
av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov+frag_discont", 0);
else
av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov", 0);
} else {
dict_set_int(&opts, "cluster_time_limit", c->min_seg_duration / 1000, 0);
dict_set_int(&opts, "cluster_size_limit", 5 * 1024 * 1024, 0); // set a large cluster size limit
......@@ -793,6 +797,9 @@ static int dash_init(AVFormatContext *s)
av_log(s, AV_LOG_VERBOSE, "Representation %d init segment will be written to: %s\n", i, filename);
if (c->skip_to_segment > 1)
av_opt_set_int(os->ctx, "fragments", c->skip_to_segment, AV_OPT_SEARCH_CHILDREN);
// Flush init segment
// except for mp4, since delay_moov is set and the init segment
// is then flushed after the first packets
......@@ -822,7 +829,7 @@ static int dash_init(AVFormatContext *s)
os->first_pts = AV_NOPTS_VALUE;
os->max_pts = AV_NOPTS_VALUE;
os->last_dts = AV_NOPTS_VALUE;
os->segment_index = 1;
os->segment_index = c->skip_to_segment;
}
if (!c->has_video && c->min_seg_duration <= 0) {
......@@ -1050,6 +1057,12 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
DASHContext *c = s->priv_data;
AVStream *st = s->streams[pkt->stream_index];
OutputStream *os = &c->streams[pkt->stream_index];
int64_t seg_end_duration = (os->segment_index - c->skip_to_segment + 1) * (int64_t) c->min_seg_duration;
/* av_log(s, AV_LOG_WARNING, "segment_index=%d\n", os->segment_index); */
/* av_log(s, AV_LOG_WARNING, "min_seg_duration=%d\n", c->min_seg_duration); */
/* av_log(s, AV_LOG_WARNING, "seg_end_duration=%d\n", seg_end_duration); */
int ret;
ret = update_stream_extradata(s, os, st->codecpar);
......@@ -1080,7 +1093,7 @@ static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
if ((!c->has_video || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
pkt->flags & AV_PKT_FLAG_KEY && os->packets_written &&
av_compare_ts(pkt->pts - os->start_pts, st->time_base,
c->min_seg_duration, AV_TIME_BASE_Q) >= 0) {
seg_end_duration, AV_TIME_BASE_Q) >= 0) {
int64_t prev_duration = c->last_duration;
c->last_duration = av_rescale_q(pkt->pts - os->start_pts,
......@@ -1190,6 +1203,7 @@ static const AVOption options[] = {
{ "init_seg_name", "DASH-templated name to used for the initialization segment", OFFSET(init_seg_name), AV_OPT_TYPE_STRING, {.str = "init-stream$RepresentationID$.m4s"}, 0, 0, E },
{ "media_seg_name", "DASH-templated name to used for the media segments", OFFSET(media_seg_name), AV_OPT_TYPE_STRING, {.str = "chunk-stream$RepresentationID$-$Number%05d$.m4s"}, 0, 0, E },
{ "utc_timing_url", "URL of the page that will return the UTC timestamp in ISO format", OFFSET(utc_timing_url), AV_OPT_TYPE_STRING, { 0 }, 0, 0, E },
{ "skip_to_segment", "first segment number to actually write", OFFSET(skip_to_segment), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, INT_MAX, E },
{ NULL },
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment