Go to the documentation of this file.
24 #include "config_components.h"
49 #if CONFIG_HTTP_PROTOCOL
75 #define MPD_PROFILE_DASH 1
76 #define MPD_PROFILE_DVB 2
225 if (!*pb || !http_base_proto || !
c->http_persistent) {
227 #if CONFIG_HTTP_PROTOCOL
246 if (!http_base_proto || !
c->http_persistent) {
248 #if CONFIG_HTTP_PROTOCOL
260 switch (segment_type) {
273 default:
return NULL;
282 "Unable to open %s for writing: %s\n", url, errbuf);
283 return c->ignore_io_errors ? 0 : err;
303 int has_mp4_streams = 0;
304 for (
int i = 0;
i <
s->nb_streams; ++
i) {
307 c->segment_type_option,
s->streams[
i]->codecpar->codec_id);
323 if (
c->hls_playlist && !has_mp4_streams) {
382 if (!strcmp(str,
"mp4a") || !strcmp(str,
"mp4v")) {
391 if (
tag ==
MKTAG(
'm',
'p',
'4',
'a')) {
398 }
else if (
tag ==
MKTAG(
'm',
'p',
'4',
'v')) {
402 }
else if (!strcmp(str,
"avc1")) {
403 uint8_t *tmpbuf =
NULL;
408 if (extradata[0] != 1) {
420 if (extradata_size >= 4)
422 extradata[1], extradata[2], extradata[3]);
424 }
else if (!strcmp(str,
"av01")) {
454 if (!
c->single_file) {
478 if (
c->http_persistent)
485 const char *base_url,
int id) {
487 snprintf(playlist_name, string_size,
"%smedia_%d.m3u8", base_url,
id);
489 snprintf(playlist_name, string_size,
"media_%d.m3u8",
id);
493 int *start_index,
int *start_number) {
496 if (
c->window_size) {
503 int representation_id,
int final,
504 char *prefetch_url) {
507 char temp_filename_hls[1024];
508 char filename_hls[1024];
510 int target_duration = 0;
513 int use_rename = proto && !strcmp(proto,
"file");
514 int i, start_index, start_number;
515 double prog_date_time = 0;
519 if (!
c->hls_playlist || start_index >= os->
nb_segments ||
524 c->dirname, representation_id);
526 snprintf(temp_filename_hls,
sizeof(temp_filename_hls), use_rename ?
"%s.tmp" :
"%s", filename_hls);
551 if (
fabs(prog_date_time) < 1e-7) {
553 prog_date_time =
c->start_time_s;
560 (
double) seg->
duration / timescale, 0,
563 &prog_date_time, 0, 0, 0);
570 avio_printf(
c->m3u8_out,
"#EXT-X-PREFETCH:%s\n", prefetch_url);
584 int ret, range_length;
591 if (!
c->single_file) {
605 for (
i = 0;
i <
c->nb_as;
i++) {
615 for (
i = 0;
i <
s->nb_streams;
i++) {
642 int representation_id,
int final)
645 int i, start_index, start_number;
648 if (
c->use_template) {
650 avio_printf(
out,
"\t\t\t\t<SegmentTemplate timescale=\"%d\" ", timescale);
651 if (!
c->use_timeline) {
661 if (
c->presentation_time_offset)
662 avio_printf(
out,
" presentationTimeOffset=\"%"PRId64
"\"",
c->presentation_time_offset);
664 if (
c->use_timeline) {
665 int64_t cur_time = 0;
671 if (
i == start_index || seg->
time != cur_time) {
672 cur_time = seg->
time;
684 cur_time += (1 + repeat) * seg->
duration;
689 }
else if (
c->single_file) {
710 if (!
c->lhls ||
final) {
717 int outlen = strlen(str)*3/2 + 6;
722 for (; *str; str++) {
723 if (
pos + 6 > outlen) {
725 outlen = 2 * outlen + 6;
734 memcpy(&
out[
pos],
"&", 5);
736 }
else if (*str ==
'<') {
737 memcpy(&
out[
pos],
"<", 4);
739 }
else if (*str ==
'>') {
740 memcpy(&
out[
pos],
">", 4);
742 }
else if (*str ==
'\'') {
743 memcpy(&
out[
pos],
"'", 6);
745 }
else if (*str ==
'\"') {
746 memcpy(&
out[
pos],
""", 6);
760 int minutes = seconds / 60;
761 int hours = minutes / 60;
767 if (hours || minutes)
774 struct tm *ptm, tmbuf;
775 int64_t time_ms = time_us / 1000;
776 const time_t time_s = time_ms / 1000;
777 int millisec = time_ms - (time_s * 1000);
781 if (!strftime(buf,
size,
"%Y-%m-%dT%H:%M:%S", ptm)) {
798 avio_printf(
out,
"\t\t<AdaptationSet id=\"%d\" contentType=\"%s\" startWithSAP=\"1\" segmentAlignment=\"true\" bitstreamSwitching=\"true\"",
816 avio_printf(
out,
"\t\t\t<EssentialProperty id=\"%d\" schemeIdUri=\"http://dashif.org/guidelines/trickmode\" value=\"%d\"/>\n", as->
id, as->
trick_idx);
819 avio_printf(
out,
"\t\t\t<Role schemeIdUri=\"urn:mpeg:dash:role:2011\" value=\"%s\"/>\n", role->
value);
822 for (
i = 0;
i <
s->nb_streams;
i++) {
825 char bandwidth_str[64] = {
'\0'};
827 if (os->
as_idx - 1 != as_index)
831 snprintf(bandwidth_str,
sizeof(bandwidth_str),
" bandwidth=\"%d\"", os->
bit_rate);
834 snprintf(bandwidth_str,
sizeof(bandwidth_str),
" bandwidth=\"%d\"", average_bit_rate);
839 avio_printf(
out,
"\t\t\t<Representation id=\"%d\" mimeType=\"video/%s\" codecs=\"%s\"%s width=\"%d\" height=\"%d\"",
857 avio_printf(
out,
"\t\t\t<Representation id=\"%d\" mimeType=\"audio/%s\" codecs=\"%s\"%s audioSamplingRate=\"%d\">\n",
859 avio_printf(
out,
"\t\t\t\t<AudioChannelConfiguration schemeIdUri=\"urn:mpeg:dash:23003:3:audio_channel_configuration:2011\" value=\"%d\" />\n",
860 s->streams[
i]->codecpar->ch_layout.nb_channels);
863 avio_printf(
out,
"\t\t\t\t<ProducerReferenceTime id=\"%d\" inband=\"true\" type=\"%s\" wallClockTime=\"%s\" presentationTime=\"%"PRId64
"\">\n",
865 avio_printf(
out,
"\t\t\t\t\t<UTCTiming schemeIdUri=\"urn:mpeg:dash:utc:http-xsdate:2014\" value=\"%s\"/>\n",
c->utc_timing_url);
894 *as = &
c->as[
c->nb_as - 1];
895 memset(*as, 0,
sizeof(**as));
896 (*as)->media_type =
type;
897 (*as)->frag_type = -1;
898 (*as)->trick_idx = -1;
909 if (as->
media_type !=
s->streams[
i]->codecpar->codec_type) {
910 av_log(
s,
AV_LOG_ERROR,
"Codec type of stream %d doesn't match AdaptationSet's media type\n",
i);
917 av_log(
s,
AV_LOG_ERROR,
"DVB-DASH profile allows a max of 16 Representations per Adaptation Set\n");
929 const char *p =
c->adaptation_sets;
930 enum { new_set, parse_default, parsing_streams, parse_seg_duration, parse_frag_duration }
state;
936 for (
i = 0;
i <
s->nb_streams;
i++) {
941 c->streams[
i].as_idx =
c->nb_as;
961 char id_str[10], *end_str;
964 snprintf(id_str,
sizeof(id_str),
"%.*s", n, p);
966 i = strtol(id_str, &end_str, 10);
967 if (id_str == end_str || i < 0 || i >
c->nb_as) {
979 state = parse_default;
981 state = parse_seg_duration;
983 state = parse_frag_duration;
984 }
else if (
state == parse_seg_duration ||
state == parse_frag_duration) {
989 snprintf(str,
sizeof(str),
"%.*s", n, p);
1000 if (
state == parse_seg_duration)
1004 state = parse_default;
1008 n = strcspn(p,
",");
1009 snprintf(type_str,
sizeof(type_str),
"%.*s", n, p);
1014 if (!strcmp(type_str,
"duration"))
1016 else if (!strcmp(type_str,
"pframes"))
1018 else if (!strcmp(type_str,
"every_frame"))
1020 else if (!strcmp(type_str,
"none"))
1023 av_log(
s,
AV_LOG_ERROR,
"Unable to parse option value \"%s\" as fragment type\n", type_str);
1026 state = parse_default;
1028 n = strcspn(p,
">") + 1;
1029 if (n < strlen(p)) {
1032 av_log(
s,
AV_LOG_ERROR,
"Parse error, descriptor string should be a self-closing xml tag\n");
1038 state = parse_default;
1040 char trick_id_str[10], *end_str;
1042 n = strcspn(p,
",");
1043 snprintf(trick_id_str,
sizeof(trick_id_str),
"%.*s", n, p);
1046 as->
trick_idx = strtol(trick_id_str, &end_str, 10);
1047 if (trick_id_str == end_str || as->
trick_idx < 0)
1052 state = parse_default;
1054 state = parsing_streams;
1055 }
else if (
state == parsing_streams) {
1057 char idx_str[8], *end_str;
1059 n = strcspn(p,
" ,");
1060 snprintf(idx_str,
sizeof(idx_str),
"%.*s", n, p);
1068 for (
i = 0;
i <
s->nb_streams;
i++) {
1069 if (
s->streams[
i]->codecpar->codec_type !=
type)
1078 i = strtol(idx_str, &end_str, 10);
1079 if (idx_str == end_str || i < 0 || i >=
s->nb_streams) {
1104 for (
i = 0;
i <
s->nb_streams;
i++) {
1113 for (
i = 0;
i <
c->nb_as;
i++) {
1117 for (n = 0; n <
c->nb_as; n++) {
1121 if (n >=
c->nb_as) {
1134 char temp_filename[1024];
1137 int use_rename = proto && !strcmp(proto,
"file");
1138 static unsigned int warned_non_file = 0;
1142 if (!use_rename && !warned_non_file++)
1143 av_log(
s,
AV_LOG_ERROR,
"Cannot use rename on non file protocol, this may lead to races and temporary partial files\n");
1145 snprintf(temp_filename,
sizeof(temp_filename), use_rename ?
"%s.tmp" :
"%s",
s->url);
1153 avio_printf(
out,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
1154 avio_printf(
out,
"<MPD xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
1155 "\txmlns=\"urn:mpeg:dash:schema:mpd:2011\"\n"
1156 "\txmlns:xlink=\"http://www.w3.org/1999/xlink\"\n"
1157 "\txsi:schemaLocation=\"urn:mpeg:DASH:schema:MPD:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd\"\n"
1162 avio_printf(
out,
"%s",
"urn:dvb:dash:profile:dvb-dash:2014\"\n");
1164 final ?
"static" :
"dynamic");
1172 if (
c->use_template && !
c->use_timeline)
1173 update_period = 500;
1174 if (
c->update_period)
1175 update_period =
c->update_period;
1176 avio_printf(
out,
"\tminimumUpdatePeriod=\"PT%"PRId64
"S\"\n", update_period);
1179 if (
c->availability_start_time[0])
1180 avio_printf(
out,
"\tavailabilityStartTime=\"%s\"\n",
c->availability_start_time);
1184 if (
c->window_size &&
c->use_template) {
1194 write_time(
out,
c->ldash &&
c->max_gop_size ?
c->max_gop_size :
c->last_duration * 2);
1205 if (!
final &&
c->target_latency &&
c->target_latency_refid >= 0) {
1206 avio_printf(
out,
"\t\t<Latency target=\"%"PRId64
"\"",
c->target_latency / 1000);
1207 if (
s->nb_streams > 1)
1213 avio_printf(
out,
"\t\t<PlaybackRate min=\"%.2f\" max=\"%.2f\"/>\n",
1217 if (
c->window_size &&
s->nb_streams > 0 &&
c->streams[0].nb_segments > 0 && !
c->use_template) {
1228 for (
i = 0;
i <
c->nb_as;
i++) {
1234 if (
c->utc_timing_url)
1235 avio_printf(
out,
"\t<UTCTiming schemeIdUri=\"urn:mpeg:dash:utc:http-xsdate:2014\" value=\"%s\"/>\n",
c->utc_timing_url);
1246 if (
c->hls_playlist) {
1247 char filename_hls[1024];
1250 if (
c->master_playlist_created && (!
c->master_publish_rate ||
1251 c->streams[0].segment_index %
c->master_publish_rate))
1255 snprintf(filename_hls,
sizeof(filename_hls),
"%s%s",
c->dirname,
c->hls_master_name);
1257 snprintf(filename_hls,
sizeof(filename_hls),
"%s",
c->hls_master_name);
1259 snprintf(temp_filename,
sizeof(temp_filename), use_rename ?
"%s.tmp" :
"%s", filename_hls);
1272 const char *audio_group =
"A1";
1273 char audio_codec_str[128] =
"\0";
1275 int max_audio_bitrate = 0;
1277 for (
i = 0;
i <
s->nb_streams;
i++) {
1278 char playlist_file[64];
1287 playlist_file,
NULL,
i, is_default);
1291 if (strlen(audio_codec_str))
1292 av_strlcat(audio_codec_str,
",",
sizeof(audio_codec_str));
1298 for (
i = 0;
i <
s->nb_streams;
i++) {
1299 char playlist_file[64];
1300 char codec_str[128];
1303 const char *agroup =
NULL;
1316 if (max_audio_bitrate) {
1317 agroup = audio_group;
1318 stream_bitrate += max_audio_bitrate;
1319 av_strlcat(codec_str,
",",
sizeof(codec_str));
1320 av_strlcat(codec_str, audio_codec_str,
sizeof(codec_str));
1324 playlist_file, agroup,
1331 for (
i = 0;
i <
s->nb_streams;
i++) {
1332 char playlist_file[64];
1333 char codec_str[128];
1350 playlist_file,
NULL,
1359 c->master_playlist_created = 1;
1378 char basename[1024];
1380 c->nr_of_streams_to_flush = 0;
1381 if (
c->single_file_name)
1384 c->use_template = 0;
1392 "LHLS is experimental, Please set -strict experimental in order to enable it.\n");
1396 if (
c->lhls && !
c->streaming) {
1401 if (
c->lhls && !
c->hls_playlist) {
1403 c->hls_playlist = 1;
1406 if (
c->ldash && !
c->streaming) {
1411 if (
c->target_latency && !
c->streaming) {
1413 c->target_latency = 0;
1416 if (
c->global_sidx && !
c->single_file) {
1421 if (
c->global_sidx &&
c->streaming) {
1430 if (
c->write_prft < 0) {
1431 c->write_prft =
c->ldash;
1436 if (
c->write_prft && !
c->utc_timing_url) {
1437 av_log(
s,
AV_LOG_WARNING,
"Producer Reference Time element option will be ignored as utc_timing_url is not set\n");
1441 if (
c->write_prft && !
c->streaming) {
1442 av_log(
s,
AV_LOG_WARNING,
"Producer Reference Time element option will be ignored as streaming is not enabled\n");
1446 if (
c->ldash && !
c->write_prft) {
1447 av_log(
s,
AV_LOG_WARNING,
"Low Latency mode enabled without Producer Reference Time element option! Resulting manifest may not be complaint\n");
1450 if (
c->target_latency && !
c->write_prft) {
1451 av_log(
s,
AV_LOG_WARNING,
"Target latency option will be ignored as Producer Reference Time element will not be written\n");
1452 c->target_latency = 0;
1455 if (
av_cmp_q(
c->max_playback_rate,
c->min_playback_rate) < 0) {
1456 av_log(
s,
AV_LOG_WARNING,
"Minimum playback rate value is higer than the Maximum. Both will be ignored\n");
1457 c->min_playback_rate =
c->max_playback_rate = (
AVRational) {1, 1};
1461 ptr = strrchr(
c->dirname,
'/');
1463 av_strlcpy(basename, &ptr[1],
sizeof(basename));
1466 c->dirname[0] =
'\0';
1470 ptr = strrchr(basename,
'.');
1474 c->streams =
av_mallocz(
sizeof(*
c->streams) *
s->nb_streams);
1484 for (
i = 0;
i <
s->nb_streams;
i++) {
1490 char filename[1024];
1492 os->
bit_rate =
s->streams[
i]->codecpar->bit_rate;
1505 if (
c->init_seg_name) {
1510 if (
c->media_seg_name) {
1515 if (
c->single_file_name) {
1526 "One or many segment file names doesn't end with .webm. "
1527 "Override -init_seg_name and/or -media_seg_name and/or "
1528 "-single_file_name to end with the extension .webm\n");
1532 av_log(
s,
AV_LOG_WARNING,
"One or more streams in WebM output format. Streaming option will be ignored\n");
1546 #if FF_API_AVFORMAT_IO_CLOSE
1548 ctx->io_close =
s->io_close;
1576 if (
c->single_file) {
1586 if (!
c->single_file) {
1627 av_log(
s,
AV_LOG_WARNING,
"frag_type set to P-Frame reordering, but no parser found for stream %d\n",
i);
1675 AVRational avg_frame_rate =
s->streams[
i]->avg_frame_rate;
1677 if (avg_frame_rate.
num > 0) {
1701 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);
1717 c->nr_of_streams_to_flush++;
1720 if (!
c->has_video &&
c->seg_duration <= 0) {
1727 c->nr_of_streams_flushed = 0;
1728 c->target_latency_refid = -1;
1737 for (
i = 0;
i <
s->nb_streams;
i++) {
1754 int64_t start_pos, int64_t range_length,
1755 int64_t index_length,
int next_exp_index)
1774 if (seg->
time < 0) {
1803 int64_t
pos,
int *index_length)
1822 *index_length =
AV_RB32(&buf[0]);
1830 size_t extradata_size;
1837 if (!extradata_size)
1844 memcpy(par->
extradata, extradata, extradata_size);
1855 if (http_base_proto) {
1900 for (
int i = 0;
i < remove_count; ++
i) {
1917 int use_rename = proto && !strcmp(proto,
"file");
1919 int cur_flush_segment_index = 0, next_exp_index = -1;
1921 cur_flush_segment_index =
c->streams[stream].segment_index;
1924 if (
c->use_template && !
c->use_timeline &&
c->index_correction &&
1927 int64_t pts_diff =
av_rescale_q(
c->streams[stream].last_pts -
1928 c->streams[stream].first_pts,
1929 s->streams[stream]->time_base,
1931 next_exp_index = (pts_diff /
c->streams[stream].seg_duration) + 1;
1935 for (
i = 0;
i <
s->nb_streams;
i++) {
1938 int range_length, index_length = 0;
1947 if (stream >= 0 &&
i != stream) {
1967 if (
c->single_file) {
1994 os->
pos += range_length;
1997 if (
c->window_size) {
1998 for (
i = 0;
i <
s->nb_streams;
i++) {
2000 int remove_count = os->
nb_segments -
c->window_size -
c->extra_window_size;
2001 if (remove_count > 0)
2007 for (
i = 0;
i <
s->nb_streams;
i++) {
2012 if (
c->global_sidx) {
2013 int j, start_index, start_number;
2030 if (
c->has_video && !
final) {
2031 c->nr_of_streams_flushed++;
2032 if (
c->nr_of_streams_flushed !=
c->nr_of_streams_to_flush)
2035 c->nr_of_streams_flushed = 0;
2039 if (!
c->streaming ||
final)
2049 size_t side_data_size;
2064 if (
c->target_latency_refid < 0)
2077 int64_t seg_end_duration, elapsed_duration;
2102 if (
c->write_prft) {
2113 if (!
c->availability_start_time[0]) {
2115 c->start_time_s = start_time_us / 1000000;
2117 sizeof(
c->availability_start_time), start_time_us);
2127 int64_t frame_duration = 0;
2143 if (
c->use_template && !
c->use_timeline) {
2179 "Segment durations differ too much, enable use_timeline "
2180 "and use_template, or keep a stricter keyframe interval\n");
2250 int use_rename = proto && !strcmp(proto,
"file");
2260 use_rename ?
"%s.tmp" :
"%s", os->
full_path);
2284 uint8_t *buf =
NULL;
2302 if (
s->nb_streams > 0) {
2306 if (!
c->last_duration)
2308 s->streams[0]->time_base,
2311 s->streams[0]->time_base,
2316 if (
c->remove_at_exit) {
2317 for (
i = 0;
i <
s->nb_streams; ++
i) {
2322 char filename[1024];
2329 if (
c->hls_playlist &&
c->master_playlist_created) {
2330 char filename[1024];
2331 snprintf(filename,
sizeof(filename),
"%s%s",
c->dirname,
c->hls_master_name);
2360 #define OFFSET(x) offsetof(DASHContext, x)
2361 #define E AV_OPT_FLAG_ENCODING_PARAM
2363 {
"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 },
2364 {
"window_size",
"number of segments kept in the manifest",
OFFSET(window_size),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
E },
2365 {
"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 },
2366 {
"seg_duration",
"segment duration (in seconds, fractional value can be set)",
OFFSET(seg_duration),
AV_OPT_TYPE_DURATION, { .i64 = 5000000 }, 0, INT_MAX,
E },
2367 {
"frag_duration",
"fragment duration (in seconds, fractional value can be set)",
OFFSET(frag_duration),
AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT_MAX,
E },
2372 {
"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,
"frag_type"},
2373 {
"remove_at_exit",
"remove all segments when finished",
OFFSET(remove_at_exit),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
2374 {
"use_template",
"Use SegmentTemplate instead of SegmentList",
OFFSET(use_template),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
E },
2375 {
"use_timeline",
"Use SegmentTimeline in SegmentTemplate",
OFFSET(use_timeline),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
E },
2376 {
"single_file",
"Store all segments in one file, accessed using byte ranges",
OFFSET(single_file),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
2377 {
"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 },
2378 {
"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 },
2379 {
"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 },
2380 {
"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 },
2383 {
"http_persistent",
"Use persistent HTTP connections",
OFFSET(http_persistent),
AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1,
E },
2384 {
"hls_playlist",
"Generate HLS playlist files(master.m3u8, media_%d.m3u8)",
OFFSET(hls_playlist),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
2385 {
"hls_master_name",
"HLS master playlist name",
OFFSET(hls_master_name),
AV_OPT_TYPE_STRING, {.str =
"master.m3u8"}, 0, 0,
E },
2386 {
"streaming",
"Enable/Disable streaming mode of output. Each frame will be moof fragment",
OFFSET(streaming),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
2387 {
"timeout",
"set timeout for socket I/O operations",
OFFSET(timeout),
AV_OPT_TYPE_DURATION, { .i64 = -1 }, -1, INT_MAX, .flags =
E },
2388 {
"index_correction",
"Enable/Disable segment index correction logic",
OFFSET(index_correction),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
2389 {
"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},
2390 {
"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 },
2395 {
"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 },
2396 {
"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 },
2397 {
"ldash",
"Enable Low-latency dash. Constrains the value of a few elements",
OFFSET(ldash),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
E },
2398 {
"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},
2399 {
"write_prft",
"Write producer reference time element",
OFFSET(write_prft),
AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1,
E},
2404 {
"target_latency",
"Set desired target latency for Low-latency dash",
OFFSET(target_latency),
AV_OPT_TYPE_DURATION, { .i64 = 0 }, 0, INT_MAX,
E },
2405 {
"min_playback_rate",
"Set desired minimum playback rate",
OFFSET(min_playback_rate),
AV_OPT_TYPE_RATIONAL, { .dbl = 1.0 }, 0.5, 1.5,
E },
2406 {
"max_playback_rate",
"Set desired maximum playback rate",
OFFSET(max_playback_rate),
AV_OPT_TYPE_RATIONAL, { .dbl = 1.0 }, 0.5, 1.5,
E },
2407 {
"update_period",
"Set the mpd update interval",
OFFSET(update_period),
AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX,
E},
2421 .p.extensions =
"mpd",
static const AVOption options[]
#define FF_ENABLE_DEPRECATION_WARNINGS
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_BPRINT_SIZE_UNLIMITED
int master_playlist_created
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
AVRational max_frame_rate
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it.
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVMediaType codec_type
General type of the encoded data.
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.
static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)
struct AVBSFContext * bsfc
bitstream filter to run on stream
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
const AVCodecTag ff_mp4_obj_type[]
This struct describes the properties of an encoded stream.
void ff_hls_write_end_list(AVIOContext *out)
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
@ 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...
static int dash_check_bitstream(AVFormatContext *s, AVStream *st, const AVPacket *avpkt)
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
static int dict_copy_entry(AVDictionary **dst, const AVDictionary *src, const char *key)
int64_t presentation_time_offset
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
const char * hls_master_name
static void set_http_options(AVDictionary **options, DASHContext *c)
static int parse_adaptation_sets(AVFormatContext *s)
static int update_stream_extradata(AVFormatContext *s, OutputStream *os, AVPacket *pkt, AVRational *frame_rate)
AVStream ** streams
A list of all streams in the file.
static void deinit(AVFormatContext *s)
int strict_std_compliance
Allow non-standard and experimental extension.
static void set_codec_str(AVFormatContext *s, AVCodecParameters *par, AVRational *frame_rate, char *str, int size)
int64_t wallclock
A UTC timestamp, in microseconds, since Unix epoch (e.g, av_gettime()).
static int dash_init(AVFormatContext *s)
AVRational avg_frame_rate
Average framerate.
#define FF_COMPLIANCE_STRICT
Strictly conform to all the things in the spec no matter what consequences.
#define AV_DICT_APPEND
If the entry already exists, append to it.
#define AV_LOG_VERBOSE
Detailed information.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
static void dashenc_io_close(AVFormatContext *s, AVIOContext **pb, char *filename)
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
AVRational min_frame_rate
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.
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
uint8_t chroma_subsampling_y
static int add_adaptation_set(AVFormatContext *s, AdaptationSet **as, enum AVMediaType type)
AVCodecParserContext * parser
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
const char * single_file_name
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)
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
static void dashenc_delete_media_segments(AVFormatContext *s, OutputStream *os, int remove_count)
static int dashenc_delete_segment_file(AVFormatContext *s, const char *file)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
void ff_hls_write_audio_rendition(AVIOContext *out, const char *agroup, const char *filename, const char *language, int name_id, int is_default)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
AVCodecParserContext * av_parser_init(int codec_id)
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)
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
int ff_rename(const char *url_src, const char *url_dst, void *logctx)
Wrap ffurl_move() and log if error happens.
uint8_t color_description_present_flag
static void get_hls_playlist_name(char *playlist_name, int string_size, const char *base_url, int id)
static void write_time(AVIOContext *out, int64_t time)
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVIOContext * http_delete
const char * init_seg_name
static void get_start_index_number(OutputStream *os, DASHContext *c, int *start_index, int *start_number)
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
int ff_isom_get_vpcc_features(AVFormatContext *s, AVCodecParameters *par, const uint8_t *data, int len, AVRational *frame_rate, VPCC *vpcc)
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
int flags
Flags modifying the (de)muxer behaviour.
const char * media_seg_name
static double av_q2d(AVRational a)
Convert an AVRational to a double.
int(* init)(AVBSFContext *ctx)
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.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AVIO_FLAG_WRITE
write-only
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static const FFOutputFormat * ffofmt(const AVOutputFormat *fmt)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static void dashenc_delete_file(AVFormatContext *s, char *filename)
const char * media_seg_name
static int write_manifest(AVFormatContext *s, int final)
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 ff_http_do_new_request(URLContext *h, const char *uri)
Send a new HTTP request, reusing the old connection.
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
uint8_t chroma_sample_position
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int avcodec_parameters_to_context(AVCodecContext *codec, const struct AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
static __device__ float fabs(float a)
int first_segment_bit_rate
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
static int dash_write_packet(AVFormatContext *s, AVPacket *pkt)
static int write_trailer(AVFormatContext *s1)
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Rational number (pair of numerator and denominator).
char * av_strireplace(const char *str, const char *from, const char *to)
Locale-independent strings replace.
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PICTURE_TYPE_I
Intra.
int ffurl_shutdown(URLContext *h, int flags)
Signal the URLContext that we are done reading or writing the stream.
AVIOContext * pb
I/O context.
uint8_t transfer_characteristics
static int flush_init_segment(AVFormatContext *s, OutputStream *os)
static SegmentType select_segment_type(SegmentType segment_type, enum AVCodecID codec_id)
static const struct codec_string codecs[]
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
const AVCodecTag ff_codec_movvideo_tags[]
int av_write_frame(AVFormatContext *s, AVPacket *pkt)
Write a packet to an output media file.
This structure supplies correlation between a packet timestamp and a wall clock production time.
const AVCodecTag ff_codec_movaudio_tags[]
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
AVCodecID
Identify the syntax and semantics of the bitstream.
int extradata_size
Size of the extradata content in bytes.
void ff_hls_write_playlist_version(AVIOContext *out, int version)
const char * extension_name
uint8_t matrix_coefficients
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
double availability_time_offset
unsigned int av_codec_get_tag(const struct AVCodecTag *const *tags, enum AVCodecID id)
Get the codec tag for the given codec id id.
int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
AVProducerReferenceTime producer_reference_time
static int64_t start_time
char * url
input or output URL.
int nr_of_streams_to_flush
struct URLContext * ffio_geturlcontext(AVIOContext *s)
Return the URLContext associated with the AVIOContext.
const char * utc_timing_url
#define AV_NOPTS_VALUE
Undefined timestamp value.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
AVRational min_playback_rate
void ff_hls_write_init_file(AVIOContext *out, const char *filename, int byterange_mode, int64_t size, int64_t pos)
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
static void set_vp9_codec_str(AVFormatContext *s, AVCodecParameters *par, AVRational *frame_rate, char *str, int size)
uint64_t availability_start_time
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
void avio_wb32(AVIOContext *s, unsigned int val)
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
@ AV_PKT_DATA_PRFT
Producer Reference Time data corresponding to the AVProducerReferenceTime struct, usually exported by...
int flags
A combination of AV_PKT_FLAG values.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
AVCodecContext * parser_avctx
#define AV_LOG_INFO
Standard information.
static int flush_dynbuf(DASHContext *c, OutputStream *os, int *range_length)
AVRational max_playback_rate
int64_t max_frag_duration
static const char * get_format_str(SegmentType segment_type)
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
#define PARSER_FLAG_COMPLETE_FRAMES
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
#define AVERROR_MUXER_NOT_FOUND
Muxer not found.
#define AV_TIME_BASE
Internal time base represented as integer.
static void find_index_range(AVFormatContext *s, const char *full_path, int64_t pos, int *index_length)
int avoid_negative_ts
Avoid negative timestamps during muxing.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
enum AVFieldOrder field_order
Video only.
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
const FFOutputFormat ff_dash_muxer
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
char producer_reference_time_str[100]
int ff_av1_parse_seq_header(AV1SequenceParameters *seq, const uint8_t *buf, int size)
Parses a Sequence Header from the the provided buffer.
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
const char * init_seg_name
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, int64_t video_keyframe_size, int64_t video_keyframe_pos, int iframe_mode)
static int write_adaptation_set(AVFormatContext *s, AVIOContext *out, int as_index, int final)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
const struct AVOutputFormat * oformat
The output container format.
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,...
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...
void av_bprintf(AVBPrint *buf, const char *fmt,...)
#define AV_ERROR_MAX_STRING_SIZE
static int adaptation_set_add_stream(AVFormatContext *s, int as_idx, int i)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
const char * single_file_name
static int dash_write_header(AVFormatContext *s)
static void write_styp(AVIOContext *pb)
main external API structure.
int64_t max_segment_duration
int index
stream index in AVFormatContext
int nr_of_streams_flushed
static int dashenc_io_open(AVFormatContext *s, AVIOContext **pb, char *filename, AVDictionary **options)
static const char * get_extension_str(SegmentType type, int single_file)
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, int bandwidth, const char *filename, const char *agroup, const char *codecs, const char *ccgroup, const char *sgroup)
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
int64_t total_pkt_duration
static void format_date(char *buf, int size, int64_t time_us)
int(* io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, AVDictionary **options)
A callback for opening new IO streams.
uint8_t chroma_subsampling_x
static int dash_write_trailer(AVFormatContext *s)
static void write_hls_media_playlist(OutputStream *os, AVFormatContext *s, int representation_id, int final, char *prefetch_url)
int64_t av_gettime(void)
Get the current time in microseconds.
#define FF_DISABLE_DEPRECATION_WARNINGS
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 AVIO_FLAG_READ
read-only
char * av_strdup(const char *s)
Duplicate a string.
static void output_segment_list(OutputStream *os, AVIOContext *out, AVFormatContext *s, int representation_id, int final)
@ AV_PICTURE_TYPE_P
Predicted.
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.
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 video_delay
Video only.
static int handle_io_open_error(AVFormatContext *s, int err, char *url)
static int dash_flush(AVFormatContext *s, int final, int stream)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
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)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
int64_t pos
byte position in stream, -1 if unknown
int(* io_close2)(struct AVFormatContext *s, AVIOContext *pb)
A callback for closing the streams opened with AVFormatContext.io_open().
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
static int dash_parse_prft(DASHContext *c, AVPacket *pkt)
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.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
AVDictionary * format_options
static const AVClass dash_class
#define MKTAG(a, b, c, d)
SegmentType segment_type_option
int ffurl_delete(const char *url)
Delete a resource.
static void write_header(FFV1Context *f)
char * av_strndup(const char *s, size_t len)
Duplicate a substring of a string.
static void dash_free(AVFormatContext *s)
enum AVMediaType media_type
static int init_segment_types(AVFormatContext *s)
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
void av_parser_close(AVCodecParserContext *s)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
static char * xmlescape(const char *str)