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) {
166 if (extradata_size >= 4)
168 extradata[1], extradata[2], extradata[3]);
198 int i, start_index = 0, start_number = 1;
206 avio_printf(out,
"\t\t\t\t<SegmentTemplate timescale=\"%d\" ", timescale);
216 if (i == start_index)
226 avio_printf(out,
"\t\t\t\t\t</SegmentTimeline>\n");
246 avio_printf(out,
"\t\t\t\t\t<SegmentURL media=\"%s\" />\n", seg->
file);
253 size_t format_tag_size,
const char **ptr) {
254 const char *next_ptr;
260 }
else if (
av_strstart(identifier,
"$RepresentationID$", &next_ptr)) {
264 av_strlcpy(format_tag,
"%d", format_tag_size);
269 else if (
av_strstart(identifier,
"$Bandwidth", &next_ptr))
271 else if (
av_strstart(identifier,
"$Time", &next_ptr))
280 if (next_ptr[0] ==
'$') {
281 snprintf(format_tag, format_tag_size,
"%%%s", number_format);
284 const char *width_ptr;
290 snprintf(format_tag, format_tag_size,
"%s%c%s",
"%0", width_ptr[0], number_format);
294 "closing '$' character or a format-string like '%%0[width]d', "
295 "where width must be a single digit\n", next_ptr);
305 const char *
template,
int rep_id,
306 int number,
int bit_rate,
309 const char *t_cur =
template;
310 while (dst_pos < buffer_size - 1 && *t_cur) {
314 const char *t_next = strchr(t_cur,
'$');
316 int num_copy_bytes =
FFMIN(t_next - t_cur, buffer_size - dst_pos - 1);
317 av_strlcpy(&dst[dst_pos], t_cur, num_copy_bytes + 1);
319 dst_pos += num_copy_bytes;
322 av_strlcpy(&dst[dst_pos], t_cur, buffer_size - dst_pos);
326 if (dst_pos >= buffer_size - 1 || !*t_cur)
337 n =
snprintf(&dst[dst_pos], buffer_size - dst_pos, format_tag, rep_id);
340 n =
snprintf(&dst[dst_pos], buffer_size - dst_pos, format_tag, number);
343 n =
snprintf(&dst[dst_pos], buffer_size - dst_pos, format_tag, bit_rate);
346 n =
snprintf(&dst[dst_pos], buffer_size - dst_pos, format_tag, time);
360 dst_pos +=
FFMIN(n, buffer_size - dst_pos - 1);
366 int outlen = strlen(str)*3/2 + 6;
371 for (; *str; str++) {
372 if (pos + 6 > outlen) {
374 outlen = 2 * outlen + 6;
383 memcpy(&out[pos],
"&", 5);
385 }
else if (*str ==
'<') {
386 memcpy(&out[pos],
"<", 4);
388 }
else if (*str ==
'>') {
389 memcpy(&out[pos],
">", 4);
391 }
else if (*str ==
'\'') {
392 memcpy(&out[pos],
"'", 6);
394 }
else if (*str ==
'\"') {
395 memcpy(&out[pos],
""", 6);
409 int minutes = seconds / 60;
410 int hours = minutes / 60;
416 if (hours || minutes)
425 char temp_filename[1024];
435 avio_printf(out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
436 avio_printf(out,
"<MPD xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
437 "\txmlns=\"urn:mpeg:dash:schema:mpd:2011\"\n"
438 "\txmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
439 "\txsi:schemaLocation=\"urn:mpeg:DASH:schema:MPD:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd\"\n"
440 "\tprofiles=\"urn:mpeg:dash:profile:isoff-live:2011\"\n"
441 "\ttype=\"%s\"\n",
final ?
"static" :
"dynamic");
443 avio_printf(out,
"\tmediaPresentationDuration=\"");
450 avio_printf(out,
"\tminimumUpdatePeriod=\"PT%dS\"\n", update_period);
453 time_t t = time(NULL);
454 struct tm *ptm, tmbuf;
458 "%Y-%m-%dT%H:%M:%S", ptm))
476 avio_printf(out,
"\t\t<Title>%s</Title>\n", escaped);
492 avio_printf(out,
"\t\t<AdaptationSet id=\"video\" segmentAlignment=\"true\" bitstreamSwitching=\"true\">\n");
505 avio_printf(out,
"\t\t<AdaptationSet id=\"audio\" segmentAlignment=\"true\" bitstreamSwitching=\"true\">\n");
512 avio_printf(out,
"\t\t\t\t<AudioChannelConfiguration schemeIdUri=\"urn:mpeg:dash:23003:3:audio_channel_configuration:2011\" value=\"%d\" />\n", st->
codec->
channels);
539 ptr = strrchr(c->
dirname,
'/');
541 av_strlcpy(basename, &ptr[1],
sizeof(basename));
548 ptr = strrchr(basename,
'.');
580 av_log(s, level,
"No bit rate set for stream %d\n", i);
625 av_dict_set(&opts,
"movflags",
"frag_custom+dash", 0);
669 int64_t start_pos, int64_t range_length,
670 int64_t index_length)
708 const char *filename, int64_t pos,
711 char full_path[1024];
716 snprintf(full_path,
sizeof(full_path),
"%s%s", dirname, filename);
730 *index_length =
AV_RB32(&buf[0]);
737 int cur_flush_segment_index = 0;
743 char filename[1024] =
"", full_path[1024], temp_path[1024];
745 int range_length, index_length = 0;
753 if (stream >= 0 && i != stream) {
765 snprintf(temp_path,
sizeof(temp_path),
"%s.tmp", full_path);
781 ret =
ff_rename(temp_path, full_path, s);
796 for (j = 0; j <
remove; j++) {
849 "Segment durations differ too much, enable use_timeline "
850 "and use_template, or keep a stricter keyframe interval\n");
898 #define OFFSET(x) offsetof(DASHContext, x)
899 #define E AV_OPT_FLAG_ENCODING_PARAM
901 {
"window_size",
"number of segments kept in the manifest",
OFFSET(window_size),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
E },
902 {
"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 },
903 {
"min_seg_duration",
"minimum segment duration (in microseconds)",
OFFSET(min_seg_duration),
AV_OPT_TYPE_INT64, { .i64 = 5000000 }, 0, INT_MAX,
E },
904 {
"remove_at_exit",
"remove all segments when finished",
OFFSET(remove_at_exit),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
E },
905 {
"use_template",
"Use SegmentTemplate instead of SegmentList",
OFFSET(use_template),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1,
E },
906 {
"use_timeline",
"Use SegmentTimeline in SegmentTemplate",
OFFSET(use_timeline),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1,
E },
907 {
"single_file",
"Store all segments in one file, accessed using byte ranges",
OFFSET(single_file),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
E },
908 {
"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 },
909 {
"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 },
910 {
"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 },