FFmpeg  4.4.9
webmdashenc.c
Go to the documentation of this file.
1 /*
2  * WebM DASH Manifest XML muxer
3  * Copyright (c) 2014 Vignesh Venkatasubramanian
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /*
23  * WebM DASH Specification:
24  * https://sites.google.com/a/webmproject.org/wiki/adaptive-streaming/webm-dash-specification
25  * ISO DASH Specification:
26  * http://standards.iso.org/ittf/PubliclyAvailableStandards/c065274_ISO_IEC_23009-1_2014.zip
27  */
28 
29 #include <float.h>
30 #include <stdint.h>
31 #include <string.h>
32 
33 #include "avformat.h"
34 #include "matroska.h"
35 
36 #include "libavutil/avstring.h"
37 #include "libavutil/dict.h"
38 #include "libavutil/opt.h"
40 
41 typedef struct AdaptationSet {
42  char id[10];
43  int *streams;
44  int nb_streams;
46 
47 typedef struct WebMDashMuxContext {
48  const AVClass *class;
51  int nb_as;
53  int is_live;
61 
62 static const char *get_codec_name(int codec_id)
63 {
65 }
66 
68 {
69  int i = 0;
70  double max = 0.0;
71  for (i = 0; i < s->nb_streams; i++) {
72  AVDictionaryEntry *duration = av_dict_get(s->streams[i]->metadata,
73  DURATION, NULL, 0);
74  if (!duration || atof(duration->value) < 0) continue;
75  if (atof(duration->value) > max) max = atof(duration->value);
76  }
77  return max / 1000;
78 }
79 
81 {
82  WebMDashMuxContext *w = s->priv_data;
83  AVIOContext *pb = s->pb;
84  double min_buffer_time = 1.0;
85  avio_printf(pb, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
86  avio_printf(pb, "<MPD\n");
87  avio_printf(pb, " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
88  avio_printf(pb, " xmlns=\"urn:mpeg:DASH:schema:MPD:2011\"\n");
89  avio_printf(pb, " xsi:schemaLocation=\"urn:mpeg:DASH:schema:MPD:2011\"\n");
90  avio_printf(pb, " type=\"%s\"\n", w->is_live ? "dynamic" : "static");
91  if (!w->is_live) {
92  avio_printf(pb, " mediaPresentationDuration=\"PT%gS\"\n",
93  get_duration(s));
94  }
95  avio_printf(pb, " minBufferTime=\"PT%gS\"\n", min_buffer_time);
96  avio_printf(pb, " profiles=\"%s\"%s",
97  w->is_live ? "urn:mpeg:dash:profile:isoff-live:2011" : "urn:mpeg:dash:profile:webm-on-demand:2012",
98  w->is_live ? "\n" : ">\n");
99  if (w->is_live) {
100  time_t local_time = time(NULL);
101  struct tm gmt_buffer;
102  struct tm *gmt = gmtime_r(&local_time, &gmt_buffer);
103  char gmt_iso[21];
104  if (!strftime(gmt_iso, 21, "%Y-%m-%dT%H:%M:%SZ", gmt)) {
105  return AVERROR_UNKNOWN;
106  }
107  if (s->flags & AVFMT_FLAG_BITEXACT) {
108  av_strlcpy(gmt_iso, "", 1);
109  }
110  avio_printf(pb, " availabilityStartTime=\"%s\"\n", gmt_iso);
111  avio_printf(pb, " timeShiftBufferDepth=\"PT%gS\"\n", w->time_shift_buffer_depth);
112  avio_printf(pb, " minimumUpdatePeriod=\"PT%dS\"", w->minimum_update_period);
113  avio_printf(pb, ">\n");
114  if (w->utc_timing_url) {
115  avio_printf(pb, "<UTCTiming\n");
116  avio_printf(pb, " schemeIdUri=\"urn:mpeg:dash:utc:http-iso:2014\"\n");
117  avio_printf(pb, " value=\"%s\"/>\n", w->utc_timing_url);
118  }
119  }
120  return 0;
121 }
122 
124 {
125  avio_printf(s->pb, "</MPD>\n");
126 }
127 
129 {
130  int i;
131  AVDictionaryEntry *gold = av_dict_get(s->streams[as->streams[0]]->metadata,
132  CUE_TIMESTAMPS, NULL, 0);
133  if (!gold) return 0;
134  for (i = 1; i < as->nb_streams; i++) {
135  AVDictionaryEntry *ts = av_dict_get(s->streams[as->streams[i]]->metadata,
136  CUE_TIMESTAMPS, NULL, 0);
137  if (!ts || !av_strstart(ts->value, gold->value, NULL)) return 0;
138  }
139  return 1;
140 }
141 
143 {
144  int i;
145  const AVStream *gold_st = s->streams[as->streams[0]];
146  AVDictionaryEntry *gold_track_num = av_dict_get(gold_st->metadata,
147  TRACK_NUMBER, NULL, 0);
148  AVCodecParameters *gold_par = gold_st->codecpar;
149  if (!gold_track_num) return 0;
150  for (i = 1; i < as->nb_streams; i++) {
151  const AVStream *st = s->streams[as->streams[i]];
152  AVDictionaryEntry *track_num = av_dict_get(st->metadata,
153  TRACK_NUMBER, NULL, 0);
154  AVCodecParameters *par = st->codecpar;
155  if (!track_num ||
156  !av_strstart(track_num->value, gold_track_num->value, NULL) ||
157  gold_par->codec_id != par->codec_id ||
158  gold_par->extradata_size != par->extradata_size ||
159  (par->extradata_size > 0 &&
160  memcmp(gold_par->extradata, par->extradata, par->extradata_size))) {
161  return 0;
162  }
163  }
164  return 1;
165 }
166 
167 /*
168  * Writes a Representation within an Adaptation Set. Returns 0 on success and
169  * < 0 on failure.
170  */
171 static int write_representation(AVFormatContext *s, AVStream *st, char *id,
172  int output_width, int output_height,
173  int output_sample_rate)
174 {
175  WebMDashMuxContext *w = s->priv_data;
176  AVIOContext *pb = s->pb;
177  const AVCodecParameters *par = st->codecpar;
178  AVDictionary *metadata = w->escaped_metadata[st->index];
179  AVDictionaryEntry *bandwidth = av_dict_get(metadata, BANDWIDTH, NULL, 0);
180  const char *bandwidth_str;
181  avio_printf(pb, "<Representation id=\"%s\"", id);
182  if (bandwidth) {
183  bandwidth_str = bandwidth->value;
184  } else if (w->is_live) {
185  // if bandwidth for live was not provided, use a default
186  bandwidth_str = (par->codec_type == AVMEDIA_TYPE_AUDIO) ? "128000" : "1000000";
187  } else {
188  return AVERROR(EINVAL);
189  }
190  avio_printf(pb, " bandwidth=\"%s\"", bandwidth_str);
191  if (par->codec_type == AVMEDIA_TYPE_VIDEO && output_width)
192  avio_printf(pb, " width=\"%d\"", par->width);
193  if (par->codec_type == AVMEDIA_TYPE_VIDEO && output_height)
194  avio_printf(pb, " height=\"%d\"", par->height);
195  if (par->codec_type == AVMEDIA_TYPE_AUDIO && output_sample_rate)
196  avio_printf(pb, " audioSamplingRate=\"%d\"", par->sample_rate);
197  if (w->is_live) {
198  // For live streams, Codec and Mime Type always go in the Representation tag.
199  avio_printf(pb, " codecs=\"%s\"", get_codec_name(par->codec_id));
200  avio_printf(pb, " mimeType=\"%s/webm\"",
201  par->codec_type == AVMEDIA_TYPE_VIDEO ? "video" : "audio");
202  // For live streams, subsegments always start with key frames. So this
203  // is always 1.
204  avio_printf(pb, " startsWithSAP=\"1\"");
205  avio_printf(pb, ">");
206  } else {
207  AVDictionaryEntry *irange = av_dict_get(metadata, INITIALIZATION_RANGE, NULL, 0);
208  AVDictionaryEntry *cues_start = av_dict_get(metadata, CUES_START, NULL, 0);
209  AVDictionaryEntry *cues_end = av_dict_get(metadata, CUES_END, NULL, 0);
210  AVDictionaryEntry *filename = av_dict_get(metadata, FILENAME, NULL, 0);
211  if (!irange || !cues_start || !cues_end || !filename)
212  return AVERROR(EINVAL);
213 
214  avio_printf(pb, ">\n");
215  avio_printf(pb, "<BaseURL>%s</BaseURL>\n", filename->value);
216  avio_printf(pb, "<SegmentBase\n");
217  avio_printf(pb, " indexRange=\"%s-%s\">\n", cues_start->value, cues_end->value);
218  avio_printf(pb, "<Initialization\n");
219  avio_printf(pb, " range=\"0-%s\" />\n", irange->value);
220  avio_printf(pb, "</SegmentBase>\n");
221  }
222  avio_printf(pb, "</Representation>\n");
223  return 0;
224 }
225 
226 /*
227  * Checks if width of all streams are the same. Returns 1 if true, 0 otherwise.
228  */
230 {
231  int first_width, i;
232  if (as->nb_streams < 2) return 1;
233  first_width = s->streams[as->streams[0]]->codecpar->width;
234  for (i = 1; i < as->nb_streams; i++)
235  if (first_width != s->streams[as->streams[i]]->codecpar->width)
236  return 0;
237  return 1;
238 }
239 
240 /*
241  * Checks if height of all streams are the same. Returns 1 if true, 0 otherwise.
242  */
244 {
245  int first_height, i;
246  if (as->nb_streams < 2) return 1;
247  first_height = s->streams[as->streams[0]]->codecpar->height;
248  for (i = 1; i < as->nb_streams; i++)
249  if (first_height != s->streams[as->streams[i]]->codecpar->height)
250  return 0;
251  return 1;
252 }
253 
254 /*
255  * Checks if sample rate of all streams are the same. Returns 1 if true, 0 otherwise.
256  */
258 {
259  int first_sample_rate, i;
260  if (as->nb_streams < 2) return 1;
261  first_sample_rate = s->streams[as->streams[0]]->codecpar->sample_rate;
262  for (i = 1; i < as->nb_streams; i++)
263  if (first_sample_rate != s->streams[as->streams[i]]->codecpar->sample_rate)
264  return 0;
265  return 1;
266 }
267 
269 {
270  WebMDashMuxContext *w = s->priv_data;
271  int i;
272  for (i = 0; i < w->nb_as; i++) {
273  av_freep(&w->as[i].streams);
274  }
275  av_freep(&w->as);
276  w->nb_as = 0;
277 }
278 
279 /*
280  * Parses a live header filename and returns the position of the '_' and '.'
281  * delimiting <file_description> and <representation_id>.
282  *
283  * Name of the header file should conform to the following pattern:
284  * <file_description>_<representation_id>.hdr where <file_description> can be
285  * anything. The chunks should be named according to the following pattern:
286  * <file_description>_<representation_id>_<chunk_number>.chk
287  */
288 static int split_filename(char *filename, char **underscore_pos,
289  char **period_pos)
290 {
291  *underscore_pos = strrchr(filename, '_');
292  if (!*underscore_pos)
293  return AVERROR(EINVAL);
294  *period_pos = strchr(*underscore_pos, '.');
295  if (!*period_pos)
296  return AVERROR(EINVAL);
297  return 0;
298 }
299 
300 /*
301  * Writes an Adaptation Set. Returns 0 on success and < 0 on failure.
302  */
303 static int write_adaptation_set(AVFormatContext *s, int as_index)
304 {
305  WebMDashMuxContext *w = s->priv_data;
306  AdaptationSet *as = &w->as[as_index];
307  const AVStream *st = s->streams[as->streams[0]];
308  AVCodecParameters *par = st->codecpar;
309  AVDictionaryEntry *lang;
310  AVIOContext *pb = s->pb;
311  int i;
312  static const char boolean[2][6] = { "false", "true" };
313  int subsegmentStartsWithSAP = 1;
314 
315  // Width, Height and Sample Rate will go in the AdaptationSet tag if they
316  // are the same for all contained Representations. otherwise, they will go
317  // on their respective Representation tag. For live streams, they always go
318  // in the Representation tag.
319  int width_in_as = 1, height_in_as = 1, sample_rate_in_as = 1;
320  if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
321  width_in_as = !w->is_live && check_matching_width (s, as);
322  height_in_as = !w->is_live && check_matching_height(s, as);
323  } else {
324  sample_rate_in_as = !w->is_live && check_matching_sample_rate(s, as);
325  }
326 
327  avio_printf(pb, "<AdaptationSet id=\"%s\"", as->id);
328  avio_printf(pb, " mimeType=\"%s/webm\"",
329  par->codec_type == AVMEDIA_TYPE_VIDEO ? "video" : "audio");
330  avio_printf(pb, " codecs=\"%s\"", get_codec_name(par->codec_id));
331 
332  lang = av_dict_get(st->metadata, "language", NULL, 0);
333  if (lang) {
334  char *escaped;
335  int ret = av_escape(&escaped, lang->value, NULL, AV_ESCAPE_MODE_XML,
337  if (ret < 0)
338  return ret;
339  avio_printf(pb, " lang=\"%s\"", escaped);
340  av_free(escaped);
341  }
342 
343  if (par->codec_type == AVMEDIA_TYPE_VIDEO && width_in_as)
344  avio_printf(pb, " width=\"%d\"", par->width);
345  if (par->codec_type == AVMEDIA_TYPE_VIDEO && height_in_as)
346  avio_printf(pb, " height=\"%d\"", par->height);
347  if (par->codec_type == AVMEDIA_TYPE_AUDIO && sample_rate_in_as)
348  avio_printf(pb, " audioSamplingRate=\"%d\"", par->sample_rate);
349 
350  avio_printf(pb, " bitstreamSwitching=\"%s\"",
351  boolean[bitstream_switching(s, as)]);
352  avio_printf(pb, " subsegmentAlignment=\"%s\"",
353  boolean[w->is_live || subsegment_alignment(s, as)]);
354 
355  for (i = 0; i < as->nb_streams; i++) {
356  AVDictionaryEntry *kf = av_dict_get(s->streams[as->streams[i]]->metadata,
357  CLUSTER_KEYFRAME, NULL, 0);
358  if (!w->is_live && (!kf || !strncmp(kf->value, "0", 1))) subsegmentStartsWithSAP = 0;
359  }
360  avio_printf(pb, " subsegmentStartsWithSAP=\"%d\"", subsegmentStartsWithSAP);
361  avio_printf(pb, ">\n");
362 
363  if (w->is_live) {
364  AVDictionaryEntry *filename =
365  av_dict_get(w->escaped_metadata[st->index], FILENAME, NULL, 0);
366  char *underscore_pos, *period_pos;
367  int ret;
368  if (!filename)
369  return AVERROR(EINVAL);
370  ret = split_filename(filename->value, &underscore_pos, &period_pos);
371  if (ret) return ret;
372  *underscore_pos = '\0';
373  avio_printf(pb, "<ContentComponent id=\"1\" type=\"%s\"/>\n",
374  par->codec_type == AVMEDIA_TYPE_VIDEO ? "video" : "audio");
375  avio_printf(pb, "<SegmentTemplate");
376  avio_printf(pb, " timescale=\"1000\"");
377  avio_printf(pb, " duration=\"%d\"", w->chunk_duration);
378  avio_printf(pb, " media=\"%s_$RepresentationID$_$Number$.chk\"",
379  filename->value);
380  avio_printf(pb, " startNumber=\"%d\"", w->chunk_start_index);
381  avio_printf(pb, " initialization=\"%s_$RepresentationID$.hdr\"",
382  filename->value);
383  avio_printf(pb, "/>\n");
384  *underscore_pos = '_';
385  }
386 
387  for (i = 0; i < as->nb_streams; i++) {
388  char buf[25], *representation_id = buf, *underscore_pos, *period_pos;
389  AVStream *st = s->streams[as->streams[i]];
390  int ret;
391  if (w->is_live) {
392  AVDictionaryEntry *filename =
393  av_dict_get(w->escaped_metadata[st->index], FILENAME, NULL, 0);
394  if (!filename)
395  return AVERROR(EINVAL);
396  ret = split_filename(filename->value, &underscore_pos, &period_pos);
397  if (ret < 0)
398  return ret;
399  representation_id = underscore_pos + 1;
400  *period_pos = '\0';
401  } else {
402  snprintf(buf, sizeof(buf), "%d", w->representation_id++);
403  }
404  ret = write_representation(s, st, representation_id, !width_in_as,
405  !height_in_as, !sample_rate_in_as);
406  if (ret) return ret;
407  if (w->is_live)
408  *period_pos = '.';
409  }
410  avio_printf(s->pb, "</AdaptationSet>\n");
411  return 0;
412 }
413 
415 {
416  WebMDashMuxContext *w = s->priv_data;
417  char *p = w->adaptation_sets;
418  char *q;
419  enum { new_set, parsed_id, parsing_streams } state;
420  if (!w->adaptation_sets) {
421  av_log(s, AV_LOG_ERROR, "The 'adaptation_sets' option must be set.\n");
422  return AVERROR(EINVAL);
423  }
424  // syntax id=0,streams=0,1,2 id=1,streams=3,4 and so on
425  state = new_set;
426  while (1) {
427  if (*p == '\0') {
428  if (state == new_set)
429  break;
430  else
431  return AVERROR(EINVAL);
432  } else if (state == new_set && *p == ' ') {
433  p++;
434  continue;
435  } else if (state == new_set && !strncmp(p, "id=", 3)) {
436  void *mem = av_realloc(w->as, sizeof(*w->as) * (w->nb_as + 1));
437  const char *comma;
438  if (mem == NULL)
439  return AVERROR(ENOMEM);
440  w->as = mem;
441  ++w->nb_as;
442  w->as[w->nb_as - 1].nb_streams = 0;
443  w->as[w->nb_as - 1].streams = NULL;
444  p += 3; // consume "id="
445  q = w->as[w->nb_as - 1].id;
446  comma = strchr(p, ',');
447  if (!comma || comma - p >= sizeof(w->as[w->nb_as - 1].id)) {
448  av_log(s, AV_LOG_ERROR, "'id' in 'adaptation_sets' is malformed.\n");
449  return AVERROR(EINVAL);
450  }
451  while (*p != ',') *q++ = *p++;
452  *q = 0;
453  p++;
454  state = parsed_id;
455  } else if (state == parsed_id && !strncmp(p, "streams=", 8)) {
456  p += 8; // consume "streams="
457  state = parsing_streams;
458  } else if (state == parsing_streams) {
459  struct AdaptationSet *as = &w->as[w->nb_as - 1];
460  int64_t num;
461  int ret = av_reallocp_array(&as->streams, ++as->nb_streams,
462  sizeof(*as->streams));
463  if (ret < 0)
464  return ret;
465  num = strtoll(p, &q, 10);
466  if (!av_isdigit(*p) || (*q != ' ' && *q != '\0' && *q != ',') ||
467  num < 0 || num >= s->nb_streams) {
468  av_log(s, AV_LOG_ERROR, "Invalid value for 'streams' in adapation_sets.\n");
469  return AVERROR(EINVAL);
470  }
471  as->streams[as->nb_streams - 1] = num;
472  if (*q == '\0') break;
473  if (*q == ' ') state = new_set;
474  p = ++q;
475  } else {
476  return -1;
477  }
478  }
479  return 0;
480 }
481 
483 {
484  int i;
485  double start = 0.0;
486  int ret;
487  WebMDashMuxContext *w = s->priv_data;
488 
489  for (unsigned i = 0; i < s->nb_streams; i++) {
490  enum AVCodecID codec_id = s->streams[i]->codecpar->codec_id;
493  return AVERROR(EINVAL);
494  }
495 
496  w->escaped_metadata = av_calloc(s->nb_streams, sizeof(*w->escaped_metadata));
497  if (!w->escaped_metadata)
498  return AVERROR(ENOMEM);
499  for (i = 0; i < s->nb_streams; i++) {
500  const AVDictionaryEntry *e = NULL;
501  while ((e = av_dict_get(s->streams[i]->metadata, "", e, AV_DICT_IGNORE_SUFFIX))) {
502  char *value;
505  if (ret < 0)
506  goto fail;
507  ret = av_dict_set(&w->escaped_metadata[i], e->key, value,
509  if (ret < 0)
510  goto fail;
511  }
512  }
513 
514  ret = parse_adaptation_sets(s);
515  if (ret < 0) {
516  goto fail;
517  }
518  ret = write_header(s);
519  if (ret < 0) {
520  goto fail;
521  }
522  avio_printf(s->pb, "<Period id=\"0\"");
523  avio_printf(s->pb, " start=\"PT%gS\"", start);
524  if (!w->is_live) {
525  avio_printf(s->pb, " duration=\"PT%gS\"", get_duration(s));
526  }
527  avio_printf(s->pb, " >\n");
528 
529  for (i = 0; i < w->nb_as; i++) {
530  ret = write_adaptation_set(s, i);
531  if (ret < 0) {
532  goto fail;
533  }
534  }
535 
536  avio_printf(s->pb, "</Period>\n");
537  write_footer(s);
538 fail:
540  for (i = 0; i < s->nb_streams; i++)
541  av_dict_free(&w->escaped_metadata[i]);
542  av_freep(&w->escaped_metadata);
543  return ret < 0 ? ret : 0;
544 }
545 
547 {
548  return AVERROR_EOF;
549 }
550 
551 #define OFFSET(x) offsetof(WebMDashMuxContext, x)
552 static const AVOption options[] = {
553  { "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 },
554  { "live", "create a live stream manifest", OFFSET(is_live), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM },
555  { "chunk_start_index", "start index of the chunk", OFFSET(chunk_start_index), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
556  { "chunk_duration_ms", "duration of each chunk (in milliseconds)", OFFSET(chunk_duration), AV_OPT_TYPE_INT, {.i64 = 1000}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
557  { "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, AV_OPT_FLAG_ENCODING_PARAM },
558  { "time_shift_buffer_depth", "Smallest time (in seconds) shifting buffer for which any Representation is guaranteed to be available.", OFFSET(time_shift_buffer_depth), AV_OPT_TYPE_DOUBLE, { .dbl = 60.0 }, 1.0, DBL_MAX, AV_OPT_FLAG_ENCODING_PARAM },
559  { "minimum_update_period", "Minimum Update Period (in seconds) of the manifest.", OFFSET(minimum_update_period), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
560  { NULL },
561 };
562 
563 static const AVClass webm_dash_class = {
564  .class_name = "WebM DASH Manifest muxer",
565  .item_name = av_default_item_name,
566  .option = options,
567  .version = LIBAVUTIL_VERSION_INT,
568 };
569 
571  .name = "webm_dash_manifest",
572  .long_name = NULL_IF_CONFIG_SMALL("WebM DASH Manifest"),
573  .mime_type = "application/xml",
574  .extensions = "xml",
575  .priv_data_size = sizeof(WebMDashMuxContext),
578  .priv_class = &webm_dash_class,
579 };
Main libavformat public API header.
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1380
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
#define s(width, name)
Definition: cbs_vp9.c:257
static struct @322 state
#define fail()
Definition: checkasm.h:133
#define NULL
Definition: coverity.c:32
long long int64_t
Definition: coverity.c:34
#define max(a, b)
Definition: cuda_runtime.h:33
Public dictionary API.
double value
Definition: eval.c:100
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:740
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:46
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3501
@ AV_CODEC_ID_VORBIS
Definition: codec_id.h:429
@ AV_CODEC_ID_VP8
Definition: codec_id.h:189
@ AV_CODEC_ID_VP9
Definition: codec_id.h:217
@ AV_CODEC_ID_OPUS
Definition: codec_id.h:484
#define AV_DICT_MULTIKEY
Allow to store several equal keys in the dictionary.
Definition: dict.h:79
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:199
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
Definition: dict.h:70
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
Definition: dict.h:74
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:134
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array through a pointer to a pointer.
Definition: mem.c:206
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
int av_escape(char **dst, const char *src, const char *special_chars, enum AVEscapeMode mode, int flags)
Escape string in src, and put the escaped string in an allocated string in *dst, which must be freed ...
Definition: avstring.c:338
#define AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES
Within AV_ESCAPE_MODE_XML, additionally escape double quotes for double quoted attributes.
Definition: avstring.h:357
static av_const int av_isdigit(int c)
Locale-independent conversion of ASCII isdigit.
Definition: avstring.h:211
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
Definition: avstring.c:34
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.
Definition: avstring.c:83
@ AV_ESCAPE_MODE_XML
Use XML non-markup character data escaping.
Definition: avstring.h:327
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
int i
Definition: input.c:407
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
uint8_t w
Definition: llviddspenc.c:39
#define CUES_START
Definition: matroska.h:376
#define CUES_END
Definition: matroska.h:377
#define FILENAME
Definition: matroska.h:378
#define CLUSTER_KEYFRAME
Definition: matroska.h:381
#define DURATION
Definition: matroska.h:380
#define BANDWIDTH
Definition: matroska.h:379
#define INITIALIZATION_RANGE
Definition: matroska.h:375
#define TRACK_NUMBER
Definition: matroska.h:383
#define CUE_TIMESTAMPS
Definition: matroska.h:382
AVOptions.
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:278
#define snprintf
Definition: snprintf.h:34
Describe the class of an AVClass context structure.
Definition: log.h:67
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
const char * name
Name of the codec described by this descriptor.
Definition: codec_desc.h:46
This struct describes the properties of an encoded stream.
Definition: codec_par.h:52
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:78
int width
Video only.
Definition: codec_par.h:126
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:74
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
int sample_rate
Audio only.
Definition: codec_par.h:170
char * key
Definition: dict.h:82
char * value
Definition: dict.h:83
Format I/O context.
Definition: avformat.h:1232
Bytestream IO Context.
Definition: avio.h:161
AVOption.
Definition: opt.h:248
const char * name
Definition: avformat.h:491
This structure stores compressed data.
Definition: packet.h:346
Stream structure.
Definition: avformat.h:873
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1038
AVDictionary * metadata
Definition: avformat.h:937
int index
stream index in AVFormatContext
Definition: avformat.h:874
int nb_streams
Definition: dashenc.c:94
char * adaptation_sets
Definition: webmdashenc.c:49
double time_shift_buffer_depth
Definition: webmdashenc.c:57
AdaptationSet * as
Definition: webmdashenc.c:50
AVDictionary ** escaped_metadata
Definition: webmdashenc.c:59
#define av_free(p)
#define av_freep(p)
#define av_log(a,...)
int64_t duration
Definition: movenc.c:64
AVPacket * pkt
Definition: movenc.c:59
#define gmtime_r
Definition: time_internal.h:34
enum AVCodecID codec_id
Definition: vaapi_decode.c:374
static const AVClass webm_dash_class
Definition: webmdashenc.c:563
static int check_matching_width(AVFormatContext *s, const AdaptationSet *as)
Definition: webmdashenc.c:229
static const AVOption options[]
Definition: webmdashenc.c:552
static int check_matching_sample_rate(AVFormatContext *s, const AdaptationSet *as)
Definition: webmdashenc.c:257
static int write_representation(AVFormatContext *s, AVStream *st, char *id, int output_width, int output_height, int output_sample_rate)
Definition: webmdashenc.c:171
static int check_matching_height(AVFormatContext *s, const AdaptationSet *as)
Definition: webmdashenc.c:243
static void free_adaptation_sets(AVFormatContext *s)
Definition: webmdashenc.c:268
static int split_filename(char *filename, char **underscore_pos, char **period_pos)
Definition: webmdashenc.c:288
static void write_footer(AVFormatContext *s)
Definition: webmdashenc.c:123
static double get_duration(AVFormatContext *s)
Definition: webmdashenc.c:67
static int bitstream_switching(AVFormatContext *s, const AdaptationSet *as)
Definition: webmdashenc.c:142
static int webm_dash_manifest_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: webmdashenc.c:546
static int write_header(AVFormatContext *s)
Definition: webmdashenc.c:80
static int subsegment_alignment(AVFormatContext *s, const AdaptationSet *as)
Definition: webmdashenc.c:128
AVOutputFormat ff_webm_dash_manifest_muxer
Definition: webmdashenc.c:570
static int parse_adaptation_sets(AVFormatContext *s)
Definition: webmdashenc.c:414
#define OFFSET(x)
Definition: webmdashenc.c:551
static int webm_dash_manifest_write_header(AVFormatContext *s)
Definition: webmdashenc.c:482
static const char * get_codec_name(int codec_id)
Definition: webmdashenc.c:62
static int write_adaptation_set(AVFormatContext *s, int as_index)
Definition: webmdashenc.c:303