127 if (!strcmp(str,
"mp4a") || !strcmp(str,
"mp4v")) {
136 if (tag ==
MKTAG(
'm',
'p',
'4',
'a')) {
143 }
else if (tag ==
MKTAG(
'm',
'p',
'4',
'v')) {
147 }
else if (!strcmp(str,
"avc1")) {
153 if (extradata[0] != 1) {
165 if (extradata_size >= 4)
167 extradata[1], extradata[2], extradata[3]);
197 int i, start_index = 0, start_number = 1;
205 avio_printf(out,
"\t\t\t\t<SegmentTemplate timescale=\"%d\" ", timescale);
216 if (i == start_index || seg->
time != cur_time) {
217 cur_time = seg->
time;
229 cur_time += (1 + repeat) * seg->
duration;
231 avio_printf(out,
"\t\t\t\t\t</SegmentTimeline>\n");
251 avio_printf(out,
"\t\t\t\t\t<SegmentURL media=\"%s\" />\n", seg->
file);
258 size_t format_tag_size,
const char **ptr) {
259 const char *next_ptr;
265 }
else if (
av_strstart(identifier,
"$RepresentationID$", &next_ptr)) {
269 av_strlcpy(format_tag,
"%d", format_tag_size);
274 else if (
av_strstart(identifier,
"$Bandwidth", &next_ptr))
276 else if (
av_strstart(identifier,
"$Time", &next_ptr))
285 if (next_ptr[0] ==
'$') {
286 snprintf(format_tag, format_tag_size,
"%%%s", number_format);
289 const char *width_ptr;
295 snprintf(format_tag, format_tag_size,
"%s%c%s",
"%0", width_ptr[0], number_format);
299 "closing '$' character or a format-string like '%%0[width]d', "
300 "where width must be a single digit\n", next_ptr);
310 const char *
template,
int rep_id,
311 int number,
int bit_rate,
314 const char *t_cur =
template;
315 while (dst_pos < buffer_size - 1 && *t_cur) {
319 const char *t_next = strchr(t_cur,
'$');
321 int num_copy_bytes =
FFMIN(t_next - t_cur, buffer_size - dst_pos - 1);
322 av_strlcpy(&dst[dst_pos], t_cur, num_copy_bytes + 1);
324 dst_pos += num_copy_bytes;
327 av_strlcpy(&dst[dst_pos], t_cur, buffer_size - dst_pos);
331 if (dst_pos >= buffer_size - 1 || !*t_cur)
342 n =
snprintf(&dst[dst_pos], buffer_size - dst_pos, format_tag, rep_id);
345 n =
snprintf(&dst[dst_pos], buffer_size - dst_pos, format_tag, number);
348 n =
snprintf(&dst[dst_pos], buffer_size - dst_pos, format_tag, bit_rate);
351 n =
snprintf(&dst[dst_pos], buffer_size - dst_pos, format_tag, time);
365 dst_pos +=
FFMIN(n, buffer_size - dst_pos - 1);
371 int outlen = strlen(str)*3/2 + 6;
376 for (; *str; str++) {
377 if (pos + 6 > outlen) {
379 outlen = 2 * outlen + 6;
388 memcpy(&out[pos],
"&", 5);
390 }
else if (*str ==
'<') {
391 memcpy(&out[pos],
"<", 4);
393 }
else if (*str ==
'>') {
394 memcpy(&out[pos],
">", 4);
396 }
else if (*str ==
'\'') {
397 memcpy(&out[pos],
"'", 6);
399 }
else if (*str ==
'\"') {
400 memcpy(&out[pos],
""", 6);
414 int minutes = seconds / 60;
415 int hours = minutes / 60;
421 if (hours || minutes)
430 char temp_filename[1024];
440 avio_printf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
441 avio_printf(out,
"<MPD xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
442 "\txmlns=\"urn:mpeg:dash:schema:mpd:2011\"\n"
443 "\txmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
444 "\txsi:schemaLocation=\"urn:mpeg:DASH:schema:MPD:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd\"\n"
445 "\tprofiles=\"urn:mpeg:dash:profile:isoff-live:2011\"\n"
446 "\ttype=\"%s\"\n",
final ?
"static" :
"dynamic");
448 avio_printf(out,
"\tmediaPresentationDuration=\"");
455 avio_printf(out,
"\tminimumUpdatePeriod=\"PT%"PRId64
"S\"\n", update_period);
458 time_t t = time(
NULL);
459 struct tm *ptm, tmbuf;
463 "%Y-%m-%dT%H:%M:%S", ptm))
481 avio_printf(out,
"\t\t<Title>%s</Title>\n", escaped);
497 avio_printf(out,
"\t\t<AdaptationSet id=\"video\" segmentAlignment=\"true\" bitstreamSwitching=\"true\">\n");
512 avio_printf(out,
"\t\t<AdaptationSet id=\"audio\" segmentAlignment=\"true\" bitstreamSwitching=\"true\">\n");
521 avio_printf(out,
"\t\t\t\t<AudioChannelConfiguration schemeIdUri=\"urn:mpeg:dash:23003:3:audio_channel_configuration:2011\" value=\"%d\" />\n", st->
codec->
channels);
548 ptr = strrchr(c->
dirname,
'/');
550 av_strlcpy(basename, &ptr[1],
sizeof(basename));
557 ptr = strrchr(basename,
'.');
589 av_log(s, level,
"No bit rate set for stream %d\n", i);
634 av_dict_set(&opts,
"movflags",
"frag_custom+dash+delay_moov", 0);
642 av_log(s,
AV_LOG_VERBOSE,
"Representation %d init segment will be written to: %s\n", i, filename);
676 int64_t start_pos, int64_t range_length,
677 int64_t index_length)
717 int64_t pos,
int *index_length)
736 *index_length =
AV_RB32(&buf[0]);
766 int cur_flush_segment_index = 0;
772 char filename[1024] =
"", full_path[1024], temp_path[1024];
774 int range_length, index_length = 0;
782 if (stream >= 0 && i != stream) {
805 snprintf(temp_path,
sizeof(temp_path),
"%s.tmp", full_path);
824 ret =
ff_rename(temp_path, full_path, s);
840 for (j = 0; j <
remove; j++) {
897 "Segment durations differ too much, enable use_timeline "
898 "and use_template, or keep a stricter keyframe interval\n");
956 #define OFFSET(x) offsetof(DASHContext, x)
957 #define E AV_OPT_FLAG_ENCODING_PARAM
959 {
"window_size",
"number of segments kept in the manifest",
OFFSET(window_size),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
E },
960 {
"extra_window_size",
"number of segments kept outside of the manifest before removing from disk",
OFFSET(extra_window_size),
AV_OPT_TYPE_INT, { .i64 = 5 }, 0, INT_MAX,
E },
961 {
"min_seg_duration",
"minimum segment duration (in microseconds)",
OFFSET(min_seg_duration),
AV_OPT_TYPE_INT64, { .i64 = 5000000 }, 0, INT_MAX,
E },
962 {
"remove_at_exit",
"remove all segments when finished",
OFFSET(remove_at_exit),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
E },
963 {
"use_template",
"Use SegmentTemplate instead of SegmentList",
OFFSET(use_template),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1,
E },
964 {
"use_timeline",
"Use SegmentTimeline in SegmentTemplate",
OFFSET(use_timeline),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1,
E },
965 {
"single_file",
"Store all segments in one file, accessed using byte ranges",
OFFSET(single_file),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
E },
966 {
"single_file_name",
"DASH-templated name to be used for baseURL. Implies storing all segments in one file, accessed using byte ranges",
OFFSET(single_file_name),
AV_OPT_TYPE_STRING, { .str =
NULL }, 0, 0,
E },
967 {
"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 },
968 {
"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 },