24#include "config_components.h"
48#if CONFIG_HTTP_PROTOCOL
72#define MPD_PROFILE_DASH 1
73#define MPD_PROFILE_DVB 2
74#define DASH_MAX_AVAILABILITY_START_TIME_MS (INT64_MAX / 1000)
75#define DASH_MAX_SUGGESTED_PRESENTATION_DELAY ((int64_t)INT_MAX * AV_TIME_BASE + AV_TIME_BASE - 1)
214 if (!*pb || !http_base_proto || !
c->http_persistent) {
216#if CONFIG_HTTP_PROTOCOL
235 if (!http_base_proto || !
c->http_persistent) {
237#if CONFIG_HTTP_PROTOCOL
249 switch (segment_type) {
262 default:
return NULL;
269 "Unable to open %s for writing: %s\n", url,
av_err2str(err));
270 return c->ignore_io_errors ? 0 : err;
290 int has_mp4_streams = 0;
291 for (
int i = 0;
i <
s->nb_streams; ++
i) {
294 c->segment_type_option,
s->streams[
i]->codecpar->codec_id);
310 if (
c->hls_playlist && !has_mp4_streams) {
330 if (!
c->single_file) {
354 if (
c->http_persistent)
361 const char *base_url,
int id) {
363 snprintf(playlist_name, string_size,
"%smedia_%d.m3u8", base_url,
id);
365 snprintf(playlist_name, string_size,
"media_%d.m3u8",
id);
369 int *start_index,
int *start_number) {
372 if (
c->window_size) {
379 int representation_id,
int final,
380 char *prefetch_url) {
383 char temp_filename_hls[1024];
384 char filename_hls[1024];
386 int target_duration = 0;
389 int use_rename = proto && !strcmp(proto,
"file");
390 int i, start_index, start_number;
391 double prog_date_time = 0;
395 if (!
c->hls_playlist || start_index >= os->
nb_segments ||
400 c->dirname, representation_id);
402 snprintf(temp_filename_hls,
sizeof(temp_filename_hls), use_rename ?
"%s.tmp" :
"%s", filename_hls);
427 if (
fabs(prog_date_time) < 1e-7) {
429 prog_date_time =
c->start_time_s;
436 (
double) seg->
duration / timescale, 0,
446 avio_printf(
c->m3u8_out,
"#EXT-X-PREFETCH:%s\n", prefetch_url);
460 int ret, range_length;
467 if (!
c->single_file) {
469 snprintf(filename,
sizeof(filename),
"%s%s",
c->dirname, os->
initfile);
481 for (
i = 0;
i <
c->nb_as;
i++) {
491 for (
i = 0;
i <
s->nb_streams;
i++) {
518 int representation_id,
int final)
521 int i, start_index, start_number;
524 if (
c->use_template) {
526 avio_printf(
out,
"\t\t\t\t<SegmentTemplate timescale=\"%d\" ", timescale);
527 if (!
c->use_timeline) {
537 if (
c->presentation_time_offset)
538 avio_printf(
out,
" presentationTimeOffset=\"%"PRId64
"\"",
c->presentation_time_offset);
540 if (
c->use_timeline) {
547 if (
i == start_index || seg->
time != cur_time) {
548 cur_time = seg->
time;
560 cur_time += (1 + repeat) * seg->
duration;
565 }
else if (
c->single_file) {
586 if (!
c->lhls ||
final) {
593 int outlen = strlen(str)*3/2 + 6;
598 for (; *str; str++) {
599 if (
pos + 6 > outlen) {
601 outlen = 2 * outlen + 6;
610 memcpy(&
out[
pos],
"&", 5);
612 }
else if (*str ==
'<') {
613 memcpy(&
out[
pos],
"<", 4);
615 }
else if (*str ==
'>') {
616 memcpy(&
out[
pos],
">", 4);
618 }
else if (*str ==
'\'') {
619 memcpy(&
out[
pos],
"'", 6);
621 }
else if (*str ==
'\"') {
622 memcpy(&
out[
pos],
""", 6);
636 int minutes = seconds / 60;
637 int hours = minutes / 60;
643 if (hours || minutes)
650 struct tm *ptm, tmbuf;
651 int64_t time_ms = time_us / 1000;
652 const time_t time_s = time_ms / 1000;
653 int millisec = time_ms - (time_s * 1000);
657 if (!strftime(buf,
size,
"%Y-%m-%dT%H:%M:%S", ptm)) {
662 snprintf(buf +
len,
size -
len,
".%03dZ", millisec);
674 avio_printf(
out,
"\t\t<AdaptationSet id=\"%d\" contentType=\"%s\" startWithSAP=\"1\" segmentAlignment=\"true\" bitstreamSwitching=\"true\"",
692 avio_printf(
out,
"\t\t\t<EssentialProperty id=\"%d\" schemeIdUri=\"http://dashif.org/guidelines/trickmode\" value=\"%d\"/>\n", as->
id, as->
trick_idx);
695 avio_printf(
out,
"\t\t\t<Role schemeIdUri=\"urn:mpeg:dash:role:2011\" value=\"%s\"/>\n", role->
value);
698 for (
i = 0;
i <
s->nb_streams;
i++) {
701 char bandwidth_str[64] = {
'\0'};
703 if (os->
as_idx - 1 != as_index)
707 snprintf(bandwidth_str,
sizeof(bandwidth_str),
" bandwidth=\"%d\"", os->
bit_rate);
709 int average_bit_rate = 0;
710 if (
c->total_duration > 0)
712 snprintf(bandwidth_str,
sizeof(bandwidth_str),
" bandwidth=\"%d\"", average_bit_rate);
717 avio_printf(
out,
"\t\t\t<Representation id=\"%d\" mimeType=\"video/%s\" codecs=\"%s\"%s width=\"%d\" height=\"%d\"",
735 avio_printf(
out,
"\t\t\t<Representation id=\"%d\" mimeType=\"audio/%s\" codecs=\"%s\"%s audioSamplingRate=\"%d\">\n",
737 avio_printf(
out,
"\t\t\t\t<AudioChannelConfiguration schemeIdUri=\"urn:mpeg:dash:23003:3:audio_channel_configuration:2011\" value=\"%d\" />\n",
738 s->streams[
i]->codecpar->ch_layout.nb_channels);
741 avio_printf(
out,
"\t\t\t\t<ProducerReferenceTime id=\"%d\" inband=\"true\" type=\"%s\" wallClockTime=\"%s\" presentationTime=\"%"PRId64
"\">\n",
743 avio_printf(
out,
"\t\t\t\t\t<UTCTiming schemeIdUri=\"urn:mpeg:dash:utc:http-xsdate:2014\" value=\"%s\"/>\n",
c->utc_timing_url);
772 *as = &
c->as[
c->nb_as - 1];
773 memset(*as, 0,
sizeof(**as));
774 (*as)->media_type =
type;
775 (*as)->frag_type = -1;
776 (*as)->trick_idx = -1;
787 if (as->
media_type !=
s->streams[
i]->codecpar->codec_type) {
788 av_log(
s,
AV_LOG_ERROR,
"Codec type of stream %d doesn't match AdaptationSet's media type\n",
i);
795 av_log(
s,
AV_LOG_ERROR,
"DVB-DASH profile allows a max of 16 Representations per Adaptation Set\n");
807 const char *p =
c->adaptation_sets;
808 enum { new_set, parse_default, parsing_streams, parse_seg_duration, parse_frag_duration }
state;
814 for (
i = 0;
i <
s->nb_streams;
i++) {
819 c->streams[
i].as_idx =
c->nb_as;
839 char id_str[10], *end_str;
842 snprintf(id_str,
sizeof(id_str),
"%.*s", n, p);
844 i = strtol(id_str, &end_str, 10);
857 state = parse_default;
859 state = parse_seg_duration;
861 state = parse_frag_duration;
862 }
else if (
state == parse_seg_duration ||
state == parse_frag_duration) {
867 snprintf(str,
sizeof(str),
"%.*s", n, p);
878 if (
state == parse_seg_duration)
882 state = parse_default;
887 snprintf(type_str,
sizeof(type_str),
"%.*s", n, p);
892 if (!strcmp(type_str,
"duration"))
894 else if (!strcmp(type_str,
"pframes"))
896 else if (!strcmp(type_str,
"every_frame"))
898 else if (!strcmp(type_str,
"none"))
901 av_log(
s,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as fragment type\n", type_str);
904 state = parse_default;
906 n = strcspn(p,
">") + 1;
910 av_log(
s,
AV_LOG_ERROR,
"Parse error, descriptor string should be a self-closing xml tag\n");
916 state = parse_default;
918 char trick_id_str[10], *end_str;
921 snprintf(trick_id_str,
sizeof(trick_id_str),
"%.*s", n, p);
924 as->
trick_idx = strtol(trick_id_str, &end_str, 10);
925 if (trick_id_str == end_str || as->
trick_idx < 0)
930 state = parse_default;
932 state = parsing_streams;
933 }
else if (
state == parsing_streams) {
935 char idx_str[8], *end_str;
937 n = strcspn(p,
" ,");
938 snprintf(idx_str,
sizeof(idx_str),
"%.*s", n, p);
946 for (
i = 0;
i <
s->nb_streams;
i++) {
947 if (
s->streams[
i]->codecpar->codec_type !=
type)
956 i = strtol(idx_str, &end_str, 10);
982 for (
i = 0;
i <
s->nb_streams;
i++) {
991 for (
i = 0;
i <
c->nb_as;
i++) {
995 for (n = 0; n <
c->nb_as; n++) {
1012 char temp_filename[1024];
1015 int use_rename = proto && !strcmp(proto,
"file");
1016 static unsigned int warned_non_file = 0;
1020 if (!use_rename && !warned_non_file++)
1021 av_log(
s,
AV_LOG_ERROR,
"Cannot use rename on non file protocol, this may lead to races and temporary partial files\n");
1023 snprintf(temp_filename,
sizeof(temp_filename), use_rename ?
"%s.tmp" :
"%s",
s->url);
1031 avio_printf(
out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
1032 avio_printf(
out,
"<MPD xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
1033 "\txmlns=\"urn:mpeg:dash:schema:mpd:2011\"\n"
1034 "\txmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
1035 "\txsi:schemaLocation=\"urn:mpeg:DASH:schema:MPD:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd\"\n"
1040 avio_printf(
out,
"%s",
"urn:dvb:dash:profile:dvb-dash:2014\"\n");
1042 final ?
"static" :
"dynamic");
1050 if (
c->use_template && !
c->use_timeline)
1051 update_period = 500;
1052 if (
c->update_period)
1053 update_period =
c->update_period;
1054 avio_printf(
out,
"\tminimumUpdatePeriod=\"PT%"PRId64
"S\"\n", update_period);
1056 if (
c->suggested_presentation_delay) {
1063 if (
c->availability_start_time[0])
1064 avio_printf(
out,
"\tavailabilityStartTime=\"%s\"\n",
c->availability_start_time);
1068 if (
c->window_size &&
c->use_template) {
1078 write_time(
out,
c->ldash &&
c->max_gop_size ?
c->max_gop_size :
c->last_duration * 2);
1089 if (!
final &&
c->target_latency &&
c->target_latency_refid >= 0) {
1090 avio_printf(
out,
"\t\t<Latency target=\"%"PRId64
"\"",
c->target_latency / 1000);
1091 if (
s->nb_streams > 1)
1097 avio_printf(
out,
"\t\t<PlaybackRate min=\"%.2f\" max=\"%.2f\"/>\n",
1101 if (
c->window_size &&
s->nb_streams > 0 &&
c->streams[0].nb_segments > 0 && !
c->use_template) {
1112 for (
i = 0;
i <
c->nb_as;
i++) {
1118 if (
c->utc_timing_url)
1119 avio_printf(
out,
"\t<UTCTiming schemeIdUri=\"urn:mpeg:dash:utc:http-xsdate:2014\" value=\"%s\"/>\n",
c->utc_timing_url);
1126 if ((ret =
ff_rename(temp_filename,
s->url,
s)) < 0)
1130 if (
c->hls_playlist) {
1131 char filename_hls[1024];
1134 if (
c->master_playlist_created && (!
c->master_publish_rate ||
1135 c->streams[0].segment_index %
c->master_publish_rate))
1139 snprintf(filename_hls,
sizeof(filename_hls),
"%s%s",
c->dirname,
c->hls_master_name);
1141 snprintf(filename_hls,
sizeof(filename_hls),
"%s",
c->hls_master_name);
1143 snprintf(temp_filename,
sizeof(temp_filename), use_rename ?
"%s.tmp" :
"%s", filename_hls);
1156 const char *audio_group =
"A1";
1157 char audio_codec_str[128] =
"\0";
1159 int max_audio_bitrate = 0;
1161 for (
i = 0;
i <
s->nb_streams;
i++) {
1162 char playlist_file[64];
1171 playlist_file,
NULL,
i, is_default,
1172 s->streams[
i]->codecpar->ch_layout.nb_channels);
1176 if (strlen(audio_codec_str))
1177 av_strlcat(audio_codec_str,
",",
sizeof(audio_codec_str));
1183 for (
i = 0;
i <
s->nb_streams;
i++) {
1184 char playlist_file[64];
1185 char codec_str[128];
1188 const char *agroup =
NULL;
1201 if (max_audio_bitrate) {
1202 agroup = audio_group;
1203 stream_bitrate += max_audio_bitrate;
1204 av_strlcat(codec_str,
",",
sizeof(codec_str));
1205 av_strlcat(codec_str, audio_codec_str,
sizeof(codec_str));
1209 playlist_file, agroup,
1216 for (
i = 0;
i <
s->nb_streams;
i++) {
1217 char playlist_file[64];
1218 char codec_str[128];
1235 playlist_file,
NULL,
1242 if ((ret =
ff_rename(temp_filename, filename_hls,
s)) < 0)
1244 c->master_playlist_created = 1;
1263 char basename[1024];
1265 c->nr_of_streams_to_flush = 0;
1266 if (
c->single_file_name)
1269 c->use_template = 0;
1277 "LHLS is experimental, Please set -strict experimental in order to enable it.\n");
1281 if (
c->lhls && !
c->streaming) {
1286 if (
c->lhls && !
c->hls_playlist) {
1288 c->hls_playlist = 1;
1291 if (
c->ldash && !
c->streaming) {
1296 if (
c->target_latency && !
c->streaming) {
1298 c->target_latency = 0;
1301 if (
c->global_sidx && !
c->single_file) {
1306 if (
c->global_sidx &&
c->streaming) {
1315 if (
c->write_prft < 0) {
1316 c->write_prft =
c->ldash;
1321 if (
c->write_prft && !
c->utc_timing_url) {
1322 av_log(
s,
AV_LOG_WARNING,
"Producer Reference Time element option will be ignored as utc_timing_url is not set\n");
1326 if (
c->write_prft && !
c->streaming) {
1327 av_log(
s,
AV_LOG_WARNING,
"Producer Reference Time element option will be ignored as streaming is not enabled\n");
1331 if (
c->ldash && !
c->write_prft) {
1332 av_log(
s,
AV_LOG_WARNING,
"Low Latency mode enabled without Producer Reference Time element option! Resulting manifest may not be complaint\n");
1335 if (
c->target_latency && !
c->write_prft) {
1336 av_log(
s,
AV_LOG_WARNING,
"Target latency option will be ignored as Producer Reference Time element will not be written\n");
1337 c->target_latency = 0;
1340 if (
av_cmp_q(
c->max_playback_rate,
c->min_playback_rate) < 0) {
1341 av_log(
s,
AV_LOG_WARNING,
"Minimum playback rate value is higher than the Maximum. Both will be ignored\n");
1342 c->min_playback_rate =
c->max_playback_rate = (
AVRational) {1, 1};
1346 ptr = strrchr(
c->dirname,
'/');
1348 av_strlcpy(basename, &ptr[1],
sizeof(basename));
1351 c->dirname[0] =
'\0';
1355 ptr = strrchr(basename,
'.');
1359 c->streams =
av_mallocz(
sizeof(*
c->streams) *
s->nb_streams);
1369 for (
i = 0;
i <
s->nb_streams;
i++) {
1375 char filename[1024];
1378 os->
bit_rate =
s->streams[
i]->codecpar->bit_rate;
1391 if (
c->init_seg_name) {
1396 if (
c->media_seg_name) {
1401 if (
c->single_file_name) {
1412 "One or many segment file names doesn't end with .webm. "
1413 "Override -init_seg_name and/or -media_seg_name and/or "
1414 "-single_file_name to end with the extension .webm\n");
1418 av_log(
s,
AV_LOG_WARNING,
"One or more streams in WebM output format. Streaming option will be ignored\n");
1430 ctx->interrupt_callback =
s->interrupt_callback;
1431 ctx->opaque =
s->opaque;
1432 ctx->io_close2 =
s->io_close2;
1433 ctx->io_open =
s->io_open;
1434 ctx->strict_std_compliance =
s->strict_std_compliance;
1442 ctx->avoid_negative_ts =
s->avoid_negative_ts;
1443 ctx->flags =
s->flags;
1457 if (
c->single_file) {
1465 snprintf(filename,
sizeof(filename),
"%s%s",
c->dirname, os->
initfile);
1467 if (!
c->single_file) {
1510 av_log(
s,
AV_LOG_WARNING,
"frag_type set to P-Frame reordering, but no parser found for stream %d\n",
i);
1556 s->avoid_negative_ts =
ctx->avoid_negative_ts;
1558 AVRational avg_frame_rate =
s->streams[
i]->avg_frame_rate;
1560 if (avg_frame_rate.
num > 0) {
1584 av_log(
s,
AV_LOG_ERROR,
"Conflicting stream aspect ratios values in Adaptation Set %d. Please ensure all adaptation sets have the same aspect ratio\n", os->
as_idx);
1600 c->nr_of_streams_to_flush++;
1603 if (!
c->has_video &&
c->seg_duration <= 0) {
1610 c->nr_of_streams_flushed = 0;
1611 c->target_latency_refid = -1;
1620 for (
i = 0;
i <
s->nb_streams;
i++) {
1638 int64_t index_length,
int next_exp_index)
1657 if (seg->
time < 0) {
1705 *index_length =
AV_RB32(&buf[0]);
1713 size_t extradata_size;
1721 if (!extradata_size)
1728 memcpy(par->
extradata, extradata, extradata_size);
1740 if (http_base_proto) {
1757 "failed to delete %s: %s\n", filename,
av_err2str(res));
1784 for (
int i = 0;
i < remove_count; ++
i) {
1801 int use_rename = proto && !strcmp(proto,
"file");
1803 int cur_flush_segment_index = 0, next_exp_index = -1;
1805 cur_flush_segment_index =
c->streams[stream].segment_index;
1808 if (
c->use_template && !
c->use_timeline &&
c->index_correction &&
1812 c->streams[stream].first_pts,
1813 s->streams[stream]->time_base,
1815 next_exp_index = (pts_diff /
c->streams[stream].seg_duration) + 1;
1819 for (
i = 0;
i <
s->nb_streams;
i++) {
1822 int range_length, index_length = 0;
1831 if (stream >= 0 &&
i != stream) {
1851 if (
c->single_file) {
1878 os->
pos += range_length;
1881 if (
c->window_size) {
1882 for (
i = 0;
i <
s->nb_streams;
i++) {
1884 int remove_count = os->
nb_segments -
c->window_size -
c->extra_window_size;
1885 if (remove_count > 0)
1891 for (
i = 0;
i <
s->nb_streams;
i++) {
1896 if (
c->global_sidx) {
1897 int j, start_index, start_number;
1914 if (
c->has_video && !
final) {
1915 c->nr_of_streams_flushed++;
1916 if (
c->nr_of_streams_flushed !=
c->nr_of_streams_to_flush)
1919 c->nr_of_streams_flushed = 0;
1923 if (!
c->streaming ||
final)
1933 size_t side_data_size;
1948 if (
c->target_latency_refid < 0)
1949 c->target_latency_refid =
pkt->stream_index;
1961 int64_t seg_end_duration, elapsed_duration;
1986 if (
c->write_prft) {
1997 if (!
c->availability_start_time[0]) {
1999 int64_t mpd_start_time_us =
c->availability_start_time_ms ?
2000 c->availability_start_time_ms * 1000 :
2002 c->start_time_s = start_time_us / 1000000;
2004 sizeof(
c->availability_start_time), mpd_start_time_us);
2030 if (
c->use_template && !
c->use_timeline) {
2066 "Segment durations differ too much, enable use_timeline "
2067 "and use_template, or keep a stricter keyframe interval\n");
2137 int use_rename = proto && !strcmp(proto,
"file");
2147 use_rename ?
"%s.tmp" :
"%s", os->
full_path);
2171 uint8_t *buf =
NULL;
2189 if (
s->nb_streams > 0) {
2193 if (!
c->last_duration)
2195 s->streams[0]->time_base,
2198 s->streams[0]->time_base,
2203 if (
c->remove_at_exit) {
2204 for (
i = 0;
i <
s->nb_streams; ++
i) {
2209 char filename[1024];
2216 if (
c->hls_playlist &&
c->master_playlist_created) {
2217 char filename[1024];
2218 snprintf(filename,
sizeof(filename),
"%s%s",
c->dirname,
c->hls_master_name);
2247#define OFFSET(x) offsetof(DASHContext, x)
2248#define E AV_OPT_FLAG_ENCODING_PARAM
2250 {
"adaptation_sets",
"Adaptation sets. Syntax: id=0,streams=0,1,2 id=1,streams=3,4 and so on",
OFFSET(adaptation_sets),
AV_OPT_TYPE_STRING, { 0 }, 0, 0,
AV_OPT_FLAG_ENCODING_PARAM },
2255 {
"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 },
2256 {
"format_options",
"set list of options for the container format (mp4/webm) used for dash",
OFFSET(format_options),
AV_OPT_TYPE_DICT, {.str =
NULL}, 0, 0,
E},
2257 {
"frag_duration",
"fragment duration (in seconds, fractional value can be set)",
OFFSET(frag_duration),
AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT_MAX,
E },
2262 {
"pframes",
"fragment at keyframes and following P-Frame reordering (Video only, experimental)", 0,
AV_OPT_TYPE_CONST, {.i64 =
FRAG_TYPE_PFRAMES }, 0, UINT_MAX,
E, .unit =
"frag_type"},
2263 {
"global_sidx",
"Write global SIDX atom. Applicable only for single file, mp4 output, non-streaming mode",
OFFSET(global_sidx),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
2264 {
"hls_master_name",
"HLS master playlist name",
OFFSET(hls_master_name),
AV_OPT_TYPE_STRING, {.str =
"master.m3u8"}, 0, 0,
E },
2265 {
"hls_playlist",
"Generate HLS playlist files(master.m3u8, media_%d.m3u8)",
OFFSET(hls_playlist),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
2267 {
"http_persistent",
"Use persistent HTTP connections",
OFFSET(http_persistent),
AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1,
E },
2269 {
"ignore_io_errors",
"Ignore IO errors during open and write. Useful for long-duration runs with network output",
OFFSET(ignore_io_errors),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
2270 {
"index_correction",
"Enable/Disable segment index correction logic",
OFFSET(index_correction),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
2271 {
"init_seg_name",
"DASH-templated name to used for the initialization segment",
OFFSET(init_seg_name),
AV_OPT_TYPE_STRING, {.str =
"init-stream$RepresentationID$.$ext$"}, 0, 0,
E },
2272 {
"ldash",
"Enable Low-latency dash. Constrains the value of a few elements",
OFFSET(ldash),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
2273 {
"lhls",
"Enable Low-latency HLS(Experimental). Adds #EXT-X-PREFETCH tag with current segment's URI",
OFFSET(lhls),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
2274 {
"master_m3u8_publish_rate",
"Publish master playlist every after this many segment intervals",
OFFSET(master_publish_rate),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, UINT_MAX,
E},
2275 {
"max_playback_rate",
"Set desired maximum playback rate",
OFFSET(max_playback_rate),
AV_OPT_TYPE_RATIONAL, { .dbl = 1.0 }, 0.5, 1.5,
E },
2276 {
"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$.$ext$"}, 0, 0,
E },
2278 {
"min_playback_rate",
"Set desired minimum playback rate",
OFFSET(min_playback_rate),
AV_OPT_TYPE_RATIONAL, { .dbl = 1.0 }, 0.5, 1.5,
E },
2282 {
"remove_at_exit",
"remove all segments when finished",
OFFSET(remove_at_exit),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
2283 {
"seg_duration",
"segment duration (in seconds, fractional value can be set)",
OFFSET(seg_duration),
AV_OPT_TYPE_DURATION, { .i64 = 5000000 }, 0, INT_MAX,
E },
2284 {
"single_file",
"Store all segments in one file, accessed using byte ranges",
OFFSET(single_file),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
2285 {
"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 },
2287 {
"streaming",
"Enable/Disable streaming mode of output. Each frame will be moof fragment",
OFFSET(streaming),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
2289 {
"target_latency",
"Set desired target latency for Low-latency dash",
OFFSET(target_latency),
AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT_MAX,
E },
2290 {
"timeout",
"set timeout for socket I/O operations",
OFFSET(timeout),
AV_OPT_TYPE_DURATION, { .i64 = -1 }, -1, INT_MAX, .flags =
E },
2291 {
"update_period",
"Set the mpd update interval",
OFFSET(update_period),
AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX,
E},
2292 {
"use_template",
"Use SegmentTemplate instead of SegmentList",
OFFSET(use_template),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
E },
2293 {
"use_timeline",
"Use SegmentTimeline in SegmentTemplate",
OFFSET(use_timeline),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
E },
2294 {
"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 },
2295 {
"window_size",
"number of segments kept in the manifest",
OFFSET(window_size),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
E },
2296 {
"write_prft",
"Write producer reference time element",
OFFSET(write_prft),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
E},
2301 .class_name =
"dash muxer",
2310 .p.extensions =
"mpd",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static AVFormatContext * ctx
static AVDictionary * opts
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define PARSER_FLAG_COMPLETE_FRAMES
int ffurl_shutdown(URLContext *h, int flags)
Signal the URLContext that we are done reading or writing the stream.
URLContext * ffio_geturlcontext(AVIOContext *s)
Return the URLContext associated with the AVIOContext.
int ffurl_delete(const char *url)
Delete a resource.
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
int ff_rename(const char *url_src, const char *url_dst, void *logctx)
Wrap ffurl_move() and log if error happens.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
void avio_wb32(AVIOContext *s, unsigned int val)
#define AVIO_FLAG_READ
read-only
#define AVIO_FLAG_WRITE
write-only
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
Convenience header that includes libavutil's core.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_UNLIMITED
#define i(width, name, range_min, range_max)
static void deinit(AVFormatContext *s)
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
int ff_make_codec_str(void *logctx, const AVCodecParameters *par, const AVRational *frame_rate, struct AVBPrint *out)
Make a RFC 4281/6381 like string describing a codec.
static __device__ float fabs(float a)
void ff_dash_fill_tmpl_params(char *dst, size_t buffer_size, const char *template, int rep_id, int number, int bit_rate, int64_t time)
static const AVClass dash_class
static void write_time(AVIOContext *out, int64_t time)
static int dict_copy_entry(AVDictionary **dst, const AVDictionary *src, const char *key)
#define DASH_MAX_SUGGESTED_PRESENTATION_DELAY
static const char * get_extension_str(SegmentType type, int single_file)
static int dash_parse_prft(DASHContext *c, AVPacket *pkt)
static int init_segment_types(AVFormatContext *s)
static void get_start_index_number(OutputStream *os, DASHContext *c, int *start_index, int *start_number)
static int update_stream_extradata(AVFormatContext *s, OutputStream *os, AVPacket *pkt, AVRational *frame_rate)
static void dash_free(AVFormatContext *s)
#define DASH_MAX_AVAILABILITY_START_TIME_MS
static int dashenc_delete_segment_file(AVFormatContext *s, const char *file)
static int dash_flush(AVFormatContext *s, int final, int stream)
static void dashenc_io_close(AVFormatContext *s, AVIOContext **pb, char *filename)
static int dash_init(AVFormatContext *s)
static int dashenc_io_open(AVFormatContext *s, AVIOContext **pb, char *filename, AVDictionary **options)
static int add_adaptation_set(AVFormatContext *s, AdaptationSet **as, enum AVMediaType type)
static void output_segment_list(OutputStream *os, AVIOContext *out, AVFormatContext *s, int representation_id, int final)
static void dashenc_delete_media_segments(AVFormatContext *s, OutputStream *os, int remove_count)
static char * xmlescape(const char *str)
static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
static int flush_dynbuf(DASHContext *c, OutputStream *os, int *range_length)
static void get_hls_playlist_name(char *playlist_name, int string_size, const char *base_url, int id)
static void find_index_range(AVFormatContext *s, const char *full_path, int64_t pos, int *index_length)
static int parse_adaptation_sets(AVFormatContext *s)
static void write_hls_media_playlist(OutputStream *os, AVFormatContext *s, int representation_id, int final, char *prefetch_url)
static void write_styp(AVIOContext *pb)
static int dash_write_header(AVFormatContext *s)
static int add_segment(OutputStream *os, const char *file, int64_t time, int64_t duration, int64_t start_pos, int64_t range_length, int64_t index_length, int next_exp_index)
static int dash_check_bitstream(AVFormatContext *s, AVStream *st, const AVPacket *avpkt)
static int handle_io_open_error(AVFormatContext *s, int err, char *url)
static void set_http_options(AVDictionary **options, DASHContext *c)
static int dash_write_trailer(AVFormatContext *s)
static const char * get_format_str(SegmentType segment_type)
static void format_date(char *buf, int size, int64_t time_us)
static void dashenc_delete_file(AVFormatContext *s, char *filename)
static int adaptation_set_add_stream(AVFormatContext *s, int as_idx, int i)
static SegmentType select_segment_type(SegmentType segment_type, enum AVCodecID codec_id)
static int write_manifest(AVFormatContext *s, int final)
static int write_adaptation_set(AVFormatContext *s, AVIOContext *out, int as_index, int final)
static int flush_init_segment(AVFormatContext *s, OutputStream *os)
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
#define FF_COMPLIANCE_STRICT
Strictly conform to all the things in the spec no matter what consequences.
int(* init)(AVBSFContext *ctx)
static struct @346255127015250356166251341105367306144006377143 state
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
static int64_t start_time
static void write_header(FFV1Context *f)
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
@ AV_OPT_TYPE_RATIONAL
Underlying C type is AVRational.
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
AVCodecID
Identify the syntax and semantics of the bitstream.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
@ AV_PKT_DATA_PRFT
Producer Reference Time data corresponding to the AVProducerReferenceTime struct, usually exported by...
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
AVCodecParserContext * av_parser_init(enum AVCodecID codec_id)
void av_parser_close(AVCodecParserContext *s)
int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int64_t pts, int64_t dts, int64_t pos)
Parse a packet.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
av_warn_unused_result int avformat_init_output(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and initialize the codec, but do not write the header.
av_warn_unused_result int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
const AVOutputFormat * av_guess_format(const char *short_name, const char *filename, const char *mime_type)
Return the output format in the list of registered output formats which best matches the provided par...
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file.
int av_match_ext(const char *filename, const char *extensions)
Return a positive value if the given filename has one of the given extensions, 0 otherwise.
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_init_for_buffer(AVBPrint *buf, char *buffer, unsigned size)
Init a print buffer using a pre-existing buffer.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
#define AV_DICT_APPEND
If the entry already exists, append to it.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it.
#define AVERROR_MUXER_NOT_FOUND
Muxer not found.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare two timestamps each in its own time base.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
char * av_strndup(const char *s, size_t len)
Duplicate a substring of a string.
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes,...
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
char * av_strnstr(const char *haystack, const char *needle, size_t hay_length)
Locate the first occurrence of the string needle in the string haystack where not more than hay_lengt...
char * av_strireplace(const char *str, const char *from, const char *to)
Locale-independent strings replace.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE
Internal time base represented as integer.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
#define LIBAVUTIL_VERSION_INT
void ff_hls_write_playlist_version(AVIOContext *out, int version)
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)
void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, const char *filename, const char *language, int name_id, int is_default, int nb_channels)
void ff_hls_write_init_file(AVIOContext *out, const char *filename, int byterange_mode, int64_t size, int64_t pos)
void ff_hls_write_end_list(AVIOContext *out)
int ff_hls_write_file_entry(AVIOContext *out, int insert_discont, int byterange_mode, double duration, int round_duration, int64_t size, int64_t pos, const char *baseurl, const char *filename, double *prog_date_time, int iframe_mode)
void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth, int avg_bandwidth, const char *filename, const char *agroup, const char *codecs, const char *ccgroup, const char *sgroup)
int ff_http_do_new_request(URLContext *h, const char *uri)
Send a new HTTP request, reusing the old connection.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define MKTAG(a, b, c, d)
Memory handling functions.
static const FFOutputFormat * ffofmt(const AVOutputFormat *fmt)
miscellaneous OS support macros and functions.
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
Utilities for rational number calculation.
Describe the class of an AVClass context structure.
main external API structure.
This struct describes the properties of an encoded stream.
int extradata_size
Size of the extradata content in bytes.
enum AVFieldOrder field_order
The order of the fields in interlaced video.
int height
The height of the video frame in pixels.
int width
The width of the video frame in pixels.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
enum AVMediaType codec_type
General type of the encoded data.
int video_delay
Number of delayed frames.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
AVIOContext * pb
I/O context.
const struct AVOutputFormat * oformat
The output container format.
AVStream ** streams
A list of all streams in the file.
This structure stores compressed data.
This structure supplies correlation between a packet timestamp and a wall clock production time.
int64_t wallclock
A UTC timestamp, in microseconds, since Unix epoch (e.g, av_gettime()).
Rational number (pair of numerator and denominator).
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int index
stream index in AVFormatContext
AVRational avg_frame_rate
Average framerate.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
AVRational min_frame_rate
enum AVMediaType media_type
int64_t max_frag_duration
AVRational max_frame_rate
const char * utc_timing_url
const char * single_file_name
int64_t max_segment_duration
AVIOContext * http_delete
int64_t suggested_presentation_delay
AVRational min_playback_rate
const char * init_seg_name
int64_t presentation_time_offset
int64_t availability_start_time_ms
int nr_of_streams_flushed
int master_playlist_created
const char * media_seg_name
int nr_of_streams_to_flush
SegmentType segment_type_option
AVDictionary * format_options
int64_t availability_start_time
AVRational max_playback_rate
const char * hls_master_name
struct AVBSFContext * bsfc
bitstream filter to run on stream
AVCodecParserContext * parser
const char * init_seg_name
const char * media_seg_name
atomic_uint_least64_t packets_written
int first_segment_bit_rate
char producer_reference_time_str[100]
const char * extension_name
double availability_time_offset
int64_t total_pkt_duration
const char * single_file_name
AVCodecContext * parser_avctx
AVProducerReferenceTime producer_reference_time
int64_t av_gettime(void)
Get the current time in microseconds.
unbuffered private I/O API
static int write_trailer(AVFormatContext *s1)