FFmpeg
matroskaenc.c
Go to the documentation of this file.
1 /*
2  * Matroska muxer
3  * Copyright (c) 2007 David Conrad
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 #include <stdint.h>
23 
24 #include "config.h"
25 
26 #include "av1.h"
27 #include "avc.h"
28 #include "hevc.h"
29 #include "avformat.h"
30 #include "avio_internal.h"
31 #include "avlanguage.h"
32 #include "dovi_isom.h"
33 #include "flacenc.h"
34 #include "internal.h"
35 #include "isom.h"
36 #include "matroska.h"
37 #include "riff.h"
38 #include "vorbiscomment.h"
39 #include "wv.h"
40 
41 #include "libavutil/avstring.h"
43 #include "libavutil/crc.h"
44 #include "libavutil/dict.h"
45 #include "libavutil/intfloat.h"
46 #include "libavutil/intreadwrite.h"
47 #include "libavutil/lfg.h"
49 #include "libavutil/mathematics.h"
50 #include "libavutil/opt.h"
51 #include "libavutil/parseutils.h"
52 #include "libavutil/random_seed.h"
53 #include "libavutil/rational.h"
54 #include "libavutil/samplefmt.h"
55 #include "libavutil/stereo3d.h"
56 
57 #include "libavcodec/xiph.h"
58 #include "libavcodec/mpeg4audio.h"
59 
60 /* Level 1 elements we create a SeekHead entry for:
61  * Info, Tracks, Chapters, Attachments, Tags (potentially twice) and Cues */
62 #define MAX_SEEKHEAD_ENTRIES 7
63 
64 #define MODE_MATROSKAv2 0x01
65 #define MODE_WEBM 0x02
66 
67 #define IS_WEBM(mkv) (CONFIG_WEBM_MUXER && CONFIG_MATROSKA_MUXER ? \
68  ((mkv)->mode == MODE_WEBM) : CONFIG_WEBM_MUXER)
69 #define IS_SEEKABLE(pb, mkv) (((pb)->seekable & AVIO_SEEKABLE_NORMAL) && \
70  !(mkv)->is_live)
71 
72 enum {
76 };
77 
78 typedef struct ebml_master {
79  int64_t pos; ///< absolute offset in the containing AVIOContext where the master's elements start
80  int sizebytes; ///< how many bytes were reserved for the size
81 } ebml_master;
82 
83 typedef struct ebml_stored_master {
85  int64_t pos;
87 
88 typedef struct mkv_seekhead_entry {
89  uint32_t elementid;
90  uint64_t segmentpos;
92 
93 typedef struct mkv_seekhead {
94  int64_t filepos;
98 } mkv_seekhead;
99 
100 typedef struct mkv_cuepoint {
101  uint64_t pts;
103  int64_t cluster_pos; ///< offset of the cluster containing the block relative to the segment
104  int64_t relative_pos; ///< relative offset from the position of the cluster containing the block
105  int64_t duration; ///< duration of the block according to time base
106 } mkv_cuepoint;
107 
108 typedef struct mkv_cues {
111 } mkv_cues;
112 
113 typedef struct mkv_track {
115  int has_cue;
116  uint64_t uid;
117  unsigned track_num;
121  int64_t last_timestamp;
122  int64_t duration;
125  int64_t ts_offset;
126 } mkv_track;
127 
128 typedef struct MatroskaMuxContext {
129  const AVClass *class;
130  int mode;
134  int64_t segment_offset;
136  int64_t cluster_pos; ///< file offset of the current Cluster
137  int64_t cluster_pts;
139  int64_t duration;
143  int64_t cues_pos;
144 
146 
147  unsigned nb_attachments;
149 
152 
157  int is_live;
158 
159  int is_dash;
164 
165  uint32_t segment_uid[4];
167 
168 /** 2 bytes * 7 for EBML IDs, 7 1-byte EBML lengths, 6 1-byte uint,
169  * 8 byte for "matroska" doctype string */
170 #define MAX_EBML_HEADER_SIZE 35
171 
172 /** 2 bytes * 3 for EBML IDs, 3 1-byte EBML lengths, 8 bytes for 64 bit
173  * offset, 4 bytes for target EBML ID */
174 #define MAX_SEEKENTRY_SIZE 21
175 
176 /** 4 * (1-byte EBML ID, 1-byte EBML size, 8-byte uint max) */
177 #define MAX_CUETRACKPOS_SIZE 40
178 
179 /** Seek preroll value for opus */
180 #define OPUS_SEEK_PREROLL 80000000
181 
182 static int ebml_id_size(uint32_t id)
183 {
184  return (av_log2(id) + 7U) / 8;
185 }
186 
187 static void put_ebml_id(AVIOContext *pb, uint32_t id)
188 {
189  int i = ebml_id_size(id);
190  while (i--)
191  avio_w8(pb, (uint8_t)(id >> (i * 8)));
192 }
193 
194 /**
195  * Write an EBML size meaning "unknown size".
196  *
197  * @param bytes The number of bytes the size should occupy (maximum: 8).
198  */
199 static void put_ebml_size_unknown(AVIOContext *pb, int bytes)
200 {
201  av_assert0(bytes <= 8);
202  avio_w8(pb, 0x1ff >> bytes);
203  if (av_builtin_constant_p(bytes) && bytes == 1)
204  return;
205  ffio_fill(pb, 0xff, bytes - 1);
206 }
207 
208 /**
209  * Returns how many bytes are needed to represent a number
210  * as EBML variable length integer.
211  */
212 static int ebml_num_size(uint64_t num)
213 {
214  int bytes = 0;
215  do {
216  bytes++;
217  } while (num >>= 7);
218  return bytes;
219 }
220 
221 /**
222  * Calculate how many bytes are needed to represent the length field
223  * of an EBML element whose payload has a given length.
224  */
225 static int ebml_length_size(uint64_t length)
226 {
227  return ebml_num_size(length + 1);
228 }
229 
230 /**
231  * Write a number as EBML variable length integer on `bytes` bytes.
232  * `bytes` is taken literally without checking.
233  */
234 static void put_ebml_num(AVIOContext *pb, uint64_t num, int bytes)
235 {
236  num |= 1ULL << bytes * 7;
237  for (int i = bytes - 1; i >= 0; i--)
238  avio_w8(pb, (uint8_t)(num >> i * 8));
239 }
240 
241 /**
242  * Write a length as EBML variable length integer.
243  *
244  * @param bytes The number of bytes that need to be used to write the number.
245  * If zero, the minimal number of bytes will be used.
246  */
247 static void put_ebml_length(AVIOContext *pb, uint64_t length, int bytes)
248 {
249  int needed_bytes = ebml_length_size(length);
250 
251  // sizes larger than this are currently undefined in EBML
252  av_assert0(length < (1ULL << 56) - 1);
253 
254  if (bytes == 0)
255  bytes = needed_bytes;
256  // The bytes needed to write the given size must not exceed
257  // the bytes that we ought to use.
258  av_assert0(bytes >= needed_bytes);
259  put_ebml_num(pb, length, bytes);
260 }
261 
262 /**
263  * Write a (random) UID with fixed size to make the output more deterministic
264  */
265 static void put_ebml_uid(AVIOContext *pb, uint32_t elementid, uint64_t uid)
266 {
267  put_ebml_id(pb, elementid);
268  put_ebml_length(pb, 8, 0);
269  avio_wb64(pb, uid);
270 }
271 
272 static void put_ebml_uint(AVIOContext *pb, uint32_t elementid, uint64_t val)
273 {
274  int i, bytes = 1;
275  uint64_t tmp = val;
276  while (tmp >>= 8)
277  bytes++;
278 
279  put_ebml_id(pb, elementid);
280  put_ebml_length(pb, bytes, 0);
281  for (i = bytes - 1; i >= 0; i--)
282  avio_w8(pb, (uint8_t)(val >> i * 8));
283 }
284 
285 static void put_ebml_sint(AVIOContext *pb, uint32_t elementid, int64_t val)
286 {
287  int i, bytes = 1;
288  uint64_t tmp = 2*(val < 0 ? val^-1 : val);
289 
290  while (tmp >>= 8)
291  bytes++;
292 
293  put_ebml_id(pb, elementid);
294  put_ebml_length(pb, bytes, 0);
295  for (i = bytes - 1; i >= 0; i--)
296  avio_w8(pb, (uint8_t)(val >> i * 8));
297 }
298 
299 static void put_ebml_float(AVIOContext *pb, uint32_t elementid, double val)
300 {
301  put_ebml_id(pb, elementid);
302  put_ebml_length(pb, 8, 0);
304 }
305 
306 static void put_ebml_binary(AVIOContext *pb, uint32_t elementid,
307  const void *buf, int size)
308 {
309  put_ebml_id(pb, elementid);
310  put_ebml_length(pb, size, 0);
311  avio_write(pb, buf, size);
312 }
313 
314 static void put_ebml_string(AVIOContext *pb, uint32_t elementid,
315  const char *str)
316 {
317  put_ebml_binary(pb, elementid, str, strlen(str));
318 }
319 
320 /**
321  * Write a void element of a given size. Useful for reserving space in
322  * the file to be written to later.
323  *
324  * @param size The number of bytes to reserve, which must be at least 2.
325  */
326 static void put_ebml_void(AVIOContext *pb, int size)
327 {
328  av_assert0(size >= 2);
329 
331  // we need to subtract the length needed to store the size from the
332  // size we need to reserve so 2 cases, we use 8 bytes to store the
333  // size if possible, 1 byte otherwise
334  if (size < 10) {
335  size -= 2;
336  put_ebml_length(pb, size, 0);
337  } else {
338  size -= 9;
339  put_ebml_length(pb, size, 8);
340  }
341  ffio_fill(pb, 0, size);
342 }
343 
344 static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid,
345  uint64_t expectedsize)
346 {
347  int bytes = expectedsize ? ebml_length_size(expectedsize) : 8;
348 
349  put_ebml_id(pb, elementid);
350  put_ebml_size_unknown(pb, bytes);
351  return (ebml_master) { avio_tell(pb), bytes };
352 }
353 
355 {
356  int64_t pos = avio_tell(pb);
357 
358  if (avio_seek(pb, master.pos - master.sizebytes, SEEK_SET) < 0)
359  return;
360  put_ebml_length(pb, pos - master.pos, master.sizebytes);
361  avio_seek(pb, pos, SEEK_SET);
362 }
363 
364 static void mkv_add_seekhead_entry(MatroskaMuxContext *mkv, uint32_t elementid,
365  uint64_t filepos)
366 {
367  mkv_seekhead *seekhead = &mkv->seekhead;
368 
370 
371  seekhead->entries[seekhead->num_entries].elementid = elementid;
372  seekhead->entries[seekhead->num_entries++].segmentpos = filepos - mkv->segment_offset;
373 }
374 
376 {
377  int ret;
378 
379  if (!*dyn_cp && (ret = avio_open_dyn_buf(dyn_cp)) < 0)
380  return ret;
381 
382  if (mkv->write_crc)
383  put_ebml_void(*dyn_cp, 6); /* Reserve space for CRC32 so position/size calculations using avio_tell() take it into account */
384 
385  return 0;
386 }
387 
389  MatroskaMuxContext *mkv, uint32_t id,
390  int length_size, int keep_buffer,
391  int add_seekentry)
392 {
393  uint8_t *buf, crc[4];
394  int ret, size, skip = 0;
395 
396  size = avio_get_dyn_buf(*dyn_cp, &buf);
397  if ((ret = (*dyn_cp)->error) < 0)
398  goto fail;
399 
400  if (add_seekentry)
401  mkv_add_seekhead_entry(mkv, id, avio_tell(pb));
402 
403  put_ebml_id(pb, id);
404  put_ebml_length(pb, size, length_size);
405  if (mkv->write_crc) {
406  skip = 6; /* Skip reserved 6-byte long void element from the dynamic buffer. */
407  AV_WL32(crc, av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), UINT32_MAX, buf + skip, size - skip) ^ UINT32_MAX);
408  put_ebml_binary(pb, EBML_ID_CRC32, crc, sizeof(crc));
409  }
410  avio_write(pb, buf + skip, size - skip);
411 
412 fail:
413  if (keep_buffer) {
414  ffio_reset_dyn_buf(*dyn_cp);
415  } else {
416  ffio_free_dyn_buf(dyn_cp);
417  }
418  return ret;
419 }
420 
421 /**
422  * Output EBML master. Keep the buffer if seekable, allowing for later updates.
423  * Furthermore always add a SeekHead Entry for this element.
424  */
426  ebml_stored_master *elem,
427  MatroskaMuxContext *mkv, uint32_t id)
428 {
429  if (IS_SEEKABLE(pb, mkv)) {
430  uint8_t *buf;
431  int size = avio_get_dyn_buf(elem->bc, &buf);
432 
433  if (elem->bc->error < 0)
434  return elem->bc->error;
435 
436  elem->pos = avio_tell(pb);
437  mkv_add_seekhead_entry(mkv, id, elem->pos);
438 
439  put_ebml_id(pb, id);
440  put_ebml_length(pb, size, 0);
441  avio_write(pb, buf, size);
442 
443  return 0;
444  } else
445  return end_ebml_master_crc32(pb, &elem->bc, mkv, id, 0, 0, 1);
446 }
447 
448 static void put_xiph_size(AVIOContext *pb, int size)
449 {
450  ffio_fill(pb, 255, size / 255);
451  avio_w8(pb, size % 255);
452 }
453 
454 /**
455  * Free the members allocated in the mux context.
456  */
458 {
459  MatroskaMuxContext *mkv = s->priv_data;
460 
462  ffio_free_dyn_buf(&mkv->info.bc);
463  ffio_free_dyn_buf(&mkv->track.bc);
464  ffio_free_dyn_buf(&mkv->tags.bc);
465 
466  av_freep(&mkv->cues.entries);
467  av_freep(&mkv->tracks);
468 }
469 
470 /**
471  * Initialize the SeekHead element to be ready to index level 1 Matroska
472  * elements. Enough space to write MAX_SEEKHEAD_ENTRIES SeekHead entries
473  * will be reserved at the current file location.
474  */
476 {
477  mkv->seekhead.filepos = avio_tell(pb);
478  // 21 bytes max for a Seek entry, 6 bytes max for the SeekHead ID
479  // and size, 6 bytes for a CRC32 element, and 2 bytes to guarantee
480  // that an EBML void element will fit afterwards
483 }
484 
485 /**
486  * Write the SeekHead to the file at the location reserved for it
487  * and seek to destpos afterwards. When error_on_seek_failure
488  * is not set, failure to seek to the position designated for the
489  * SeekHead is not considered an error and it is presumed that
490  * destpos is the current position; failure to seek to destpos
491  * afterwards is always an error.
492  *
493  * @return 0 on success, < 0 on error.
494  */
496  int error_on_seek_failure, int64_t destpos)
497 {
498  AVIOContext *dyn_cp = NULL;
499  mkv_seekhead *seekhead = &mkv->seekhead;
500  int64_t remaining, ret64;
501  int i, ret;
502 
503  if ((ret64 = avio_seek(pb, seekhead->filepos, SEEK_SET)) < 0)
504  return error_on_seek_failure ? ret64 : 0;
505 
506  ret = start_ebml_master_crc32(&dyn_cp, mkv);
507  if (ret < 0)
508  return ret;
509 
510  for (i = 0; i < seekhead->num_entries; i++) {
511  mkv_seekhead_entry *entry = &seekhead->entries[i];
514 
516  put_ebml_length(dyn_cp, ebml_id_size(entry->elementid), 0);
517  put_ebml_id(dyn_cp, entry->elementid);
518 
520  end_ebml_master(dyn_cp, seekentry);
521  }
522  ret = end_ebml_master_crc32(pb, &dyn_cp, mkv,
523  MATROSKA_ID_SEEKHEAD, 0, 0, 0);
524  if (ret < 0)
525  return ret;
526 
527  remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb);
528  put_ebml_void(pb, remaining);
529 
530  if ((ret64 = avio_seek(pb, destpos, SEEK_SET)) < 0)
531  return ret64;
532 
533  return 0;
534 }
535 
536 static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int stream, int64_t ts,
537  int64_t cluster_pos, int64_t relative_pos, int64_t duration)
538 {
539  mkv_cues *cues = &mkv->cues;
540  mkv_cuepoint *entries = cues->entries;
541  unsigned idx = cues->num_entries;
542 
543  if (ts < 0)
544  return 0;
545 
546  entries = av_realloc_array(entries, cues->num_entries + 1, sizeof(mkv_cuepoint));
547  if (!entries)
548  return AVERROR(ENOMEM);
549  cues->entries = entries;
550 
551  /* Make sure the cues entries are sorted by pts. */
552  while (idx > 0 && entries[idx - 1].pts > ts)
553  idx--;
554  memmove(&entries[idx + 1], &entries[idx],
555  (cues->num_entries - idx) * sizeof(entries[0]));
556 
557  entries[idx].pts = ts;
558  entries[idx].stream_idx = stream;
559  entries[idx].cluster_pos = cluster_pos - mkv->segment_offset;
560  entries[idx].relative_pos = relative_pos;
561  entries[idx].duration = duration;
562 
563  cues->num_entries++;
564 
565  return 0;
566 }
567 
568 static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp,
569  mkv_cues *cues, mkv_track *tracks, int num_tracks)
570 {
571  AVIOContext *cuepoint;
572  int ret;
573 
574  ret = avio_open_dyn_buf(&cuepoint);
575  if (ret < 0)
576  return ret;
577 
578  for (mkv_cuepoint *entry = cues->entries, *end = entry + cues->num_entries;
579  entry < end;) {
580  uint64_t pts = entry->pts;
581  uint8_t *buf;
582  int size;
583 
585 
586  // put all the entries from different tracks that have the exact same
587  // timestamp into the same CuePoint
588  for (int j = 0; j < num_tracks; j++)
589  tracks[j].has_cue = 0;
590  do {
591  ebml_master track_positions;
592  int idx = entry->stream_idx;
593 
594  av_assert0(idx >= 0 && idx < num_tracks);
595  if (tracks[idx].has_cue && streams[idx]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE)
596  continue;
597  tracks[idx].has_cue = 1;
599  put_ebml_uint(cuepoint, MATROSKA_ID_CUETRACK , tracks[idx].track_num);
600  put_ebml_uint(cuepoint, MATROSKA_ID_CUECLUSTERPOSITION , entry->cluster_pos);
601  put_ebml_uint(cuepoint, MATROSKA_ID_CUERELATIVEPOSITION, entry->relative_pos);
602  if (entry->duration > 0)
603  put_ebml_uint(cuepoint, MATROSKA_ID_CUEDURATION , entry->duration);
604  end_ebml_master(cuepoint, track_positions);
605  } while (++entry < end && entry->pts == pts);
606  size = avio_get_dyn_buf(cuepoint, &buf);
607  if ((ret = cuepoint->error) < 0)
608  break;
610  ffio_reset_dyn_buf(cuepoint);
611  }
612  ffio_free_dyn_buf(&cuepoint);
613 
614  return ret;
615 }
616 
618  const AVCodecParameters *par)
619 {
620  const uint8_t *header_start[3];
621  int header_len[3];
622  int first_header_size;
623  int err, j;
624 
625  if (par->codec_id == AV_CODEC_ID_VORBIS)
626  first_header_size = 30;
627  else
628  first_header_size = 42;
629 
631  first_header_size, header_start, header_len);
632  if (err < 0) {
633  av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n");
634  return err;
635  }
636 
637  avio_w8(pb, 2); // number packets - 1
638  for (j = 0; j < 2; j++) {
639  put_xiph_size(pb, header_len[j]);
640  }
641  for (j = 0; j < 3; j++)
642  avio_write(pb, header_start[j], header_len[j]);
643 
644  return 0;
645 }
646 
647 #if CONFIG_MATROSKA_MUXER
648 static int put_wv_codecpriv(AVIOContext *pb, const AVCodecParameters *par)
649 {
650  if (par->extradata && par->extradata_size == 2)
651  avio_write(pb, par->extradata, 2);
652  else
653  avio_wl16(pb, 0x410); // fallback to the most recent version
654  return 0;
655 }
656 
657 static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb,
658  const AVCodecParameters *par)
659 {
660  int write_comment = (par->channel_layout &&
661  !(par->channel_layout & ~0x3ffffULL) &&
663  int ret = ff_flac_write_header(pb, par->extradata, par->extradata_size,
664  !write_comment);
665 
666  if (ret < 0)
667  return ret;
668 
669  if (write_comment) {
670  const char *vendor = (s->flags & AVFMT_FLAG_BITEXACT) ?
671  "Lavf" : LIBAVFORMAT_IDENT;
672  AVDictionary *dict = NULL;
673  uint8_t buf[32];
674  int64_t len;
675 
676  snprintf(buf, sizeof(buf), "0x%"PRIx64, par->channel_layout);
677  av_dict_set(&dict, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0);
678 
679  len = ff_vorbiscomment_length(dict, vendor, NULL, 0);
680  av_assert1(len < (1 << 24) - 4);
681 
682  avio_w8(pb, 0x84);
683  avio_wb24(pb, len);
684 
685  ff_vorbiscomment_write(pb, dict, vendor, NULL, 0);
686 
687  av_dict_free(&dict);
688  }
689 
690  return 0;
691 }
692 
693 static int get_aac_sample_rates(AVFormatContext *s, MatroskaMuxContext *mkv,
694  const uint8_t *extradata, int extradata_size,
695  int *sample_rate, int *output_sample_rate)
696 {
697  MPEG4AudioConfig mp4ac;
698  int ret;
699 
700  ret = avpriv_mpeg4audio_get_config2(&mp4ac, extradata, extradata_size, 1, s);
701  /* Don't abort if the failure is because of missing extradata. Assume in that
702  * case a bitstream filter will provide the muxer with the extradata in the
703  * first packet.
704  * Abort however if s->pb is not seekable, as we would not be able to seek back
705  * to write the sample rate elements once the extradata shows up, anyway. */
706  if (ret < 0 && (extradata_size || !IS_SEEKABLE(s->pb, mkv))) {
708  "Error parsing AAC extradata, unable to determine samplerate.\n");
709  return AVERROR(EINVAL);
710  }
711 
712  if (ret < 0) {
713  /* This will only happen when this function is called while writing the
714  * header and no extradata is available. The space for this element has
715  * to be reserved for when this function is called again after the
716  * extradata shows up in the first packet, as there's no way to know if
717  * output_sample_rate will be different than sample_rate or not. */
718  *output_sample_rate = *sample_rate;
719  } else {
720  *sample_rate = mp4ac.sample_rate;
721  *output_sample_rate = mp4ac.ext_sample_rate;
722  }
723  return 0;
724 }
725 #endif
726 
728  const AVCodecParameters *par,
729  AVIOContext *dyn_cp)
730 {
731  switch (par->codec_id) {
732  case AV_CODEC_ID_VORBIS:
733  case AV_CODEC_ID_THEORA:
734  return put_xiph_codecpriv(s, dyn_cp, par);
735  case AV_CODEC_ID_AV1:
736  if (par->extradata_size)
737  return ff_isom_write_av1c(dyn_cp, par->extradata,
738  par->extradata_size);
739  else
740  put_ebml_void(pb, 4 + 3);
741  break;
742 #if CONFIG_MATROSKA_MUXER
743  case AV_CODEC_ID_FLAC:
744  return put_flac_codecpriv(s, dyn_cp, par);
745  case AV_CODEC_ID_WAVPACK:
746  return put_wv_codecpriv(dyn_cp, par);
747  case AV_CODEC_ID_H264:
748  return ff_isom_write_avcc(dyn_cp, par->extradata,
749  par->extradata_size);
750  case AV_CODEC_ID_HEVC:
751  return ff_isom_write_hvcc(dyn_cp, par->extradata,
752  par->extradata_size, 0);
753  case AV_CODEC_ID_ALAC:
754  if (par->extradata_size < 36) {
756  "Invalid extradata found, ALAC expects a 36-byte "
757  "QuickTime atom.");
758  return AVERROR_INVALIDDATA;
759  } else
760  avio_write(dyn_cp, par->extradata + 12,
761  par->extradata_size - 12);
762  break;
763  case AV_CODEC_ID_AAC:
764  if (par->extradata_size)
765  avio_write(dyn_cp, par->extradata, par->extradata_size);
766  else
767  put_ebml_void(pb, MAX_PCE_SIZE + 2 + 4);
768  break;
769 #endif
770  default:
771  if (CONFIG_MATROSKA_MUXER && par->codec_id == AV_CODEC_ID_PRORES &&
773  avio_wl32(dyn_cp, par->codec_tag);
774  } else if (par->extradata_size && par->codec_id != AV_CODEC_ID_TTA)
775  avio_write(dyn_cp, par->extradata, par->extradata_size);
776  }
777 
778  return 0;
779 }
780 
782  AVCodecParameters *par,
783  int native_id, int qt_id)
784 {
785  MatroskaMuxContext av_unused *const mkv = s->priv_data;
786  AVIOContext *dyn_cp;
787  uint8_t *codecpriv;
788  int ret, codecpriv_size;
789 
790  ret = avio_open_dyn_buf(&dyn_cp);
791  if (ret < 0)
792  return ret;
793 
794  if (native_id) {
795  ret = mkv_write_native_codecprivate(s, pb, par, dyn_cp);
796 #if CONFIG_MATROSKA_MUXER
797  } else if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
798  if (qt_id) {
799  if (!par->codec_tag)
801  par->codec_id);
804  ) {
805  avio_wb32(dyn_cp, 0x5a + par->extradata_size);
806  avio_wl32(dyn_cp, par->codec_tag);
807  ffio_fill(dyn_cp, 0, 0x5a - 8);
808  }
809  avio_write(dyn_cp, par->extradata, par->extradata_size);
810  } else {
812  av_log(s, AV_LOG_WARNING, "codec %s is not supported by this format\n",
813  avcodec_get_name(par->codec_id));
814 
815  if (!par->codec_tag)
817  par->codec_id);
818  if (!par->codec_tag && par->codec_id != AV_CODEC_ID_RAWVIDEO) {
819  av_log(s, AV_LOG_ERROR, "No bmp codec tag found for codec %s\n",
820  avcodec_get_name(par->codec_id));
821  ret = AVERROR(EINVAL);
822  }
823 
824  ff_put_bmp_header(dyn_cp, par, 0, 0, mkv->flipped_raw_rgb);
825  }
826  } else if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
827  unsigned int tag;
829  if (!tag) {
830  av_log(s, AV_LOG_ERROR, "No wav codec tag found for codec %s\n",
831  avcodec_get_name(par->codec_id));
832  ret = AVERROR(EINVAL);
833  }
834  if (!par->codec_tag)
835  par->codec_tag = tag;
836 
838 #endif
839  }
840 
841  if (ret >= 0) {
842  codecpriv_size = avio_get_dyn_buf(dyn_cp, &codecpriv);
843  if ((ret = dyn_cp->error) >= 0 && codecpriv_size)
845  codecpriv_size);
846  }
847  ffio_free_dyn_buf(&dyn_cp);
848  return ret;
849 }
850 
851 static void mkv_write_video_color(AVIOContext *pb, const AVStream *st,
852  const AVCodecParameters *par)
853 {
854  /* 18 Elements with two bytes ID, one byte length field, 8 bytes payload
855  * a master element with two bytes ID and one byte length field
856  * plus another byte to stay clear of the end. */
857  uint8_t colour[(2 + 1 + 8) * 18 + (2 + 1) + 1];
858  FFIOContext buf;
859  AVIOContext *const dyn_cp = &buf.pub;
860  int colorinfo_size;
861  const void *side_data;
862 
863  ffio_init_context(&buf, colour, sizeof(colour), 1, NULL, NULL, NULL, NULL);
864 
865  if (par->color_trc != AVCOL_TRC_UNSPECIFIED &&
866  par->color_trc < AVCOL_TRC_NB) {
868  par->color_trc);
869  }
870  if (par->color_space != AVCOL_SPC_UNSPECIFIED &&
871  par->color_space < AVCOL_SPC_NB) {
873  }
875  par->color_primaries < AVCOL_PRI_NB) {
877  }
878  if (par->color_range != AVCOL_RANGE_UNSPECIFIED &&
879  par->color_range < AVCOL_RANGE_NB) {
881  }
884  int xpos, ypos;
885 
886  avcodec_enum_to_chroma_pos(&xpos, &ypos, par->chroma_location);
887  put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORCHROMASITINGHORZ, (xpos >> 7) + 1);
888  put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORCHROMASITINGVERT, (ypos >> 7) + 1);
889  }
890 
892  NULL);
893  if (side_data) {
894  const AVContentLightMetadata *metadata = side_data;
897  }
898 
900  NULL);
901  if (side_data) {
902  ebml_master meta_element = start_ebml_master(
903  dyn_cp, MATROSKA_ID_VIDEOCOLORMASTERINGMETA, 10 * (2 + 1 + 8));
904  const AVMasteringDisplayMetadata *metadata = side_data;
905  if (metadata->has_primaries) {
907  av_q2d(metadata->display_primaries[0][0]));
909  av_q2d(metadata->display_primaries[0][1]));
911  av_q2d(metadata->display_primaries[1][0]));
913  av_q2d(metadata->display_primaries[1][1]));
915  av_q2d(metadata->display_primaries[2][0]));
917  av_q2d(metadata->display_primaries[2][1]));
919  av_q2d(metadata->white_point[0]));
921  av_q2d(metadata->white_point[1]));
922  }
923  if (metadata->has_luminance) {
925  av_q2d(metadata->max_luminance));
927  av_q2d(metadata->min_luminance));
928  }
929  end_ebml_master(dyn_cp, meta_element);
930  }
931 
932  colorinfo_size = avio_tell(dyn_cp);
933  if (colorinfo_size)
934  put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLOR, colour, colorinfo_size);
935 }
936 
938  const AVStream *st)
939 {
940  ebml_master projection;
941  uint8_t private[20];
942 
943  const AVSphericalMapping *spherical =
945  NULL);
946 
947  if (!spherical)
948  return;
949 
950  if (spherical->projection != AV_SPHERICAL_EQUIRECTANGULAR &&
952  spherical->projection != AV_SPHERICAL_CUBEMAP) {
953  av_log(s, AV_LOG_WARNING, "Unknown projection type\n");
954  return;
955  }
956 
957  // Maximally 4 8-byte elements with id-length 2 + 1 byte length field
958  // and the private data of the AV_SPHERICAL_EQUIRECTANGULAR_TILE case
960  4 * (2 + 1 + 8) + (2 + 1 + 20));
961 
962  switch (spherical->projection) {
966  break;
970  AV_WB32(private, 0); // version + flags
971  AV_WB32(private + 4, spherical->bound_top);
972  AV_WB32(private + 8, spherical->bound_bottom);
973  AV_WB32(private + 12, spherical->bound_left);
974  AV_WB32(private + 16, spherical->bound_right);
976  private, 20);
977  break;
981  AV_WB32(private, 0); // version + flags
982  AV_WB32(private + 4, 0); // layout
983  AV_WB32(private + 8, spherical->padding);
985  private, 12);
986  break;
987  default:
988  av_assert0(0);
989  }
990 
991  if (spherical->yaw)
993  (double) spherical->yaw / (1 << 16));
994  if (spherical->pitch)
996  (double) spherical->pitch / (1 << 16));
997  if (spherical->roll)
999  (double) spherical->roll / (1 << 16));
1000 
1001  end_ebml_master(pb, projection);
1002 }
1003 
1004 static void mkv_write_field_order(AVIOContext *pb, int is_webm,
1005  enum AVFieldOrder field_order)
1006 {
1007  switch (field_order) {
1008  case AV_FIELD_UNKNOWN:
1009  break;
1010  case AV_FIELD_PROGRESSIVE:
1013  break;
1014  case AV_FIELD_TT:
1015  case AV_FIELD_BB:
1016  case AV_FIELD_TB:
1017  case AV_FIELD_BT:
1020  if (!is_webm) {
1021  switch (field_order) {
1022  case AV_FIELD_TT:
1025  break;
1026  case AV_FIELD_BB:
1029  break;
1030  case AV_FIELD_TB:
1033  break;
1034  case AV_FIELD_BT:
1037  break;
1038  }
1039  }
1040  }
1041 }
1042 
1044  AVStream *st, int is_webm,
1045  int *h_width, int *h_height)
1046 {
1047  const AVDictionaryEntry *tag;
1049  const AVStereo3D *stereo;
1050 
1051  *h_width = 1;
1052  *h_height = 1;
1053  // convert metadata into proper side data and add it to the stream
1054  if ((tag = av_dict_get(st->metadata, "stereo_mode", NULL, 0)) ||
1055  (tag = av_dict_get( s->metadata, "stereo_mode", NULL, 0))) {
1056  int stereo_mode = atoi(tag->value);
1057 
1058  for (int i = 0; i < MATROSKA_VIDEO_STEREOMODE_TYPE_NB; i++)
1059  if (!strcmp(tag->value, ff_matroska_video_stereo_mode[i])){
1060  stereo_mode = i;
1061  break;
1062  }
1063 
1064  if (stereo_mode < MATROSKA_VIDEO_STEREOMODE_TYPE_NB &&
1065  stereo_mode != 10 && stereo_mode != 12) {
1066  int ret = ff_mkv_stereo3d_conv(st, stereo_mode);
1067  if (ret < 0)
1068  return ret;
1069  }
1070  }
1071 
1073  NULL);
1074  if (stereo) {
1075  switch (stereo->type) {
1076  case AV_STEREO3D_2D:
1078  break;
1080  format = (stereo->flags & AV_STEREO3D_FLAG_INVERT)
1083  *h_width = 2;
1084  break;
1085  case AV_STEREO3D_TOPBOTTOM:
1087  if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
1088  format--;
1089  *h_height = 2;
1090  break;
1093  if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
1094  format--;
1095  break;
1096  case AV_STEREO3D_LINES:
1098  if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
1099  format--;
1100  *h_height = 2;
1101  break;
1102  case AV_STEREO3D_COLUMNS:
1104  if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
1105  format--;
1106  *h_width = 2;
1107  break;
1110  if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
1111  format++;
1112  break;
1113  }
1114  }
1115 
1117  return 0;
1118 
1119  // if webm, do not write unsupported modes
1120  if ((is_webm &&
1125  "The specified stereo mode is not valid.\n");
1126  return AVERROR(EINVAL);
1127  }
1128 
1129  // write StereoMode if format is valid
1131 
1132  return 0;
1133 }
1134 
1136 {
1137 #if CONFIG_MATROSKA_MUXER
1140 
1141  if (dovi && dovi->dv_profile <= 10) {
1142  ebml_master mapping;
1143  uint8_t buf[ISOM_DVCC_DVVC_SIZE];
1144  uint32_t type;
1145 
1146  uint64_t expected_size = (2 + 1 + (sizeof(DVCC_DVVC_BLOCK_TYPE_NAME) - 1))
1147  + (2 + 1 + 4) + (2 + 1 + ISOM_DVCC_DVVC_SIZE);
1148 
1149  if (dovi->dv_profile > 7) {
1150  type = MKBETAG('d', 'v', 'v', 'C');
1151  } else {
1152  type = MKBETAG('d', 'v', 'c', 'C');
1153  }
1154 
1155  ff_isom_put_dvcc_dvvc(s, buf, dovi);
1156 
1157  mapping = start_ebml_master(pb, MATROSKA_ID_TRACKBLKADDMAPPING, expected_size);
1158 
1161  put_ebml_binary(pb, MATROSKA_ID_BLKADDIDEXTRADATA, buf, sizeof(buf));
1162 
1163  end_ebml_master(pb, mapping);
1164  }
1165 #endif
1166 }
1167 
1169  AVStream *st, mkv_track *track, AVIOContext *pb,
1170  int is_default)
1171 {
1172  AVCodecParameters *par = st->codecpar;
1173  ebml_master subinfo, track_master;
1174  int native_id = 0;
1175  int qt_id = 0;
1176  int bit_depth;
1177  int sample_rate = par->sample_rate;
1178  int output_sample_rate = 0;
1179  int display_width_div = 1;
1180  int display_height_div = 1;
1181  int j, ret;
1182  const AVDictionaryEntry *tag;
1183 
1184  if (par->codec_type == AVMEDIA_TYPE_ATTACHMENT)
1185  return 0;
1186 
1187  track_master = start_ebml_master(pb, MATROSKA_ID_TRACKENTRY, 0);
1189  put_ebml_uid (pb, MATROSKA_ID_TRACKUID, track->uid);
1190  put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGLACING, 0); // no lacing (yet)
1191 
1192  if ((tag = av_dict_get(st->metadata, "title", NULL, 0)))
1194  tag = av_dict_get(st->metadata, "language", NULL, 0);
1196  tag && tag->value[0] ? tag->value : "und");
1197 
1198  // The default value for TRACKFLAGDEFAULT is 1, so add element
1199  // if we need to clear it.
1200  if (!is_default)
1202 
1205 
1206  if (IS_WEBM(mkv)) {
1207  const char *codec_id;
1208  if (par->codec_type != AVMEDIA_TYPE_SUBTITLE) {
1209  for (j = 0; ff_webm_codec_tags[j].id != AV_CODEC_ID_NONE; j++) {
1210  if (ff_webm_codec_tags[j].id == par->codec_id) {
1212  native_id = 1;
1213  break;
1214  }
1215  }
1216  } else if (par->codec_id == AV_CODEC_ID_WEBVTT) {
1218  codec_id = "D_WEBVTT/CAPTIONS";
1219  native_id = MATROSKA_TRACK_TYPE_SUBTITLE;
1220  } else if (st->disposition & AV_DISPOSITION_DESCRIPTIONS) {
1221  codec_id = "D_WEBVTT/DESCRIPTIONS";
1222  native_id = MATROSKA_TRACK_TYPE_METADATA;
1223  } else if (st->disposition & AV_DISPOSITION_METADATA) {
1224  codec_id = "D_WEBVTT/METADATA";
1225  native_id = MATROSKA_TRACK_TYPE_METADATA;
1226  } else {
1227  codec_id = "D_WEBVTT/SUBTITLES";
1228  native_id = MATROSKA_TRACK_TYPE_SUBTITLE;
1229  }
1230  }
1231 
1232  if (!native_id) {
1234  "Only VP8 or VP9 or AV1 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM.\n");
1235  return AVERROR(EINVAL);
1236  }
1237 
1239  } else {
1251 
1252  // look for a codec ID string specific to mkv to use,
1253  // if none are found, use AVI codes
1254  if (par->codec_id != AV_CODEC_ID_RAWVIDEO || par->codec_tag) {
1255  for (j = 0; ff_mkv_codec_tags[j].id != AV_CODEC_ID_NONE; j++) {
1256  if (ff_mkv_codec_tags[j].id == par->codec_id && par->codec_id != AV_CODEC_ID_FFV1) {
1258  native_id = 1;
1259  break;
1260  }
1261  }
1262  } else {
1263  if (mkv->allow_raw_vfw) {
1264  native_id = 0;
1265  } else {
1266  av_log(s, AV_LOG_ERROR, "Raw RGB is not supported Natively in Matroska, you can use AVI or NUT or\n"
1267  "If you would like to store it anyway using VFW mode, enable allow_raw_vfw (-allow_raw_vfw 1)\n");
1268  return AVERROR(EINVAL);
1269  }
1270  }
1271  }
1272 
1273  switch (par->codec_type) {
1274  case AVMEDIA_TYPE_VIDEO:
1275  mkv->have_video = 1;
1277 
1278  if( st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0
1279  && av_cmp_q(av_inv_q(st->avg_frame_rate), st->time_base) > 0)
1281  else if( st->r_frame_rate.num > 0 && st->r_frame_rate.den > 0
1282  && av_cmp_q(av_inv_q(st->r_frame_rate), st->time_base) > 0)
1284 
1285  if (CONFIG_MATROSKA_MUXER && !native_id &&
1288  par->codec_id == AV_CODEC_ID_SVQ1 ||
1289  par->codec_id == AV_CODEC_ID_SVQ3 ||
1290  par->codec_id == AV_CODEC_ID_CINEPAK))
1291  qt_id = 1;
1292 
1293  if (qt_id)
1294  put_ebml_string(pb, MATROSKA_ID_CODECID, "V_QUICKTIME");
1295  else if (!native_id) {
1296  // if there is no mkv-specific codec ID, use VFW mode
1297  put_ebml_string(pb, MATROSKA_ID_CODECID, "V_MS/VFW/FOURCC");
1298  track->write_dts = 1;
1300  }
1301 
1302  subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKVIDEO, 0);
1303 
1306 
1307  mkv_write_field_order(pb, IS_WEBM(mkv), par->field_order);
1308 
1309  // check both side data and metadata for stereo information,
1310  // write the result to the bitstream if any is found
1311  ret = mkv_write_stereo_mode(s, pb, st, IS_WEBM(mkv),
1312  &display_width_div,
1313  &display_height_div);
1314  if (ret < 0)
1315  return ret;
1316 
1317  if (((tag = av_dict_get(st->metadata, "alpha_mode", NULL, 0)) && atoi(tag->value)) ||
1318  ((tag = av_dict_get( s->metadata, "alpha_mode", NULL, 0)) && atoi(tag->value)) ||
1319  (par->format == AV_PIX_FMT_YUVA420P)) {
1321  }
1322 
1323  // write DisplayWidth and DisplayHeight, they contain the size of
1324  // a single source view and/or the display aspect ratio
1325  if (st->sample_aspect_ratio.num) {
1326  int64_t d_width = av_rescale(par->width, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
1327  if (d_width > INT_MAX) {
1328  av_log(s, AV_LOG_ERROR, "Overflow in display width\n");
1329  return AVERROR(EINVAL);
1330  }
1331  if (d_width != par->width || display_width_div != 1 || display_height_div != 1) {
1332  if (IS_WEBM(mkv) || display_width_div != 1 || display_height_div != 1) {
1333  put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , d_width / display_width_div);
1334  put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, par->height / display_height_div);
1335  } else {
1336  AVRational display_aspect_ratio;
1337  av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
1338  par->width * (int64_t)st->sample_aspect_ratio.num,
1339  par->height * (int64_t)st->sample_aspect_ratio.den,
1340  1024 * 1024);
1341  put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH, display_aspect_ratio.num);
1342  put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, display_aspect_ratio.den);
1344  }
1345  }
1346  } else if (display_width_div != 1 || display_height_div != 1) {
1347  put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , par->width / display_width_div);
1348  put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, par->height / display_height_div);
1349  } else if (!IS_WEBM(mkv))
1351 
1352  if (par->codec_id == AV_CODEC_ID_RAWVIDEO) {
1353  uint32_t color_space = av_le2ne32(par->codec_tag);
1354  put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLORSPACE, &color_space, sizeof(color_space));
1355  }
1356  mkv_write_video_color(pb, st, par);
1357  mkv_write_video_projection(s, pb, st);
1358 
1359  end_ebml_master(pb, subinfo);
1360 
1361  if (!IS_WEBM(mkv))
1362  mkv_write_dovi(s, pb, st);
1363 
1364  break;
1365 
1366  case AVMEDIA_TYPE_AUDIO:
1367  if (par->initial_padding && par->codec_id == AV_CODEC_ID_OPUS) {
1368  int64_t codecdelay = av_rescale_q(par->initial_padding,
1369  (AVRational){ 1, 48000 },
1370  (AVRational){ 1, 1000000000 });
1371  if (codecdelay < 0) {
1372  av_log(s, AV_LOG_ERROR, "Initial padding is invalid\n");
1373  return AVERROR(EINVAL);
1374  }
1375 // track->ts_offset = av_rescale_q(par->initial_padding,
1376 // (AVRational){ 1, par->sample_rate },
1377 // st->time_base);
1378 
1379  put_ebml_uint(pb, MATROSKA_ID_CODECDELAY, codecdelay);
1380  }
1381  if (par->codec_id == AV_CODEC_ID_OPUS)
1383 #if CONFIG_MATROSKA_MUXER
1384  else if (par->codec_id == AV_CODEC_ID_AAC) {
1385  ret = get_aac_sample_rates(s, mkv, par->extradata, par->extradata_size,
1386  &sample_rate, &output_sample_rate);
1387  if (ret < 0)
1388  return ret;
1389  }
1390 #endif
1391 
1393 
1394  if (!native_id)
1395  // no mkv-specific ID, use ACM mode
1396  put_ebml_string(pb, MATROSKA_ID_CODECID, "A_MS/ACM");
1397 
1398  subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKAUDIO, 6 + 4 * 9);
1400 
1401  track->sample_rate_offset = avio_tell(pb);
1403  if (output_sample_rate)
1404  put_ebml_float(pb, MATROSKA_ID_AUDIOOUTSAMPLINGFREQ, output_sample_rate);
1405 
1407  if (!bit_depth && par->codec_id != AV_CODEC_ID_ADPCM_G726) {
1408  if (par->bits_per_raw_sample)
1410  else
1412  }
1413  if (!bit_depth)
1415  if (bit_depth)
1417  end_ebml_master(pb, subinfo);
1418  break;
1419 
1420  case AVMEDIA_TYPE_SUBTITLE:
1421  if (!native_id) {
1422  av_log(s, AV_LOG_ERROR, "Subtitle codec %d is not supported.\n", par->codec_id);
1423  return AVERROR(ENOSYS);
1424  }
1425  if (!IS_WEBM(mkv) && st->disposition & AV_DISPOSITION_DESCRIPTIONS)
1427 
1428  if (!IS_WEBM(mkv) || par->codec_id != AV_CODEC_ID_WEBVTT)
1429  native_id = MATROSKA_TRACK_TYPE_SUBTITLE;
1430 
1431  put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, native_id);
1432  break;
1433  default:
1434  av_log(s, AV_LOG_ERROR, "Only audio, video, and subtitles are supported for Matroska.\n");
1435  return AVERROR(EINVAL);
1436  }
1437 
1438  if (!IS_WEBM(mkv) || par->codec_id != AV_CODEC_ID_WEBVTT) {
1439  track->codecpriv_offset = avio_tell(pb);
1440  ret = mkv_write_codecprivate(s, pb, par, native_id, qt_id);
1441  if (ret < 0)
1442  return ret;
1443  }
1444 
1445  end_ebml_master(pb, track_master);
1446 
1447  return 0;
1448 }
1449 
1451 {
1452  MatroskaMuxContext *mkv = s->priv_data;
1453  AVIOContext *pb = s->pb;
1454  int video_default_idx = -1, audio_default_idx = -1, subtitle_default_idx = -1;
1455  int i, ret;
1456 
1457  if (mkv->nb_attachments == s->nb_streams)
1458  return 0;
1459 
1460  ret = start_ebml_master_crc32(&mkv->track.bc, mkv);
1461  if (ret < 0)
1462  return ret;
1463 
1464  if (mkv->default_mode != DEFAULT_MODE_PASSTHROUGH) {
1465  int video_idx = -1, audio_idx = -1, subtitle_idx = -1;
1466 
1467  for (i = s->nb_streams - 1; i >= 0; i--) {
1468  AVStream *st = s->streams[i];
1469 
1470  switch (st->codecpar->codec_type) {
1471 #define CASE(type, variable) \
1472  case AVMEDIA_TYPE_ ## type: \
1473  variable ## _idx = i; \
1474  if (st->disposition & AV_DISPOSITION_DEFAULT) \
1475  variable ## _default_idx = i; \
1476  break;
1477  CASE(VIDEO, video)
1478  CASE(AUDIO, audio)
1479  CASE(SUBTITLE, subtitle)
1480 #undef CASE
1481  }
1482  }
1483 
1484  video_default_idx = FFMAX(video_default_idx, video_idx);
1485  audio_default_idx = FFMAX(audio_default_idx, audio_idx);
1487  subtitle_default_idx = FFMAX(subtitle_default_idx, subtitle_idx);
1488  }
1489  for (i = 0; i < s->nb_streams; i++) {
1490  AVStream *st = s->streams[i];
1491  int is_default = st->disposition & AV_DISPOSITION_DEFAULT ||
1492  i == video_default_idx || i == audio_default_idx ||
1493  i == subtitle_default_idx;
1494  ret = mkv_write_track(s, mkv, st, &mkv->tracks[i],
1495  mkv->track.bc, is_default);
1496  if (ret < 0)
1497  return ret;
1498  }
1499 
1500  return end_ebml_master_crc32_tentatively(pb, &mkv->track, mkv,
1502 }
1503 
1505 {
1506  uint8_t *key = av_strdup(t->key);
1507  uint8_t *p = key;
1508  const uint8_t *lang = NULL;
1509  ebml_master tag;
1510 
1511  if (!key)
1512  return AVERROR(ENOMEM);
1513 
1514  if ((p = strrchr(p, '-')) &&
1515  (lang = ff_convert_lang_to(p + 1, AV_LANG_ISO639_2_BIBL)))
1516  *p = 0;
1517 
1518  p = key;
1519  while (*p) {
1520  if (*p == ' ')
1521  *p = '_';
1522  else if (*p >= 'a' && *p <= 'z')
1523  *p -= 'a' - 'A';
1524  p++;
1525  }
1526 
1529  if (lang)
1532  end_ebml_master(pb, tag);
1533 
1534  av_freep(&key);
1535  return 0;
1536 }
1537 
1539  ebml_master *tag, uint32_t elementid, uint64_t uid)
1540 {
1542  int ret;
1543 
1544  if (!*pb) {
1545  ret = start_ebml_master_crc32(pb, mkv);
1546  if (ret < 0)
1547  return ret;
1548  }
1549 
1552  if (elementid)
1553  put_ebml_uid(*pb, elementid, uid);
1554  end_ebml_master(*pb, targets);
1555  return 0;
1556 }
1557 
1558 static int mkv_check_tag_name(const char *name, uint32_t elementid)
1559 {
1560  return av_strcasecmp(name, "title") &&
1561  av_strcasecmp(name, "stereo_mode") &&
1562  av_strcasecmp(name, "creation_time") &&
1563  av_strcasecmp(name, "encoding_tool") &&
1564  av_strcasecmp(name, "duration") &&
1565  (elementid != MATROSKA_ID_TAGTARGETS_TRACKUID ||
1566  av_strcasecmp(name, "language")) &&
1567  (elementid != MATROSKA_ID_TAGTARGETS_ATTACHUID ||
1568  (av_strcasecmp(name, "filename") &&
1569  av_strcasecmp(name, "mimetype")));
1570 }
1571 
1573  AVIOContext **pb, ebml_master *tag,
1574  uint32_t elementid, uint64_t uid)
1575 {
1576  const AVDictionaryEntry *t = NULL;
1577  ebml_master tag2;
1578  int ret;
1579 
1580  ret = mkv_write_tag_targets(mkv, pb, tag ? tag : &tag2, elementid, uid);
1581  if (ret < 0)
1582  return ret;
1583 
1584  while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX))) {
1585  if (mkv_check_tag_name(t->key, elementid)) {
1586  ret = mkv_write_simpletag(*pb, t);
1587  if (ret < 0)
1588  return ret;
1589  }
1590  }
1591 
1592  if (!tag)
1593  end_ebml_master(*pb, tag2);
1594 
1595  return 0;
1596 }
1597 
1598 static int mkv_check_tag(const AVDictionary *m, uint32_t elementid)
1599 {
1600  const AVDictionaryEntry *t = NULL;
1601 
1602  while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX)))
1603  if (mkv_check_tag_name(t->key, elementid))
1604  return 1;
1605 
1606  return 0;
1607 }
1608 
1610 {
1611  MatroskaMuxContext *mkv = s->priv_data;
1612  ebml_master tag, *tagp = IS_SEEKABLE(s->pb, mkv) ? &tag : NULL;
1613  int i, ret;
1614 
1615  mkv->wrote_tags = 1;
1616 
1618 
1619  if (mkv_check_tag(s->metadata, 0)) {
1620  ret = mkv_write_tag(mkv, s->metadata, &mkv->tags.bc, NULL, 0, 0);
1621  if (ret < 0)
1622  return ret;
1623  }
1624 
1625  for (i = 0; i < s->nb_streams; i++) {
1626  const AVStream *st = s->streams[i];
1627  mkv_track *track = &mkv->tracks[i];
1628 
1630  continue;
1631 
1633  continue;
1634 
1635  ret = mkv_write_tag(mkv, st->metadata, &mkv->tags.bc, tagp,
1637  if (ret < 0)
1638  return ret;
1639 
1640  if (tagp) {
1641  AVIOContext *pb = mkv->tags.bc;
1642  ebml_master simpletag;
1643 
1644  simpletag = start_ebml_master(pb, MATROSKA_ID_SIMPLETAG,
1645  2 + 1 + 8 + 23);
1646  put_ebml_string(pb, MATROSKA_ID_TAGNAME, "DURATION");
1647  track->duration_offset = avio_tell(pb);
1648 
1649  // Reserve space to write duration as a 20-byte string.
1650  // 2 (ebml id) + 1 (data size) + 20 (data)
1651  put_ebml_void(pb, 23);
1652  end_ebml_master(pb, simpletag);
1653  end_ebml_master(pb, tag);
1654  }
1655  }
1656 
1657  if (mkv->nb_attachments && !IS_WEBM(mkv)) {
1658  for (i = 0; i < s->nb_streams; i++) {
1659  const mkv_track *track = &mkv->tracks[i];
1660  const AVStream *st = s->streams[i];
1661 
1663  continue;
1664 
1666  continue;
1667 
1668  ret = mkv_write_tag(mkv, st->metadata, &mkv->tags.bc, NULL,
1670  if (ret < 0)
1671  return ret;
1672  }
1673  }
1674 
1675  if (mkv->tags.bc) {
1676  return end_ebml_master_crc32_tentatively(s->pb, &mkv->tags, mkv,
1678  }
1679  return 0;
1680 }
1681 
1683 {
1684  for (unsigned i = 0; i < s->nb_chapters; i++) {
1685  if (!s->chapters[i]->id)
1686  return 1;
1687  for (unsigned j = 0; j < i; j++)
1688  if (s->chapters[j]->id == s->chapters[i]->id)
1689  return 1;
1690  }
1691  return 0;
1692 }
1693 
1695 {
1696  MatroskaMuxContext *mkv = s->priv_data;
1697  AVIOContext *dyn_cp = NULL, *dyn_tags = NULL, **tags, *pb = s->pb;
1698  ebml_master editionentry;
1699  AVRational scale = {1, 1E9};
1700  int ret, create_new_ids;
1701 
1702  if (!s->nb_chapters || mkv->wrote_chapters)
1703  return 0;
1704 
1705  ret = start_ebml_master_crc32(&dyn_cp, mkv);
1706  if (ret < 0)
1707  return ret;
1708 
1709  editionentry = start_ebml_master(dyn_cp, MATROSKA_ID_EDITIONENTRY, 0);
1710  if (!IS_WEBM(mkv)) {
1712  /* If mkv_write_tags() has already been called, then any tags
1713  * corresponding to chapters will be put into a new Tags element. */
1714  tags = mkv->wrote_tags ? &dyn_tags : &mkv->tags.bc;
1715  } else
1716  tags = NULL;
1717 
1718  create_new_ids = mkv_new_chapter_ids_needed(s);
1719 
1720  for (unsigned i = 0; i < s->nb_chapters; i++) {
1721  ebml_master chapteratom, chapterdisplay;
1722  const AVChapter *c = s->chapters[i];
1723  int64_t chapterstart = av_rescale_q(c->start, c->time_base, scale);
1724  int64_t chapterend = av_rescale_q(c->end, c->time_base, scale);
1725  const AVDictionaryEntry *t;
1726  uint64_t uid = create_new_ids ? i + 1ULL : c->id;
1727  if (chapterstart < 0 || chapterstart > chapterend || chapterend < 0) {
1729  "Invalid chapter start (%"PRId64") or end (%"PRId64").\n",
1730  chapterstart, chapterend);
1732  goto fail;
1733  }
1734 
1735  chapteratom = start_ebml_master(dyn_cp, MATROSKA_ID_CHAPTERATOM, 0);
1737  put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERTIMESTART, chapterstart);
1738  put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERTIMEEND, chapterend);
1739  if ((t = av_dict_get(c->metadata, "title", NULL, 0))) {
1740  chapterdisplay = start_ebml_master(dyn_cp, MATROSKA_ID_CHAPTERDISPLAY, 0);
1742  put_ebml_string(dyn_cp, MATROSKA_ID_CHAPLANG , "und");
1743  end_ebml_master(dyn_cp, chapterdisplay);
1744  }
1745  end_ebml_master(dyn_cp, chapteratom);
1746 
1747  if (tags && mkv_check_tag(c->metadata, MATROSKA_ID_TAGTARGETS_CHAPTERUID)) {
1748  ret = mkv_write_tag(mkv, c->metadata, tags, NULL,
1750  if (ret < 0)
1751  goto fail;
1752  }
1753  }
1754  end_ebml_master(dyn_cp, editionentry);
1755  mkv->wrote_chapters = 1;
1756 
1757  ret = end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CHAPTERS, 0, 0, 1);
1758  if (ret < 0)
1759  goto fail;
1760  if (dyn_tags)
1761  return end_ebml_master_crc32(pb, &dyn_tags, mkv,
1762  MATROSKA_ID_TAGS, 0, 0, 1);
1763  return 0;
1764 
1765 fail:
1766  if (tags) {
1767  /* tags == &mkv->tags.bc can only happen if mkv->tags.bc was
1768  * initially NULL, so we never free older tags. */
1769  ffio_free_dyn_buf(tags);
1770  }
1771  ffio_free_dyn_buf(&dyn_cp);
1772  return ret;
1773 }
1774 
1775 static const char *get_mimetype(const AVStream *st)
1776 {
1777  const AVDictionaryEntry *t;
1778 
1779  if (t = av_dict_get(st->metadata, "mimetype", NULL, 0))
1780  return t->value;
1781  if (st->codecpar->codec_id != AV_CODEC_ID_NONE) {
1783  if (desc && desc->mime_types) {
1784  return desc->mime_types[0];
1785  } else if (st->codecpar->codec_id == AV_CODEC_ID_TEXT)
1786  return "text/plain";
1787  }
1788 
1789  return NULL;
1790 }
1791 
1793 {
1794  MatroskaMuxContext *mkv = s->priv_data;
1795  AVIOContext *dyn_cp = NULL, *pb = s->pb;
1796  int i, ret;
1797 
1798  if (!mkv->nb_attachments)
1799  return 0;
1800 
1801  ret = start_ebml_master_crc32(&dyn_cp, mkv);
1802  if (ret < 0)
1803  return ret;
1804 
1805  for (i = 0; i < s->nb_streams; i++) {
1806  const AVStream *st = s->streams[i];
1807  mkv_track *track = &mkv->tracks[i];
1808  ebml_master attached_file;
1809  const AVDictionaryEntry *t;
1810  const char *mimetype;
1811 
1813  continue;
1814 
1815  attached_file = start_ebml_master(dyn_cp, MATROSKA_ID_ATTACHEDFILE, 0);
1816 
1817  if (t = av_dict_get(st->metadata, "title", NULL, 0))
1819  if (!(t = av_dict_get(st->metadata, "filename", NULL, 0))) {
1820  av_log(s, AV_LOG_ERROR, "Attachment stream %d has no filename tag.\n", i);
1821  ffio_free_dyn_buf(&dyn_cp);
1822  return AVERROR(EINVAL);
1823  }
1825 
1826  mimetype = get_mimetype(st);
1827  av_assert0(mimetype);
1828  put_ebml_string(dyn_cp, MATROSKA_ID_FILEMIMETYPE, mimetype);
1830  put_ebml_uid(dyn_cp, MATROSKA_ID_FILEUID, track->uid);
1831  end_ebml_master(dyn_cp, attached_file);
1832  }
1833  return end_ebml_master_crc32(pb, &dyn_cp, mkv,
1834  MATROSKA_ID_ATTACHMENTS, 0, 0, 1);
1835 }
1836 
1838 {
1839  const AVDictionaryEntry *duration = av_dict_get(s->metadata, "DURATION",
1840  NULL, 0);
1841  int64_t max = 0;
1842  int64_t us;
1843 
1844  if (duration && (av_parse_time(&us, duration->value, 1) == 0) && us > 0) {
1845  av_log(s, AV_LOG_DEBUG, "get_metadata_duration found duration in context metadata: %" PRId64 "\n", us);
1846  return us;
1847  }
1848 
1849  for (unsigned i = 0; i < s->nb_streams; i++) {
1850  int64_t us;
1851  duration = av_dict_get(s->streams[i]->metadata, "DURATION", NULL, 0);
1852 
1853  if (duration && (av_parse_time(&us, duration->value, 1) == 0))
1854  max = FFMAX(max, us);
1855  }
1856 
1857  av_log(s, AV_LOG_DEBUG, "get_metadata_duration returned: %" PRId64 "\n", max);
1858  return max;
1859 }
1860 
1862 {
1863  MatroskaMuxContext *mkv = s->priv_data;
1864  AVIOContext *pb = s->pb;
1866  const AVDictionaryEntry *tag;
1867  int ret, i, version = 2;
1868  int64_t creation_time;
1869 
1870  if (!IS_WEBM(mkv) ||
1871  av_dict_get(s->metadata, "stereo_mode", NULL, 0) ||
1872  av_dict_get(s->metadata, "alpha_mode", NULL, 0))
1873  version = 4;
1874 
1875  for (i = 0; i < s->nb_streams; i++) {
1876  if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_OPUS ||
1877  av_dict_get(s->streams[i]->metadata, "stereo_mode", NULL, 0) ||
1878  av_dict_get(s->streams[i]->metadata, "alpha_mode", NULL, 0))
1879  version = 4;
1880  }
1881 
1887  put_ebml_string(pb, EBML_ID_DOCTYPE , s->oformat->name);
1891 
1893  put_ebml_size_unknown(pb, 8);
1894  mkv->segment_offset = avio_tell(pb);
1895 
1896  // We write a SeekHead at the beginning to point to all other level
1897  // one elements (except Clusters).
1898  mkv_start_seekhead(mkv, pb);
1899 
1900  ret = start_ebml_master_crc32(&mkv->info.bc, mkv);
1901  if (ret < 0)
1902  return ret;
1903  pb = mkv->info.bc;
1904 
1906  if ((tag = av_dict_get(s->metadata, "title", NULL, 0)))
1907  put_ebml_string(pb, MATROSKA_ID_TITLE, tag->value);
1908  if (!(s->flags & AVFMT_FLAG_BITEXACT)) {
1910  if ((tag = av_dict_get(s->metadata, "encoding_tool", NULL, 0)))
1912  else
1914 
1915  if (!IS_WEBM(mkv))
1917  } else {
1918  const char *ident = "Lavf";
1921  }
1922 
1923  if (ff_parse_creation_time_metadata(s, &creation_time, 0) > 0) {
1924  // Adjust time so it's relative to 2001-01-01 and convert to nanoseconds.
1925  int64_t date_utc = (creation_time - 978307200000000LL) * 1000;
1926  uint8_t date_utc_buf[8];
1927  AV_WB64(date_utc_buf, date_utc);
1928  put_ebml_binary(pb, MATROSKA_ID_DATEUTC, date_utc_buf, 8);
1929  }
1930 
1931  // reserve space for the duration
1932  mkv->duration = 0;
1933  mkv->duration_offset = avio_tell(pb);
1934  if (!mkv->is_live) {
1935  int64_t metadata_duration = get_metadata_duration(s);
1936 
1937  if (s->duration > 0) {
1938  int64_t scaledDuration = av_rescale(s->duration, 1000, AV_TIME_BASE);
1939  put_ebml_float(pb, MATROSKA_ID_DURATION, scaledDuration);
1940  av_log(s, AV_LOG_DEBUG, "Write early duration from recording time = %" PRIu64 "\n", scaledDuration);
1941  } else if (metadata_duration > 0) {
1942  int64_t scaledDuration = av_rescale(metadata_duration, 1000, AV_TIME_BASE);
1943  put_ebml_float(pb, MATROSKA_ID_DURATION, scaledDuration);
1944  av_log(s, AV_LOG_DEBUG, "Write early duration from metadata = %" PRIu64 "\n", scaledDuration);
1945  } else if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
1946  put_ebml_void(pb, 11); // assumes double-precision float to be written
1947  }
1948  }
1950  mkv, MATROSKA_ID_INFO);
1951  if (ret < 0)
1952  return ret;
1953  pb = s->pb;
1954 
1955  ret = mkv_write_tracks(s);
1956  if (ret < 0)
1957  return ret;
1958 
1960  if (ret < 0)
1961  return ret;
1962 
1963  if (!IS_WEBM(mkv)) {
1965  if (ret < 0)
1966  return ret;
1967  }
1968 
1969  /* Must come after mkv_write_chapters() to write chapter tags
1970  * into the same Tags element as the other tags. */
1971  ret = mkv_write_tags(s);
1972  if (ret < 0)
1973  return ret;
1974 
1975  if (!IS_SEEKABLE(pb, mkv)) {
1976  ret = mkv_write_seekhead(pb, mkv, 0, avio_tell(pb));
1977  if (ret < 0)
1978  return ret;
1979  }
1980 
1981  if (s->metadata_header_padding > 0) {
1982  if (s->metadata_header_padding == 1)
1983  s->metadata_header_padding++;
1984  put_ebml_void(pb, s->metadata_header_padding);
1985  }
1986 
1987  if (mkv->reserve_cues_space) {
1988  if (IS_SEEKABLE(pb, mkv)) {
1989  mkv->cues_pos = avio_tell(pb);
1990  if (mkv->reserve_cues_space == 1)
1991  mkv->reserve_cues_space++;
1993  } else
1994  mkv->reserve_cues_space = -1;
1995  }
1996 
1997  mkv->cluster_pos = -1;
1998 
1999  // start a new cluster every 5 MB or 5 sec, or 32k / 1 sec for streaming or
2000  // after 4k and on a keyframe
2001  if (IS_SEEKABLE(pb, mkv)) {
2002  if (mkv->cluster_time_limit < 0)
2003  mkv->cluster_time_limit = 5000;
2004  if (mkv->cluster_size_limit < 0)
2005  mkv->cluster_size_limit = 5 * 1024 * 1024;
2006  } else {
2007  if (mkv->cluster_time_limit < 0)
2008  mkv->cluster_time_limit = 1000;
2009  if (mkv->cluster_size_limit < 0)
2010  mkv->cluster_size_limit = 32 * 1024;
2011  }
2012 
2013  return 0;
2014 }
2015 
2016 static int mkv_blockgroup_size(int pkt_size, int track_num_size)
2017 {
2018  int size = pkt_size + track_num_size + 3;
2020  size += 2; // EBML ID for block and block duration
2021  size += 9; // max size of block duration incl. length field
2022  return size;
2023 }
2024 
2025 #if CONFIG_MATROSKA_MUXER
2026 static int mkv_strip_wavpack(const uint8_t *src, uint8_t **pdst, int *size)
2027 {
2028  uint8_t *dst;
2029  int srclen = *size;
2030  int offset = 0;
2031  int ret;
2032 
2033  dst = av_malloc(srclen);
2034  if (!dst)
2035  return AVERROR(ENOMEM);
2036 
2037  while (srclen >= WV_HEADER_SIZE) {
2038  WvHeader header;
2039 
2041  if (ret < 0)
2042  goto fail;
2043  src += WV_HEADER_SIZE;
2044  srclen -= WV_HEADER_SIZE;
2045 
2046  if (srclen < header.blocksize) {
2048  goto fail;
2049  }
2050 
2051  if (header.initial) {
2052  AV_WL32(dst + offset, header.samples);
2053  offset += 4;
2054  }
2055  AV_WL32(dst + offset, header.flags);
2056  AV_WL32(dst + offset + 4, header.crc);
2057  offset += 8;
2058 
2059  if (!(header.initial && header.final)) {
2060  AV_WL32(dst + offset, header.blocksize);
2061  offset += 4;
2062  }
2063 
2064  memcpy(dst + offset, src, header.blocksize);
2065  src += header.blocksize;
2066  srclen -= header.blocksize;
2067  offset += header.blocksize;
2068  }
2069 
2070  *pdst = dst;
2071  *size = offset;
2072 
2073  return 0;
2074 fail:
2075  av_freep(&dst);
2076  return ret;
2077 }
2078 #endif
2079 
2081  uint32_t blockid, const AVPacket *pkt, int keyframe)
2082 {
2083  MatroskaMuxContext *mkv = s->priv_data;
2084  AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar;
2085  mkv_track *track = &mkv->tracks[pkt->stream_index];
2086  uint8_t *data = NULL, *side_data = NULL;
2087  size_t side_data_size;
2088  int err = 0, offset = 0, size = pkt->size;
2089  int64_t ts = track->write_dts ? pkt->dts : pkt->pts;
2090  uint64_t additional_id;
2091  int64_t discard_padding = 0;
2092  unsigned track_number = track->track_num;
2093  ebml_master block_group, block_additions, block_more;
2094 
2095  ts += track->ts_offset;
2096 
2097  /* The following string is identical to the one in mkv_write_vtt_blocks
2098  * so that only one copy needs to exist in binaries. */
2100  "Writing block of size %d with pts %" PRId64 ", dts %" PRId64 ", "
2101  "duration %" PRId64 " at relative offset %" PRId64 " in cluster "
2102  "at offset %" PRId64 ". TrackNumber %u, keyframe %d\n",
2103  pkt->size, pkt->pts, pkt->dts, pkt->duration, avio_tell(pb),
2104  mkv->cluster_pos, track_number, keyframe != 0);
2105 
2106 #if CONFIG_MATROSKA_MUXER
2107  if (par->codec_id == AV_CODEC_ID_H264 && par->extradata_size > 0 &&
2108  (AV_RB24(par->extradata) == 1 || AV_RB32(par->extradata) == 1)) {
2110  } else if (par->codec_id == AV_CODEC_ID_HEVC && par->extradata_size > 6 &&
2111  (AV_RB24(par->extradata) == 1 || AV_RB32(par->extradata) == 1)) {
2112  /* extradata is Annex B, assume the bitstream is too and convert it */
2113  err = ff_hevc_annexb2mp4_buf(pkt->data, &data, &size, 0, NULL);
2114  } else if (par->codec_id == AV_CODEC_ID_WAVPACK) {
2115  err = mkv_strip_wavpack(pkt->data, &data, &size);
2116  } else
2117 #endif
2118  if (par->codec_id == AV_CODEC_ID_AV1) {
2120  } else
2121  data = pkt->data;
2122 
2123  if (err < 0) {
2124  av_log(s, AV_LOG_ERROR, "Error when reformatting data of "
2125  "a packet from stream %d.\n", pkt->stream_index);
2126  return err;
2127  }
2128 
2129  if (CONFIG_MATROSKA_MUXER &&
2130  par->codec_id == AV_CODEC_ID_PRORES && size >= 8) {
2131  /* Matroska specification requires to remove the first QuickTime atom
2132  */
2133  size -= 8;
2134  offset = 8;
2135  }
2136 
2137  side_data = av_packet_get_side_data(pkt,
2139  &side_data_size);
2140  if (side_data && side_data_size >= 10) {
2141  discard_padding = av_rescale_q(AV_RL32(side_data + 4),
2142  (AVRational){1, par->sample_rate},
2143  (AVRational){1, 1000000000});
2144  }
2145 
2146  side_data = av_packet_get_side_data(pkt,
2148  &side_data_size);
2149  if (side_data) {
2150  // Only the Codec-specific BlockMore (id == 1) is currently supported.
2151  if (side_data_size < 8 || (additional_id = AV_RB64(side_data)) != 1) {
2152  side_data_size = 0;
2153  } else {
2154  side_data += 8;
2155  side_data_size -= 8;
2156  }
2157  }
2158 
2159  if (side_data_size || discard_padding) {
2160  block_group = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP, 0);
2161  blockid = MATROSKA_ID_BLOCK;
2162  }
2163 
2164  put_ebml_id(pb, blockid);
2165  put_ebml_length(pb, size + track->track_num_size + 3, 0);
2166  put_ebml_num(pb, track_number, track->track_num_size);
2167  avio_wb16(pb, ts - mkv->cluster_pts);
2168  avio_w8(pb, (blockid == MATROSKA_ID_SIMPLEBLOCK && keyframe) ? (1 << 7) : 0);
2169  avio_write(pb, data + offset, size);
2170  if (data != pkt->data)
2171  av_free(data);
2172 
2173  if (blockid == MATROSKA_ID_BLOCK && !keyframe)
2175  track->last_timestamp = ts;
2176 
2177  if (discard_padding)
2178  put_ebml_sint(pb, MATROSKA_ID_DISCARDPADDING, discard_padding);
2179 
2180  if (side_data_size) {
2181  block_additions = start_ebml_master(pb, MATROSKA_ID_BLOCKADDITIONS, 0);
2182  block_more = start_ebml_master(pb, MATROSKA_ID_BLOCKMORE, 0);
2183  /* Until dbc50f8a our demuxer used a wrong default value
2184  * of BlockAddID, so we write it unconditionally. */
2185  put_ebml_uint (pb, MATROSKA_ID_BLOCKADDID, additional_id);
2187  side_data, side_data_size);
2188  end_ebml_master(pb, block_more);
2189  end_ebml_master(pb, block_additions);
2190  }
2191  if (side_data_size || discard_padding)
2192  end_ebml_master(pb, block_group);
2193 
2194  return 0;
2195 }
2196 
2198 {
2199  MatroskaMuxContext *mkv = s->priv_data;
2200  mkv_track *track = &mkv->tracks[pkt->stream_index];
2201  ebml_master blockgroup;
2202  size_t id_size, settings_size;
2203  int size, id_size_int, settings_size_int;
2204  const char *id, *settings;
2205  int64_t ts = track->write_dts ? pkt->dts : pkt->pts;
2206  const int flags = 0;
2207 
2209  &id_size);
2210  id = id ? id : "";
2211 
2213  &settings_size);
2214  settings = settings ? settings : "";
2215 
2216  if (id_size > INT_MAX - 2 || settings_size > INT_MAX - id_size - 2 ||
2217  pkt->size > INT_MAX - settings_size - id_size - 2)
2218  return AVERROR(EINVAL);
2219 
2220  size = id_size + 1 + settings_size + 1 + pkt->size;
2221 
2222  /* The following string is identical to the one in mkv_write_block so that
2223  * only one copy needs to exist in binaries. */
2225  "Writing block of size %d with pts %" PRId64 ", dts %" PRId64 ", "
2226  "duration %" PRId64 " at relative offset %" PRId64 " in cluster "
2227  "at offset %" PRId64 ". TrackNumber %u, keyframe %d\n",
2228  size, pkt->pts, pkt->dts, pkt->duration, avio_tell(pb),
2229  mkv->cluster_pos, track->track_num, 1);
2230 
2231  blockgroup = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP,
2233 
2235  put_ebml_length(pb, size + track->track_num_size + 3, 0);
2236  put_ebml_num(pb, track->track_num, track->track_num_size);
2237  avio_wb16(pb, ts - mkv->cluster_pts);
2238  avio_w8(pb, flags);
2239 
2240  id_size_int = id_size;
2241  settings_size_int = settings_size;
2242  avio_printf(pb, "%.*s\n%.*s\n%.*s", id_size_int, id, settings_size_int, settings, pkt->size, pkt->data);
2243 
2245  end_ebml_master(pb, blockgroup);
2246 
2247  return 0;
2248 }
2249 
2251 {
2252  MatroskaMuxContext *mkv = s->priv_data;
2253  int ret;
2254 
2255  if (!mkv->have_video) {
2256  for (unsigned i = 0; i < s->nb_streams; i++)
2257  mkv->tracks[i].has_cue = 0;
2258  }
2259  mkv->cluster_pos = -1;
2260  ret = end_ebml_master_crc32(s->pb, &mkv->cluster_bc, mkv,
2261  MATROSKA_ID_CLUSTER, 0, 1, 0);
2262  if (ret < 0)
2263  return ret;
2264 
2266  return 0;
2267 }
2268 
2270 {
2271  MatroskaMuxContext *mkv = s->priv_data;
2272  mkv_track *track = &mkv->tracks[pkt->stream_index];
2273  AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar;
2274  uint8_t *side_data;
2275  size_t side_data_size;
2276  int ret;
2277 
2279  &side_data_size);
2280 
2281  switch (par->codec_id) {
2282 #if CONFIG_MATROSKA_MUXER
2283  case AV_CODEC_ID_AAC:
2284  if (side_data_size && mkv->track.bc) {
2285  int filler, output_sample_rate = 0;
2286  ret = get_aac_sample_rates(s, mkv, side_data, side_data_size,
2287  &track->sample_rate, &output_sample_rate);
2288  if (ret < 0)
2289  return ret;
2290  if (!output_sample_rate)
2291  output_sample_rate = track->sample_rate; // Space is already reserved, so it's this or a void element.
2292  ret = ff_alloc_extradata(par, side_data_size);
2293  if (ret < 0)
2294  return ret;
2295  memcpy(par->extradata, side_data, side_data_size);
2296  avio_seek(mkv->track.bc, track->codecpriv_offset, SEEK_SET);
2297  mkv_write_codecprivate(s, mkv->track.bc, par, 1, 0);
2298  filler = MAX_PCE_SIZE + 2 + 4 - (avio_tell(mkv->track.bc) - track->codecpriv_offset);
2299  if (filler)
2300  put_ebml_void(mkv->track.bc, filler);
2301  avio_seek(mkv->track.bc, track->sample_rate_offset, SEEK_SET);
2303  put_ebml_float(mkv->track.bc, MATROSKA_ID_AUDIOOUTSAMPLINGFREQ, output_sample_rate);
2304  } else if (!par->extradata_size && !track->sample_rate) {
2305  // No extradata (codecpar or packet side data).
2306  av_log(s, AV_LOG_ERROR, "Error parsing AAC extradata, unable to determine samplerate.\n");
2307  return AVERROR(EINVAL);
2308  }
2309  break;
2310  case AV_CODEC_ID_FLAC:
2311  if (side_data_size && mkv->track.bc) {
2312  uint8_t *old_extradata = par->extradata;
2313  if (side_data_size != par->extradata_size) {
2314  av_log(s, AV_LOG_ERROR, "Invalid FLAC STREAMINFO metadata for output stream %d\n",
2315  pkt->stream_index);
2316  return AVERROR(EINVAL);
2317  }
2318  par->extradata = side_data;
2319  avio_seek(mkv->track.bc, track->codecpriv_offset, SEEK_SET);
2320  mkv_write_codecprivate(s, mkv->track.bc, par, 1, 0);
2321  par->extradata = old_extradata;
2322  }
2323  break;
2324 #endif
2325  // FIXME: Remove the following once libaom starts propagating extradata during init()
2326  // See https://bugs.chromium.org/p/aomedia/issues/detail?id=2012
2327  case AV_CODEC_ID_AV1:
2328  if (side_data_size && mkv->track.bc && !par->extradata_size) {
2329  AVIOContext *dyn_cp;
2330  uint8_t *codecpriv;
2331  int codecpriv_size;
2332  ret = avio_open_dyn_buf(&dyn_cp);
2333  if (ret < 0)
2334  return ret;
2335  ff_isom_write_av1c(dyn_cp, side_data, side_data_size);
2336  codecpriv_size = avio_get_dyn_buf(dyn_cp, &codecpriv);
2337  if ((ret = dyn_cp->error) < 0 ||
2338  !codecpriv_size && (ret = AVERROR_INVALIDDATA)) {
2339  ffio_free_dyn_buf(&dyn_cp);
2340  return ret;
2341  }
2342  avio_seek(mkv->track.bc, track->codecpriv_offset, SEEK_SET);
2343  // Do not write the OBUs as we don't have space saved for them
2344  put_ebml_binary(mkv->track.bc, MATROSKA_ID_CODECPRIVATE, codecpriv, 4);
2345  ffio_free_dyn_buf(&dyn_cp);
2346  ret = ff_alloc_extradata(par, side_data_size);
2347  if (ret < 0)
2348  return ret;
2349  memcpy(par->extradata, side_data, side_data_size);
2350  } else if (!par->extradata_size)
2351  return AVERROR_INVALIDDATA;
2352  break;
2353  default:
2354  if (side_data_size)
2355  av_log(s, AV_LOG_DEBUG, "Ignoring new extradata in a packet for stream %d.\n", pkt->stream_index);
2356  break;
2357  }
2358 
2359  return 0;
2360 }
2361 
2363 {
2364  MatroskaMuxContext *mkv = s->priv_data;
2365  AVIOContext *pb;
2366  AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar;
2367  mkv_track *track = &mkv->tracks[pkt->stream_index];
2368  int keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY);
2369  int64_t duration = pkt->duration;
2370  int ret;
2371  int64_t ts = track->write_dts ? pkt->dts : pkt->pts;
2372  int64_t relative_packet_pos;
2373 
2374  if (ts == AV_NOPTS_VALUE) {
2375  av_log(s, AV_LOG_ERROR, "Can't write packet with unknown timestamp\n");
2376  return AVERROR(EINVAL);
2377  }
2378  ts += track->ts_offset;
2379 
2380  if (mkv->cluster_pos != -1) {
2381  int64_t cluster_time = ts - mkv->cluster_pts;
2382  if ((int16_t)cluster_time != cluster_time) {
2383  ret = mkv_end_cluster(s);
2384  if (ret < 0)
2385  return ret;
2386  av_log(s, AV_LOG_WARNING, "Starting new cluster due to timestamp\n");
2387  }
2388  }
2389 
2390  if (mkv->cluster_pos == -1) {
2391  ret = start_ebml_master_crc32(&mkv->cluster_bc, mkv);
2392  if (ret < 0)
2393  return ret;
2394  mkv->cluster_pos = avio_tell(s->pb);
2396  mkv->cluster_pts = FFMAX(0, ts);
2398  "Starting new cluster with timestamp "
2399  "%" PRId64 " at offset %" PRId64 " bytes\n",
2400  mkv->cluster_pts, mkv->cluster_pos);
2401  }
2402  pb = mkv->cluster_bc;
2403 
2404  relative_packet_pos = avio_tell(pb);
2405 
2406  if (par->codec_type != AVMEDIA_TYPE_SUBTITLE ||
2407  (par->codec_id != AV_CODEC_ID_WEBVTT && duration <= 0)) {
2408  ret = mkv_write_block(s, pb, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe);
2409  if (ret < 0)
2410  return ret;
2411  if (keyframe && IS_SEEKABLE(s->pb, mkv) &&
2412  (par->codec_type == AVMEDIA_TYPE_VIDEO ||
2414  !mkv->have_video && !track->has_cue)) {
2415  ret = mkv_add_cuepoint(mkv, pkt->stream_index, ts,
2416  mkv->cluster_pos, relative_packet_pos, 0);
2417  if (ret < 0)
2418  return ret;
2419  track->has_cue = 1;
2420  }
2421  } else {
2422  if (par->codec_id == AV_CODEC_ID_WEBVTT) {
2423  ret = mkv_write_vtt_blocks(s, pb, pkt);
2424  if (ret < 0)
2425  return ret;
2426  } else {
2429  track->track_num_size));
2430 
2431  /* All subtitle blocks are considered to be keyframes. */
2434  end_ebml_master(pb, blockgroup);
2435  }
2436 
2437  if (IS_SEEKABLE(s->pb, mkv)) {
2438  ret = mkv_add_cuepoint(mkv, pkt->stream_index, ts,
2439  mkv->cluster_pos, relative_packet_pos, duration);
2440  if (ret < 0)
2441  return ret;
2442  }
2443  }
2444 
2445  mkv->duration = FFMAX(mkv->duration, ts + duration);
2446  track->duration = FFMAX(track->duration, ts + duration);
2447 
2448  return 0;
2449 }
2450 
2452 {
2453  MatroskaMuxContext *mkv = s->priv_data;
2454  int codec_type = s->streams[pkt->stream_index]->codecpar->codec_type;
2455  int keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY);
2456  int cluster_size;
2457  int64_t cluster_time;
2458  int ret;
2459  int start_new_cluster;
2460 
2462  if (ret < 0)
2463  return ret;
2464 
2465  if (mkv->cluster_pos != -1) {
2466  if (mkv->tracks[pkt->stream_index].write_dts)
2467  cluster_time = pkt->dts - mkv->cluster_pts;
2468  else
2469  cluster_time = pkt->pts - mkv->cluster_pts;
2470  cluster_time += mkv->tracks[pkt->stream_index].ts_offset;
2471 
2472  cluster_size = avio_tell(mkv->cluster_bc);
2473 
2474  if (mkv->is_dash && codec_type == AVMEDIA_TYPE_VIDEO) {
2475  // WebM DASH specification states that the first block of
2476  // every Cluster has to be a key frame. So for DASH video,
2477  // we only create a Cluster on seeing key frames.
2478  start_new_cluster = keyframe;
2479  } else if (mkv->is_dash && codec_type == AVMEDIA_TYPE_AUDIO &&
2480  cluster_time > mkv->cluster_time_limit) {
2481  // For DASH audio, we create a Cluster based on cluster_time_limit.
2482  start_new_cluster = 1;
2483  } else if (!mkv->is_dash &&
2484  (cluster_size > mkv->cluster_size_limit ||
2485  cluster_time > mkv->cluster_time_limit ||
2486  (codec_type == AVMEDIA_TYPE_VIDEO && keyframe &&
2487  cluster_size > 4 * 1024))) {
2488  start_new_cluster = 1;
2489  } else
2490  start_new_cluster = 0;
2491 
2492  if (start_new_cluster) {
2493  ret = mkv_end_cluster(s);
2494  if (ret < 0)
2495  return ret;
2496  }
2497  }
2498 
2499  if (!mkv->cluster_pos)
2500  avio_write_marker(s->pb,
2501  av_rescale_q(pkt->dts, s->streams[pkt->stream_index]->time_base, AV_TIME_BASE_Q),
2503 
2504  // check if we have an audio packet cached
2505  if (mkv->cur_audio_pkt->size > 0) {
2508  if (ret < 0) {
2510  "Could not write cached audio packet ret:%d\n", ret);
2511  return ret;
2512  }
2513  }
2514 
2515  // buffer an audio packet to ensure the packet containing the video
2516  // keyframe's timecode is contained in the same cluster for WebM
2517  if (codec_type == AVMEDIA_TYPE_AUDIO) {
2518  if (pkt->size > 0)
2520  } else
2522  return ret;
2523 }
2524 
2526 {
2527  MatroskaMuxContext *mkv = s->priv_data;
2528 
2529  if (!pkt) {
2530  if (mkv->cluster_pos != -1) {
2531  int ret = mkv_end_cluster(s);
2532  if (ret < 0)
2533  return ret;
2535  "Flushing cluster at offset %" PRIu64 " bytes\n",
2536  avio_tell(s->pb));
2537  }
2538  return 1;
2539  }
2540  return mkv_write_packet(s, pkt);
2541 }
2542 
2544 {
2545  MatroskaMuxContext *mkv = s->priv_data;
2546  AVIOContext *pb = s->pb;
2547  int64_t endpos, ret64;
2548  int ret, ret2 = 0;
2549 
2550  // check if we have an audio packet cached
2551  if (mkv->cur_audio_pkt->size > 0) {
2553  if (ret < 0) {
2555  "Could not write cached audio packet ret:%d\n", ret);
2556  return ret;
2557  }
2558  }
2559 
2560  if (mkv->cluster_pos != -1) {
2561  ret = end_ebml_master_crc32(pb, &mkv->cluster_bc, mkv,
2562  MATROSKA_ID_CLUSTER, 0, 0, 0);
2563  if (ret < 0)
2564  return ret;
2565  }
2566 
2568  if (ret < 0)
2569  return ret;
2570 
2571  if (!IS_SEEKABLE(pb, mkv))
2572  return 0;
2573 
2574  endpos = avio_tell(pb);
2575 
2576  if (mkv->cues.num_entries && mkv->reserve_cues_space >= 0) {
2577  AVIOContext *cues = NULL;
2578  uint64_t size;
2579  int length_size = 0;
2580 
2581  ret = start_ebml_master_crc32(&cues, mkv);
2582  if (ret < 0)
2583  return ret;
2584 
2585  ret = mkv_assemble_cues(s->streams, cues, &mkv->cues,
2586  mkv->tracks, s->nb_streams);
2587  if (ret < 0) {
2588  ffio_free_dyn_buf(&cues);
2589  return ret;
2590  }
2591 
2592  if (mkv->reserve_cues_space) {
2593  size = avio_tell(cues);
2594  length_size = ebml_length_size(size);
2595  size += 4 + length_size;
2596  if (mkv->reserve_cues_space < size) {
2598  "Insufficient space reserved for Cues: "
2599  "%d < %"PRIu64". No Cues will be output.\n",
2600  mkv->reserve_cues_space, size);
2601  ret2 = AVERROR(EINVAL);
2602  goto after_cues;
2603  } else {
2604  if ((ret64 = avio_seek(pb, mkv->cues_pos, SEEK_SET)) < 0) {
2605  ffio_free_dyn_buf(&cues);
2606  return ret64;
2607  }
2608  if (mkv->reserve_cues_space == size + 1) {
2609  /* There is no way to reserve a single byte because
2610  * the minimal size of an EBML Void element is 2
2611  * (1 byte ID, 1 byte length field). This problem
2612  * is solved by writing the Cues' length field on
2613  * one byte more than necessary. */
2614  length_size++;
2615  size++;
2616  }
2617  }
2618  }
2619  ret = end_ebml_master_crc32(pb, &cues, mkv, MATROSKA_ID_CUES,
2620  length_size, 0, 1);
2621  if (ret < 0)
2622  return ret;
2623  if (mkv->reserve_cues_space) {
2624  if (size < mkv->reserve_cues_space)
2626  } else
2627  endpos = avio_tell(pb);
2628  }
2629 
2630 after_cues:
2631  /* Lengths greater than (1ULL << 56) - 1 can't be represented
2632  * via an EBML number, so leave the unknown length field. */
2633  if (endpos - mkv->segment_offset < (1ULL << 56) - 1) {
2634  if ((ret64 = avio_seek(pb, mkv->segment_offset - 8, SEEK_SET)) < 0)
2635  return ret64;
2636  put_ebml_length(pb, endpos - mkv->segment_offset, 8);
2637  }
2638 
2639  ret = mkv_write_seekhead(pb, mkv, 1, mkv->info.pos);
2640  if (ret < 0)
2641  return ret;
2642 
2643  if (mkv->info.bc) {
2644  // update the duration
2645  av_log(s, AV_LOG_DEBUG, "end duration = %" PRIu64 "\n", mkv->duration);
2646  avio_seek(mkv->info.bc, mkv->duration_offset, SEEK_SET);
2648  ret = end_ebml_master_crc32(pb, &mkv->info.bc, mkv,
2649  MATROSKA_ID_INFO, 0, 0, 0);
2650  if (ret < 0)
2651  return ret;
2652  }
2653 
2654  if (mkv->track.bc) {
2655  // write Tracks master
2656  avio_seek(pb, mkv->track.pos, SEEK_SET);
2657  ret = end_ebml_master_crc32(pb, &mkv->track.bc, mkv,
2658  MATROSKA_ID_TRACKS, 0, 0, 0);
2659  if (ret < 0)
2660  return ret;
2661  }
2662 
2663  // update stream durations
2664  if (mkv->tags.bc) {
2665  int i;
2666  for (i = 0; i < s->nb_streams; ++i) {
2667  const AVStream *st = s->streams[i];
2668  const mkv_track *track = &mkv->tracks[i];
2669 
2670  if (track->duration_offset > 0) {
2671  double duration_sec = track->duration * av_q2d(st->time_base);
2672  char duration_string[20] = "";
2673 
2674  av_log(s, AV_LOG_DEBUG, "stream %d end duration = %" PRIu64 "\n", i,
2675  track->duration);
2676 
2677  avio_seek(mkv->tags.bc, track->duration_offset, SEEK_SET);
2678 
2679  snprintf(duration_string, 20, "%02d:%02d:%012.9f",
2680  (int) duration_sec / 3600, ((int) duration_sec / 60) % 60,
2681  fmod(duration_sec, 60));
2682 
2683  put_ebml_binary(mkv->tags.bc, MATROSKA_ID_TAGSTRING, duration_string, 20);
2684  }
2685  }
2686 
2687  avio_seek(pb, mkv->tags.pos, SEEK_SET);
2688  ret = end_ebml_master_crc32(pb, &mkv->tags.bc, mkv,
2689  MATROSKA_ID_TAGS, 0, 0, 0);
2690  if (ret < 0)
2691  return ret;
2692  }
2693 
2694  avio_seek(pb, endpos, SEEK_SET);
2695 
2696  return ret2;
2697 }
2698 
2699 static uint64_t mkv_get_uid(const mkv_track *tracks, int i, AVLFG *c)
2700 {
2701  while (1) {
2702  uint64_t uid;
2703  int k;
2704  uid = (uint64_t)av_lfg_get(c) << 32;
2705  uid |= av_lfg_get(c);
2706  if (!uid)
2707  continue;
2708  for (k = 0; k < i; k++) {
2709  if (tracks[k].uid == uid)
2710  break;
2711  }
2712  if (k == i)
2713  return uid;
2714  }
2715 }
2716 
2717 static int mkv_init(struct AVFormatContext *s)
2718 {
2719  FFFormatContext *const si = ffformatcontext(s);
2720  MatroskaMuxContext *mkv = s->priv_data;
2721  AVLFG c;
2722  unsigned nb_tracks = 0;
2723  int i;
2724 
2725  for (i = 0; i < s->nb_streams; i++) {
2726  if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_ATRAC3 ||
2727  s->streams[i]->codecpar->codec_id == AV_CODEC_ID_COOK ||
2728  s->streams[i]->codecpar->codec_id == AV_CODEC_ID_RA_288 ||
2729  s->streams[i]->codecpar->codec_id == AV_CODEC_ID_SIPR ||
2730  s->streams[i]->codecpar->codec_id == AV_CODEC_ID_RV10 ||
2731  s->streams[i]->codecpar->codec_id == AV_CODEC_ID_RV20) {
2733  "The Matroska muxer does not yet support muxing %s\n",
2734  avcodec_get_name(s->streams[i]->codecpar->codec_id));
2735  return AVERROR_PATCHWELCOME;
2736  }
2737  }
2738 
2739  if (s->avoid_negative_ts < 0) {
2740  s->avoid_negative_ts = 1;
2741  si->avoid_negative_ts_use_pts = 1;
2742  }
2743 
2744  if (!CONFIG_MATROSKA_MUXER ||
2745  (CONFIG_WEBM_MUXER && !strcmp(s->oformat->name, "webm"))) {
2746  mkv->mode = MODE_WEBM;
2747  mkv->write_crc = 0;
2748  } else
2749  mkv->mode = MODE_MATROSKAv2;
2750 
2752 
2753  mkv->tracks = av_calloc(s->nb_streams, sizeof(*mkv->tracks));
2754  if (!mkv->tracks)
2755  return AVERROR(ENOMEM);
2756 
2757  if (!(s->flags & AVFMT_FLAG_BITEXACT)) {
2759 
2760  // Calculate the SegmentUID now in order not to waste our random seed.
2761  for (i = 0; i < 4; i++)
2762  mkv->segment_uid[i] = av_lfg_get(&c);
2763  }
2764 
2765  for (i = 0; i < s->nb_streams; i++) {
2766  AVStream *st = s->streams[i];
2767  mkv_track *track = &mkv->tracks[i];
2768 
2769  if (s->flags & AVFMT_FLAG_BITEXACT) {
2770  track->uid = i + 1;
2771  } else {
2772  track->uid = mkv_get_uid(mkv->tracks, i, &c);
2773  }
2774 
2775  // ms precision is the de-facto standard timescale for mkv files
2776  avpriv_set_pts_info(st, 64, 1, 1000);
2777 
2779  if (IS_WEBM(mkv)) {
2780  av_log(s, AV_LOG_WARNING, "Stream %d will be ignored "
2781  "as WebM doesn't support attachments.\n", i);
2782  } else if (!get_mimetype(st)) {
2783  av_log(s, AV_LOG_ERROR, "Attachment stream %d has no mimetype "
2784  "tag and it cannot be deduced from the codec id.\n", i);
2785  return AVERROR(EINVAL);
2786  }
2787  mkv->nb_attachments++;
2788  continue;
2789  }
2790 
2791  nb_tracks++;
2792  track->track_num = mkv->is_dash ? mkv->dash_track_number : nb_tracks;
2793  track->track_num_size = ebml_num_size(track->track_num);
2794  }
2795 
2796  if (mkv->is_dash && nb_tracks != 1)
2797  return AVERROR(EINVAL);
2798 
2799  return 0;
2800 }
2801 
2803  const AVPacket *pkt)
2804 {
2805  int ret = 1;
2806 
2807  if (CONFIG_MATROSKA_MUXER && st->codecpar->codec_id == AV_CODEC_ID_AAC) {
2808  if (pkt->size > 2 && (AV_RB16(pkt->data) & 0xfff0) == 0xfff0)
2809  ret = ff_stream_add_bitstream_filter(st, "aac_adtstoasc", NULL);
2810  } else if (st->codecpar->codec_id == AV_CODEC_ID_VP9) {
2811  ret = ff_stream_add_bitstream_filter(st, "vp9_superframe", NULL);
2812  }
2813 
2814  return ret;
2815 }
2816 
2818  { AV_CODEC_ID_ALAC, 0XFFFFFFFF },
2819  { AV_CODEC_ID_MLP, 0xFFFFFFFF },
2820  { AV_CODEC_ID_OPUS, 0xFFFFFFFF },
2821  { AV_CODEC_ID_PCM_S16BE, 0xFFFFFFFF },
2822  { AV_CODEC_ID_PCM_S24BE, 0xFFFFFFFF },
2823  { AV_CODEC_ID_PCM_S32BE, 0xFFFFFFFF },
2824  { AV_CODEC_ID_QDMC, 0xFFFFFFFF },
2825  { AV_CODEC_ID_QDM2, 0xFFFFFFFF },
2826  { AV_CODEC_ID_RA_144, 0xFFFFFFFF },
2827  { AV_CODEC_ID_RA_288, 0xFFFFFFFF },
2828  { AV_CODEC_ID_COOK, 0xFFFFFFFF },
2829  { AV_CODEC_ID_TRUEHD, 0xFFFFFFFF },
2830  { AV_CODEC_ID_NONE, 0xFFFFFFFF }
2831 };
2832 
2834  { AV_CODEC_ID_RV10, 0xFFFFFFFF },
2835  { AV_CODEC_ID_RV20, 0xFFFFFFFF },
2836  { AV_CODEC_ID_RV30, 0xFFFFFFFF },
2837  { AV_CODEC_ID_NONE, 0xFFFFFFFF }
2838 };
2839 
2841  { AV_CODEC_ID_DVB_SUBTITLE, 0xFFFFFFFF },
2842  { AV_CODEC_ID_DVD_SUBTITLE, 0xFFFFFFFF },
2843  { AV_CODEC_ID_HDMV_PGS_SUBTITLE, 0xFFFFFFFF },
2844  { AV_CODEC_ID_NONE, 0xFFFFFFFF }
2845 };
2846 
2847 #define OFFSET(x) offsetof(MatroskaMuxContext, x)
2848 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM
2849 static const AVOption options[] = {
2850  { "reserve_index_space", "Reserve a given amount of space (in bytes) at the beginning of the file for the index (cues).", OFFSET(reserve_cues_space), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
2851  { "cluster_size_limit", "Store at most the provided amount of bytes in a cluster. ", OFFSET(cluster_size_limit), AV_OPT_TYPE_INT , { .i64 = -1 }, -1, INT_MAX, FLAGS },
2852  { "cluster_time_limit", "Store at most the provided number of milliseconds in a cluster.", OFFSET(cluster_time_limit), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, FLAGS },
2853  { "dash", "Create a WebM file conforming to WebM DASH specification", OFFSET(is_dash), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
2854  { "dash_track_number", "Track number for the DASH stream", OFFSET(dash_track_number), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, INT_MAX, FLAGS },
2855  { "live", "Write files assuming it is a live stream.", OFFSET(is_live), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
2856  { "allow_raw_vfw", "allow RAW VFW mode", OFFSET(allow_raw_vfw), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
2857  { "flipped_raw_rgb", "Raw RGB bitmaps in VFW mode are stored bottom-up", OFFSET(flipped_raw_rgb), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
2858  { "write_crc32", "write a CRC32 element inside every Level 1 element", OFFSET(write_crc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
2859  { "default_mode", "Controls how a track's FlagDefault is inferred", OFFSET(default_mode), AV_OPT_TYPE_INT, { .i64 = DEFAULT_MODE_PASSTHROUGH }, DEFAULT_MODE_INFER, DEFAULT_MODE_PASSTHROUGH, FLAGS, "default_mode" },
2860  { "infer", "For each track type, mark each track of disposition default as default; if none exists, mark the first track as default.", 0, AV_OPT_TYPE_CONST, { .i64 = DEFAULT_MODE_INFER }, 0, 0, FLAGS, "default_mode" },
2861  { "infer_no_subs", "For each track type, mark each track of disposition default as default; for audio and video: if none exists, mark the first track as default.", 0, AV_OPT_TYPE_CONST, { .i64 = DEFAULT_MODE_INFER_NO_SUBS }, 0, 0, FLAGS, "default_mode" },
2862  { "passthrough", "Use the disposition flag as-is", 0, AV_OPT_TYPE_CONST, { .i64 = DEFAULT_MODE_PASSTHROUGH }, 0, 0, FLAGS, "default_mode" },
2863  { NULL },
2864 };
2865 
2867  .class_name = "matroska/webm muxer",
2868  .item_name = av_default_item_name,
2869  .option = options,
2870  .version = LIBAVUTIL_VERSION_INT,
2871 };
2872 
2873 #if CONFIG_MATROSKA_MUXER
2874 static int mkv_query_codec(enum AVCodecID codec_id, int std_compliance)
2875 {
2876  for (int i = 0; ff_mkv_codec_tags[i].id != AV_CODEC_ID_NONE; i++)
2877  if (ff_mkv_codec_tags[i].id == codec_id)
2878  return 1;
2879 
2880  if (std_compliance < FF_COMPLIANCE_NORMAL) {
2882  // mkv theoretically supports any video/audio through VFW/ACM
2884  return 1;
2885  }
2886 
2887  return 0;
2888 }
2889 
2891  .name = "matroska",
2892  .long_name = NULL_IF_CONFIG_SMALL("Matroska"),
2893  .mime_type = "video/x-matroska",
2894  .extensions = "mkv",
2895  .priv_data_size = sizeof(MatroskaMuxContext),
2896  .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
2898  .video_codec = CONFIG_LIBX264_ENCODER ?
2900  .init = mkv_init,
2901  .deinit = mkv_deinit,
2907  .codec_tag = (const AVCodecTag* const []){
2910  },
2911  .subtitle_codec = AV_CODEC_ID_ASS,
2912  .query_codec = mkv_query_codec,
2913  .check_bitstream = mkv_check_bitstream,
2914  .priv_class = &matroska_webm_class,
2915 };
2916 #endif
2917 
2918 #if CONFIG_WEBM_MUXER
2919 static int webm_query_codec(enum AVCodecID codec_id, int std_compliance)
2920 {
2921  for (int i = 0; ff_webm_codec_tags[i].id != AV_CODEC_ID_NONE; i++)
2922  if (ff_webm_codec_tags[i].id == codec_id)
2923  return 1;
2924 
2925  return 0;
2926 }
2927 
2928 const AVOutputFormat ff_webm_muxer = {
2929  .name = "webm",
2930  .long_name = NULL_IF_CONFIG_SMALL("WebM"),
2931  .mime_type = "video/webm",
2932  .extensions = "webm",
2933  .priv_data_size = sizeof(MatroskaMuxContext),
2934  .audio_codec = CONFIG_LIBOPUS_ENCODER ? AV_CODEC_ID_OPUS : AV_CODEC_ID_VORBIS,
2935  .video_codec = CONFIG_LIBVPX_VP9_ENCODER? AV_CODEC_ID_VP9 : AV_CODEC_ID_VP8,
2936  .subtitle_codec = AV_CODEC_ID_WEBVTT,
2937  .init = mkv_init,
2938  .deinit = mkv_deinit,
2942  .query_codec = webm_query_codec,
2946  .priv_class = &matroska_webm_class,
2947 };
2948 #endif
2949 
2950 #if CONFIG_MATROSKA_AUDIO_MUXER
2952  .name = "matroska",
2953  .long_name = NULL_IF_CONFIG_SMALL("Matroska Audio"),
2954  .mime_type = "audio/x-matroska",
2955  .extensions = "mka",
2956  .priv_data_size = sizeof(MatroskaMuxContext),
2957  .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
2959  .video_codec = AV_CODEC_ID_NONE,
2960  .init = mkv_init,
2961  .deinit = mkv_deinit,
2968  .codec_tag = (const AVCodecTag* const []){
2970  },
2971  .priv_class = &matroska_webm_class,
2972 };
2973 #endif
MatroskaMuxContext::reserve_cues_space
int reserve_cues_space
Definition: matroskaenc.c:153
MATROSKA_ID_TAGTARGETS_ATTACHUID
#define MATROSKA_ID_TAGTARGETS_ATTACHUID
Definition: matroska.h:226
AVMasteringDisplayMetadata::has_primaries
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
Definition: mastering_display_metadata.h:62
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:424
MATROSKA_ID_VIDEODISPLAYUNIT
#define MATROSKA_ID_VIDEODISPLAYUNIT
Definition: matroska.h:126
MATROSKA_ID_CODECPRIVATE
#define MATROSKA_ID_CODECPRIVATE
Definition: matroska.h:89
MATROSKA_ID_TRACKNUMBER
#define MATROSKA_ID_TRACKNUMBER
Definition: matroska.h:78
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
MATROSKA_ID_TRACKFLAGVISUALIMPAIRED
#define MATROSKA_ID_TRACKFLAGVISUALIMPAIRED
Definition: matroska.h:102
bit_depth
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
Definition: af_astats.c:226
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
MatroskaMuxContext::is_dash
int is_dash
Definition: matroskaenc.c:159
MATROSKA_ID_CHAPSTRING
#define MATROSKA_ID_CHAPSTRING
Definition: matroska.h:267
mkv_write_dovi
static void mkv_write_dovi(AVFormatContext *s, AVIOContext *pb, AVStream *st)
Definition: matroskaenc.c:1135
IS_SEEKABLE
#define IS_SEEKABLE(pb, mkv)
Definition: matroskaenc.c:69
mkv_init
static int mkv_init(struct AVFormatContext *s)
Definition: matroskaenc.c:2717
MATROSKA_ID_TAGTARGETS
#define MATROSKA_ID_TAGTARGETS
Definition: matroska.h:221
AVMasteringDisplayMetadata::max_luminance
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:57
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:74
name
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 default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
MATROSKA_ID_CLUSTERTIMECODE
#define MATROSKA_ID_CLUSTERTIMECODE
Definition: matroska.h:236
LIBAVFORMAT_IDENT
#define LIBAVFORMAT_IDENT
Definition: version.h:46
ebml_num_size
static int ebml_num_size(uint64_t num)
Returns how many bytes are needed to represent a number as EBML variable length integer.
Definition: matroskaenc.c:212
AV_CODEC_ID_AC3
@ AV_CODEC_ID_AC3
Definition: codec_id.h:426
AVIO_DATA_MARKER_BOUNDARY_POINT
@ AVIO_DATA_MARKER_BOUNDARY_POINT
A point in the output bytestream where a demuxer can start parsing (for non self synchronizing bytest...
Definition: avio.h:128
ebml_header
static EbmlSyntax ebml_header[]
Definition: matroskadec.c:430
mkv_write_packet
static int mkv_write_packet(AVFormatContext *s, const AVPacket *pkt)
Definition: matroskaenc.c:2451
AVOutputFormat::name
const char * name
Definition: avformat.h:504
MATROSKA_ID_TITLE
#define MATROSKA_ID_TITLE
Definition: matroska.h:68
AVERROR
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
uid
UID uid
Definition: mxfenc.c:2198
opt.h
put_ebml_size_unknown
static void put_ebml_size_unknown(AVIOContext *pb, int bytes)
Write an EBML size meaning "unknown size".
Definition: matroskaenc.c:199
mkv_write_packet_internal
static int mkv_write_packet_internal(AVFormatContext *s, const AVPacket *pkt)
Definition: matroskaenc.c:2362
MatroskaMuxContext::allow_raw_vfw
int allow_raw_vfw
Definition: matroskaenc.c:161
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
AVSphericalMapping::projection
enum AVSphericalProjection projection
Projection type.
Definition: spherical.h:86
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
hevc.h
AVSphericalMapping::bound_bottom
uint32_t bound_bottom
Distance from the bottom edge.
Definition: spherical.h:170
MATROSKA_ID_VIDEOCOLORMASTERINGMETA
#define MATROSKA_ID_VIDEOCOLORMASTERINGMETA
Definition: matroska.h:150
MatroskaMuxContext::segment_offset
int64_t segment_offset
Definition: matroskaenc.c:134
av_lfg_init
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition: lfg.c:32
MatroskaMuxContext::tracks
mkv_track * tracks
Definition: matroskaenc.c:140
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:52
EBML_ID_EBMLMAXSIZELENGTH
#define EBML_ID_EBMLMAXSIZELENGTH
Definition: matroska.h:39
ffformatcontext
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition: internal.h:189
mkv_new_chapter_ids_needed
static int mkv_new_chapter_ids_needed(const AVFormatContext *s)
Definition: matroskaenc.c:1682
AVCodecParameters::color_space
enum AVColorSpace color_space
Definition: codec_par.h:149
end_ebml_master_crc32
static int end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, uint32_t id, int length_size, int keep_buffer, int add_seekentry)
Definition: matroskaenc.c:388
MATROSKA_ID_TRACKFLAGTEXTDESCRIPTIONS
#define MATROSKA_ID_TRACKFLAGTEXTDESCRIPTIONS
Definition: matroska.h:103
AVFMT_VARIABLE_FPS
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:478
avcodec_get_type
enum AVMediaType avcodec_get_type(enum AVCodecID codec_id)
Get the type of the given codec.
Definition: codec_desc.c:3546
MATROSKA_ID_VIDEOPIXELWIDTH
#define MATROSKA_ID_VIDEOPIXELWIDTH
Definition: matroska.h:120
MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_LR
@ MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_LR
Definition: matroska.h:319
mkv_track::duration
int64_t duration
Definition: matroskaenc.c:122
MATROSKA_ID_AUDIOSAMPLINGFREQ
#define MATROSKA_ID_AUDIOSAMPLINGFREQ
Definition: matroska.h:170
MatroskaMuxContext::cluster_bc
AVIOContext * cluster_bc
Definition: matroskaenc.c:135
OPUS_SEEK_PREROLL
#define OPUS_SEEK_PREROLL
Seek preroll value for opus.
Definition: matroskaenc.c:180
AVMasteringDisplayMetadata::display_primaries
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
Definition: mastering_display_metadata.h:42
MODE_MATROSKAv2
#define MODE_MATROSKAv2
Definition: matroskaenc.c:64
AVMasteringDisplayMetadata::has_luminance
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
Definition: mastering_display_metadata.h:67
ff_put_bmp_header
void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par, int for_asf, int ignore_extradata, int rgb_frame_is_flipped)
Definition: riffenc.c:216
rational.h
MATROSKA_ID_DISCARDPADDING
#define MATROSKA_ID_DISCARDPADDING
Definition: matroska.h:251
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
MATROSKA_VIDEO_FIELDORDER_BB
@ MATROSKA_VIDEO_FIELDORDER_BB
Definition: matroska.h:308
MATROSKA_ID_DURATION
#define MATROSKA_ID_DURATION
Definition: matroska.h:67
MATROSKA_ID_VIDEOCOLORCHROMASITINGVERT
#define MATROSKA_ID_VIDEOCOLORCHROMASITINGVERT
Definition: matroska.h:142
avlanguage.h
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:215
MATROSKA_ID_VIDEOCOLORPRIMARIES
#define MATROSKA_ID_VIDEOCOLORPRIMARIES
Definition: matroska.h:146
AV_CODEC_ID_RAWVIDEO
@ AV_CODEC_ID_RAWVIDEO
Definition: codec_id.h:63
ff_webm_muxer
const AVOutputFormat ff_webm_muxer
av_unused
#define av_unused
Definition: attributes.h:131
check_bitstream
static int check_bitstream(AVFormatContext *s, FFStream *sti, AVPacket *pkt)
Definition: mux.c:1062
MATROSKA_ID_SEGMENT
#define MATROSKA_ID_SEGMENT
Definition: matroska.h:53
AV_DISPOSITION_DEFAULT
#define AV_DISPOSITION_DEFAULT
The stream should be chosen by default among other streams of the same type, unless the user has expl...
Definition: avformat.h:820
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:62
MATROSKA_ID_BLKADDIDTYPE
#define MATROSKA_ID_BLKADDIDTYPE
Definition: matroska.h:196
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:102
MatroskaMuxContext::dash_track_number
int dash_track_number
Definition: matroskaenc.c:160
AV_CODEC_ID_RA_144
@ AV_CODEC_ID_RA_144
Definition: codec_id.h:410
MATROSKA_ID_CHAPTERS
#define MATROSKA_ID_CHAPTERS
Definition: matroska.h:63
AVCOL_TRC_NB
@ AVCOL_TRC_NB
Not part of ABI.
Definition: pixfmt.h:516
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
MATROSKA_ID_VIDEOCOLOR_BY
#define MATROSKA_ID_VIDEOCOLOR_BY
Definition: matroska.h:156
deinit
static void deinit(AVFormatContext *s)
Definition: chromaprint.c:50
MATROSKA_ID_BLOCKDURATION
#define MATROSKA_ID_BLOCKDURATION
Definition: matroska.h:248
MATROSKA_ID_VIDEOCOLORRANGE
#define MATROSKA_ID_VIDEOCOLORRANGE
Definition: matroska.h:143
MATROSKA_ID_BLOCK
#define MATROSKA_ID_BLOCK
Definition: matroska.h:247
AVPacket::data
uint8_t * data
Definition: packet.h:373
MATROSKA_ID_TRACKDEFAULTDURATION
#define MATROSKA_ID_TRACKDEFAULTDURATION
Definition: matroska.h:109
vorbiscomment.h
targets
FFmpeg currently uses a custom build this text attempts to document some of its obscure features and options Makefile the full command issued by make and its output will be shown on the screen DBG Preprocess x86 external assembler files to a dbg asm file in the object which then gets compiled Helps in developing those assembler files DESTDIR Destination directory for the install targets
Definition: build_system.txt:16
put_xiph_size
static void put_xiph_size(AVIOContext *pb, int size)
Definition: matroskaenc.c:448
AVOption
AVOption.
Definition: opt.h:247
AVCOL_SPC_NB
@ AVCOL_SPC_NB
Not part of ABI.
Definition: pixfmt.h:540
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:497
MatroskaMuxContext::mode
int mode
Definition: matroskaenc.c:130
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:1015
mkv_track::duration_offset
int64_t duration_offset
Definition: matroskaenc.c:123
data
const char data[16]
Definition: mxf.c:143
MATROSKA_VIDEO_INTERLACE_FLAG_INTERLACED
@ MATROSKA_VIDEO_INTERLACE_FLAG_INTERLACED
Definition: matroska.h:300
MatroskaMuxContext::cluster_pts
int64_t cluster_pts
Definition: matroskaenc.c:137
mkv_write_attachments
static int mkv_write_attachments(AVFormatContext *s)
Definition: matroskaenc.c:1792
AV_CODEC_ID_ALAC
@ AV_CODEC_ID_ALAC
Definition: codec_id.h:439
MATROSKA_ID_DATEUTC
#define MATROSKA_ID_DATEUTC
Definition: matroska.h:71
ebml_id_size
static int ebml_id_size(uint32_t id)
Definition: matroskaenc.c:182
flacenc.h
AVIOContext::error
int error
contains the error code or 0 if no error happened
Definition: avio.h:240
ff_parse_creation_time_metadata
int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds)
Parse creation_time in AVFormatContext metadata if exists and warn if the parsing fails.
Definition: utils.c:1866
MatroskaMuxContext::tags
ebml_stored_master tags
Definition: matroskaenc.c:133
AV_DICT_IGNORE_SUFFIX
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
Definition: dict.h:68
MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_LR
@ MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_LR
Definition: matroska.h:327
matroska.h
ff_codec_wav_tags
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:509
mkv_track::ts_offset
int64_t ts_offset
Definition: matroskaenc.c:125
put_ebml_binary
static void put_ebml_binary(AVIOContext *pb, uint32_t elementid, const void *buf, int size)
Definition: matroskaenc.c:306
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:391
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:64
ff_isom_write_av1c
int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size)
Writes AV1 extradata (Sequence Header and Metadata OBUs) to the provided AVIOContext.
Definition: av1.c:364
AV_SPHERICAL_EQUIRECTANGULAR_TILE
@ AV_SPHERICAL_EQUIRECTANGULAR_TILE
Video represents a portion of a sphere mapped on a flat surface using equirectangular projection.
Definition: spherical.h:72
max
#define max(a, b)
Definition: cuda_runtime.h:33
mathematics.h
MATROSKA_ID_CUES
#define MATROSKA_ID_CUES
Definition: matroska.h:58
AVDictionary
Definition: dict.c:30
AV_CODEC_ID_FLAC
@ AV_CODEC_ID_FLAC
Definition: codec_id.h:435
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
MATROSKA_ID_CUETIME
#define MATROSKA_ID_CUETIME
Definition: matroska.h:203
ff_isom_put_dvcc_dvvc
void ff_isom_put_dvcc_dvvc(AVFormatContext *s, uint8_t out[ISOM_DVCC_DVVC_SIZE], AVDOVIDecoderConfigurationRecord *dovi)
Definition: dovi_isom.c:85
IS_WEBM
#define IS_WEBM(mkv)
Definition: matroskaenc.c:67
WvHeader
Definition: wv.h:34
AV_PKT_DATA_SPHERICAL
@ AV_PKT_DATA_SPHERICAL
This side data should be associated with a video stream and corresponds to the AVSphericalMapping str...
Definition: packet.h:228
MATROSKA_ID_CUERELATIVEPOSITION
#define MATROSKA_ID_CUERELATIVEPOSITION
Definition: matroska.h:209
MAX_PCE_SIZE
#define MAX_PCE_SIZE
Maximum size of a PCE including the 3-bit ID_PCE.
Definition: mpeg4audio.h:120
ff_flac_is_native_layout
int ff_flac_is_native_layout(uint64_t channel_layout)
Definition: flacenc_header.c:50
AV_CODEC_ID_HDMV_PGS_SUBTITLE
@ AV_CODEC_ID_HDMV_PGS_SUBTITLE
Definition: codec_id.h:528
AV_SPHERICAL_EQUIRECTANGULAR
@ AV_SPHERICAL_EQUIRECTANGULAR
Video represents a sphere mapped on a flat surface using equirectangular projection.
Definition: spherical.h:56
intfloat.h
codec_type
enum AVMediaType codec_type
Definition: rtp.c:37
MatroskaMuxContext::flipped_raw_rgb
int flipped_raw_rgb
Definition: matroskaenc.c:162
MATROSKA_ID_CHAPLANG
#define MATROSKA_ID_CHAPLANG
Definition: matroska.h:268
AV_CODEC_ID_TRUEHD
@ AV_CODEC_ID_TRUEHD
Definition: codec_id.h:467
MATROSKA_ID_CUEDURATION
#define MATROSKA_ID_CUEDURATION
Definition: matroska.h:210
avio_get_dyn_buf
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1483
FFIOContext
Definition: avio_internal.h:29
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:428
sample_rate
sample_rate
Definition: ffmpeg_filter.c:153
MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_LR
@ MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_LR
Definition: matroska.h:321
AV_WB64
#define AV_WB64(p, v)
Definition: intreadwrite.h:433
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
MatroskaMuxContext::cues_pos
int64_t cues_pos
Definition: matroskaenc.c:143
av_get_random_seed
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
Definition: random_seed.c:120
xiph.h
MatroskaMuxContext::cluster_size_limit
int cluster_size_limit
Definition: matroskaenc.c:154
init
static int init
Definition: av_tx.c:47
MATROSKA_VIDEO_DISPLAYUNIT_UNKNOWN
@ MATROSKA_VIDEO_DISPLAYUNIT_UNKNOWN
Definition: matroska.h:337
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:98
MATROSKA_ID_VIDEOCOLOR_LUMINANCEMAX
#define MATROSKA_ID_VIDEOCOLOR_LUMINANCEMAX
Definition: matroska.h:159
MPEG4AudioConfig
Definition: mpeg4audio.h:32
crc.h
avio_wl16
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:466
AVCodecParameters::color_primaries
enum AVColorPrimaries color_primaries
Definition: codec_par.h:147
avio_write_marker
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
Definition: aviobuf.c:490
MATROSKA_ID_VIDEOCOLOR_WHITEY
#define MATROSKA_ID_VIDEOCOLOR_WHITEY
Definition: matroska.h:158
AV_STEREO3D_SIDEBYSIDE
@ AV_STEREO3D_SIDEBYSIDE
Views are next to each other.
Definition: stereo3d.h:67
avcodec_enum_to_chroma_pos
int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
Converts AVChromaLocation to swscale x/y chroma position.
Definition: utils.c:352
start_ebml_master
static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid, uint64_t expectedsize)
Definition: matroskaenc.c:344
DVCC_DVVC_BLOCK_TYPE_NAME
#define DVCC_DVVC_BLOCK_TYPE_NAME
Definition: matroska.h:395
AV_CODEC_ID_ASS
@ AV_CODEC_ID_ASS
Definition: codec_id.h:544
AVCodecParameters::channels
int channels
Audio only.
Definition: codec_par.h:166
MATROSKA_ID_AUDIOOUTSAMPLINGFREQ
#define MATROSKA_ID_AUDIOOUTSAMPLINGFREQ
Definition: matroska.h:171
AV_FIELD_TT
@ AV_FIELD_TT
Definition: codec_par.h:39
mpeg4audio.h
MATROSKA_ID_VIDEOPROJECTIONPRIVATE
#define MATROSKA_ID_VIDEOPROJECTIONPRIVATE
Definition: matroska.h:164
mkv_write_field_order
static void mkv_write_field_order(AVIOContext *pb, int is_webm, enum AVFieldOrder field_order)
Definition: matroskaenc.c:1004
AV_CODEC_ID_PCM_S16BE
@ AV_CODEC_ID_PCM_S16BE
Definition: codec_id.h:315
U
#define U(x)
Definition: vp56_arith.h:37
mkv_cues
Definition: matroskaenc.c:108
MATROSKA_VIDEO_STEREOMODE_TYPE_MONO
@ MATROSKA_VIDEO_STEREOMODE_TYPE_MONO
Definition: matroska.h:314
fail
#define fail()
Definition: checkasm.h:127
AVCodecParameters::bits_per_raw_sample
int bits_per_raw_sample
This is the number of valid bits in each output sample.
Definition: codec_par.h:115
AV_STEREO3D_2D
@ AV_STEREO3D_2D
Video is not stereoscopic (and metadata has to be there).
Definition: stereo3d.h:55
MATROSKA_ID_CHAPTERDISPLAY
#define MATROSKA_ID_CHAPTERDISPLAY
Definition: matroska.h:266
MATROSKA_ID_TRACKUID
#define MATROSKA_ID_TRACKUID
Definition: matroska.h:79
DEFAULT_MODE_INFER
@ DEFAULT_MODE_INFER
Definition: matroskaenc.c:73
samplefmt.h
EBML_ID_DOCTYPEVERSION
#define EBML_ID_DOCTYPEVERSION
Definition: matroska.h:41
AVCOL_RANGE_NB
@ AVCOL_RANGE_NB
Not part of ABI.
Definition: pixfmt.h:598
ff_vorbiscomment_write
int ff_vorbiscomment_write(AVIOContext *pb, const AVDictionary *m, const char *vendor_string, AVChapter **chapters, unsigned int nb_chapters)
Write a VorbisComment into an AVIOContext.
Definition: vorbiscomment.c:65
put_ebml_uint
static void put_ebml_uint(AVIOContext *pb, uint32_t elementid, uint64_t val)
Definition: matroskaenc.c:272
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:504
ff_matroska_video_stereo_mode
const char *const ff_matroska_video_stereo_mode[MATROSKA_VIDEO_STEREOMODE_TYPE_NB]
Definition: matroska.c:128
AVChapter
Definition: avformat.h:1159
query_codec
static int query_codec(enum AVCodecID id, int std_compliance)
Definition: img2enc.c:230
AV_DISPOSITION_FORCED
#define AV_DISPOSITION_FORCED
Track should be used during playback by default.
Definition: avformat.h:853
val
static double val(void *priv, double ch)
Definition: aeval.c:76
type
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
Definition: writing_filters.txt:86
MATROSKA_ID_VIDEOALPHAMODE
#define MATROSKA_ID_VIDEOALPHAMODE
Definition: matroska.h:130
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1388
pts
static int64_t pts
Definition: transcode_aac.c:653
us
#define us(width, name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:278
EBML_ID_DOCTYPE
#define EBML_ID_DOCTYPE
Definition: matroska.h:40
AV_FIELD_TB
@ AV_FIELD_TB
Definition: codec_par.h:41
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
mkv_write_tag_targets
static int mkv_write_tag_targets(MatroskaMuxContext *mkv, AVIOContext **pb, ebml_master *tag, uint32_t elementid, uint64_t uid)
Definition: matroskaenc.c:1538
MATROSKA_ID_VIDEOCOLOR_WHITEX
#define MATROSKA_ID_VIDEOCOLOR_WHITEX
Definition: matroska.h:157
AVRational::num
int num
Numerator.
Definition: rational.h:59
MATROSKA_TRACK_TYPE_METADATA
@ MATROSKA_TRACK_TYPE_METADATA
Definition: matroska.h:288
AV_CODEC_ID_ATRAC3
@ AV_CODEC_ID_ATRAC3
Definition: codec_id.h:454
MATROSKA_VIDEO_FIELDORDER_TT
@ MATROSKA_VIDEO_FIELDORDER_TT
Definition: matroska.h:306
AV_CODEC_ID_DVB_SUBTITLE
@ AV_CODEC_ID_DVB_SUBTITLE
Definition: codec_id.h:523
MatroskaVideoStereoModeType
MatroskaVideoStereoModeType
Definition: matroska.h:313
av_get_bits_per_sample
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:580
AV_CODEC_ID_SIPR
@ AV_CODEC_ID_SIPR
Definition: codec_id.h:464
AVCodecParameters::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: codec_par.h:148
MATROSKA_ID_BLKADDIDNAME
#define MATROSKA_ID_BLKADDIDNAME
Definition: matroska.h:195
mkv_write_tracks
static int mkv_write_tracks(AVFormatContext *s)
Definition: matroskaenc.c:1450
mkv_seekhead_entry
Definition: matroskaenc.c:88
MATROSKA_ID_BLOCKADDITIONAL
#define MATROSKA_ID_BLOCKADDITIONAL
Definition: matroska.h:243
DEFAULT_MODE_PASSTHROUGH
@ DEFAULT_MODE_PASSTHROUGH
Definition: matroskaenc.c:75
mkv_write_vtt_blocks
static int mkv_write_vtt_blocks(AVFormatContext *s, AVIOContext *pb, const AVPacket *pkt)
Definition: matroskaenc.c:2197
AV_STEREO3D_FRAMESEQUENCE
@ AV_STEREO3D_FRAMESEQUENCE
Views are alternated temporally.
Definition: stereo3d.h:92
AV_PKT_DATA_WEBVTT_SETTINGS
@ AV_PKT_DATA_WEBVTT_SETTINGS
The optional settings (rendering instructions) that immediately follow the timestamp specifier of a W...
Definition: packet.h:202
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
EBML_ID_VOID
#define EBML_ID_VOID
Definition: matroska.h:45
MATROSKA_ID_VIDEOFIELDORDER
#define MATROSKA_ID_VIDEOFIELDORDER
Definition: matroska.h:128
AVCodecTag
Definition: internal.h:51
MATROSKA_ID_TAGS
#define MATROSKA_ID_TAGS
Definition: matroska.h:59
AV_CODEC_ID_TTA
@ AV_CODEC_ID_TTA
Definition: codec_id.h:445
options
static const AVOption options[]
Definition: matroskaenc.c:2849
duration
int64_t duration
Definition: movenc.c:64
put_ebml_id
static void put_ebml_id(AVIOContext *pb, uint32_t id)
Definition: matroskaenc.c:187
EBML_ID_EBMLMAXIDLENGTH
#define EBML_ID_EBMLMAXIDLENGTH
Definition: matroska.h:38
av_dict_get
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
avio_open_dyn_buf
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1471
mkv_cuepoint::relative_pos
int64_t relative_pos
relative offset from the position of the cluster containing the block
Definition: matroskaenc.c:104
AV_CODEC_ID_ADPCM_G726
@ AV_CODEC_ID_ADPCM_G726
Definition: codec_id.h:364
avpriv_mpeg4audio_get_config2
int avpriv_mpeg4audio_get_config2(MPEG4AudioConfig *c, const uint8_t *buf, int size, int sync_extension, void *logctx)
Parse MPEG-4 systems extradata from a raw buffer to retrieve audio configuration.
Definition: mpeg4audio.c:165
AV_STEREO3D_LINES
@ AV_STEREO3D_LINES
Views are packed per line, as if interlaced.
Definition: stereo3d.h:129
AVCodecDescriptor
This struct describes the properties of a single codec described by an AVCodecID.
Definition: codec_desc.h:38
stereo3d.h
AVMasteringDisplayMetadata::white_point
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
Definition: mastering_display_metadata.h:47
intreadwrite.h
end_ebml_master
static void end_ebml_master(AVIOContext *pb, ebml_master master)
Definition: matroskaenc.c:354
MATROSKA_ID_FILEUID
#define MATROSKA_ID_FILEUID
Definition: matroska.h:259
s
#define s(width, name)
Definition: cbs_vp9.c:257
AVCHROMA_LOC_TOP
@ AVCHROMA_LOC_TOP
Definition: pixfmt.h:621
MATROSKA_VIDEO_INTERLACE_FLAG_PROGRESSIVE
@ MATROSKA_VIDEO_INTERLACE_FLAG_PROGRESSIVE
Definition: matroska.h:301
AV_PKT_DATA_STEREO3D
@ AV_PKT_DATA_STEREO3D
This side data should be associated with a video stream and contains Stereoscopic 3D information in f...
Definition: packet.h:114
AVCOL_PRI_NB
@ AVCOL_PRI_NB
Not part of ABI.
Definition: pixfmt.h:487
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
mkv_track::write_dts
int write_dts
Definition: matroskaenc.c:114
CodecTags::str
char str[22]
Definition: matroska.h:366
av_lfg_get
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:53
MATROSKA_ID_VIDEODISPLAYWIDTH
#define MATROSKA_ID_VIDEODISPLAYWIDTH
Definition: matroska.h:118
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:224
AV_PKT_DATA_MASTERING_DISPLAY_METADATA
@ AV_PKT_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata (based on SMPTE-2086:2014).
Definition: packet.h:222
mkv_write_flush_packet
static int mkv_write_flush_packet(AVFormatContext *s, AVPacket *pkt)
Definition: matroskaenc.c:2525
MATROSKA_VIDEO_FIELDORDER_BT
@ MATROSKA_VIDEO_FIELDORDER_BT
Definition: matroska.h:310
MatroskaMuxContext::cluster_pos
int64_t cluster_pos
file offset of the current Cluster
Definition: matroskaenc.c:136
AVDictionaryEntry::key
char * key
Definition: dict.h:80
MATROSKA_ID_TAGNAME
#define MATROSKA_ID_TAGNAME
Definition: matroska.h:216
AVSphericalMapping::bound_top
uint32_t bound_top
Distance from the top edge.
Definition: spherical.h:168
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:218
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:126
ff_matroska_audio_muxer
const AVOutputFormat ff_matroska_audio_muxer
ff_av1_filter_obus_buf
int ff_av1_filter_obus_buf(const uint8_t *in, uint8_t **out, int *size, int *offset)
Filter out AV1 OBUs not meant to be present in ISOBMFF sample data and return the result in a data bu...
Definition: av1.c:86
MATROSKA_ID_TAG
#define MATROSKA_ID_TAG
Definition: matroska.h:214
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
MATROSKA_ID_TIMECODESCALE
#define MATROSKA_ID_TIMECODESCALE
Definition: matroska.h:66
lfg.h
mkv_write_stereo_mode
static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb, AVStream *st, int is_webm, int *h_width, int *h_height)
Definition: matroskaenc.c:1043
get_mimetype
static const char * get_mimetype(const AVStream *st)
Definition: matroskaenc.c:1775
MatroskaMuxContext::write_crc
int write_crc
Definition: matroskaenc.c:156
matroska_webm_class
static const AVClass matroska_webm_class
Definition: matroskaenc.c:2866
AV_OPT_TYPE_INT64
@ AV_OPT_TYPE_INT64
Definition: opt.h:225
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
MATROSKA_ID_CUETRACKPOSITION
#define MATROSKA_ID_CUETRACKPOSITION
Definition: matroska.h:204
additional_audio_tags
static const AVCodecTag additional_audio_tags[]
Definition: matroskaenc.c:2817
MATROSKA_ID_SEEKENTRY
#define MATROSKA_ID_SEEKENTRY
Definition: matroska.h:229
mkv_track::track_num
unsigned track_num
Definition: matroskaenc.c:117
AV_FIELD_UNKNOWN
@ AV_FIELD_UNKNOWN
Definition: codec_par.h:37
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
MATROSKA_ID_TRACKTYPE
#define MATROSKA_ID_TRACKTYPE
Definition: matroska.h:80
AVDOVIDecoderConfigurationRecord::dv_profile
uint8_t dv_profile
Definition: dovi_meta.h:55
additional_video_tags
static const AVCodecTag additional_video_tags[]
Definition: matroskaenc.c:2833
MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_LR
@ MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_LR
Definition: matroska.h:323
MATROSKA_ID_SEGMENTUID
#define MATROSKA_ID_SEGMENTUID
Definition: matroska.h:72
MATROSKA_ID_TRACKBLKADDMAPPING
#define MATROSKA_ID_TRACKBLKADDMAPPING
Definition: matroska.h:114
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:141
MatroskaMuxContext::cluster_time_limit
int64_t cluster_time_limit
Definition: matroskaenc.c:155
MATROSKA_ID_INFO
#define MATROSKA_ID_INFO
Definition: matroska.h:56
MatroskaMuxContext::have_video
int have_video
Definition: matroskaenc.c:148
MATROSKA_ID_AUDIOCHANNELS
#define MATROSKA_ID_AUDIOCHANNELS
Definition: matroska.h:174
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:369
AV_CODEC_ID_SVQ3
@ AV_CODEC_ID_SVQ3
Definition: codec_id.h:73
key
const char * key
Definition: hwcontext_opencl.c:168
mkv_write_video_color
static void mkv_write_video_color(AVIOContext *pb, const AVStream *st, const AVCodecParameters *par)
Definition: matroskaenc.c:851
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:472
AV_FIELD_BT
@ AV_FIELD_BT
Definition: codec_par.h:42
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:77
MATROSKA_ID_VIDEOSTEREOMODE
#define MATROSKA_ID_VIDEOSTEREOMODE
Definition: matroska.h:129
mkv_start_seekhead
static void mkv_start_seekhead(MatroskaMuxContext *mkv, AVIOContext *pb)
Initialize the SeekHead element to be ready to index level 1 Matroska elements.
Definition: matroskaenc.c:475
ff_webm_codec_tags
const CodecTags ff_webm_codec_tags[]
Definition: matroska.c:106
mkv_track::uid
uint64_t uid
Definition: matroskaenc.c:116
AVStereo3D::flags
int flags
Additional information about the frame packing.
Definition: stereo3d.h:185
MATROSKA_ID_VIDEOCOLORSPACE
#define MATROSKA_ID_VIDEOCOLORSPACE
Definition: matroska.h:132
MATROSKA_ID_TRACKNAME
#define MATROSKA_ID_TRACKNAME
Definition: matroska.h:96
FFFormatContext
Definition: internal.h:73
AV_CODEC_ID_WEBVTT
@ AV_CODEC_ID_WEBVTT
Definition: codec_id.h:540
EBML_ID_DOCTYPEREADVERSION
#define EBML_ID_DOCTYPEREADVERSION
Definition: matroska.h:42
mkv_cues::entries
mkv_cuepoint * entries
Definition: matroskaenc.c:109
AVFormatContext
Format I/O context.
Definition: avformat.h:1200
internal.h
MATROSKA_ID_TRACKFLAGHEARINGIMPAIRED
#define MATROSKA_ID_TRACKFLAGHEARINGIMPAIRED
Definition: matroska.h:101
ff_metadata_conv_ctx
void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:59
mkv_write_video_projection
static void mkv_write_video_projection(AVFormatContext *s, AVIOContext *pb, const AVStream *st)
Definition: matroskaenc.c:937
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1095
MATROSKA_VIDEO_STEREOMODE_TYPE_TOP_BOTTOM
@ MATROSKA_VIDEO_STEREOMODE_TYPE_TOP_BOTTOM
Definition: matroska.h:317
AV_LANG_ISO639_2_BIBL
@ AV_LANG_ISO639_2_BIBL
Definition: avlanguage.h:28
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
mkv_write_codecprivate
static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int native_id, int qt_id)
Definition: matroskaenc.c:781
MATROSKA_ID_BLOCKGROUP
#define MATROSKA_ID_BLOCKGROUP
Definition: matroska.h:239
MATROSKA_ID_VIDEOCOLOR_LUMINANCEMIN
#define MATROSKA_ID_VIDEOCOLOR_LUMINANCEMIN
Definition: matroska.h:160
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:965
NULL
#define NULL
Definition: coverity.c:32
MATROSKA_ID_ATTACHMENTS
#define MATROSKA_ID_ATTACHMENTS
Definition: matroska.h:61
ff_put_wav_header
int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int flags)
Write WAVEFORMAT header structure.
Definition: riffenc.c:55
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
MATROSKA_ID_CHAPTERATOM
#define MATROSKA_ID_CHAPTERATOM
Definition: matroska.h:263
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:279
MATROSKA_TRACK_TYPE_AUDIO
@ MATROSKA_TRACK_TYPE_AUDIO
Definition: matroska.h:282
ebml_length_size
static int ebml_length_size(uint64_t length)
Calculate how many bytes are needed to represent the length field of an EBML element whose payload ha...
Definition: matroskaenc.c:225
isom.h
MATROSKA_ID_TRACKFLAGORIGINAL
#define MATROSKA_ID_TRACKFLAGORIGINAL
Definition: matroska.h:104
MATROSKA_VIDEO_DISPLAYUNIT_DAR
@ MATROSKA_VIDEO_DISPLAYUNIT_DAR
Definition: matroska.h:336
write_trailer
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:98
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
MATROSKA_ID_WRITINGAPP
#define MATROSKA_ID_WRITINGAPP
Definition: matroska.h:69
ff_hevc_annexb2mp4_buf
int ff_hevc_annexb2mp4_buf(const uint8_t *buf_in, uint8_t **buf_out, int *size, int filter_ps, int *ps_count)
Writes Annex B formatted HEVC NAL units to a data buffer.
Definition: hevc.c:1046
WV_HEADER_SIZE
#define WV_HEADER_SIZE
Definition: wavpack.h:30
MatroskaMuxContext::info
ebml_stored_master info
Definition: matroskaenc.c:131
AV_DISPOSITION_COMMENT
#define AV_DISPOSITION_COMMENT
The stream is a commentary track.
Definition: avformat.h:838
MATROSKA_ID_VIDEOCOLOR_GY
#define MATROSKA_ID_VIDEOCOLOR_GY
Definition: matroska.h:154
AV_CODEC_ID_CINEPAK
@ AV_CODEC_ID_CINEPAK
Definition: codec_id.h:93
AV_CODEC_ID_DVD_SUBTITLE
@ AV_CODEC_ID_DVD_SUBTITLE
Definition: codec_id.h:522
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
ff_stream_add_bitstream_filter
int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args)
Add a bitstream filter to a stream.
Definition: utils.c:1790
src
#define src
Definition: vp8dsp.c:255
avc.h
parseutils.h
MATROSKA_ID_SIMPLETAG
#define MATROSKA_ID_SIMPLETAG
Definition: matroska.h:215
MATROSKA_ID_VIDEOPROJECTION
#define MATROSKA_ID_VIDEOPROJECTION
Definition: matroska.h:162
MatroskaMuxContext::segment_uid
uint32_t segment_uid[4]
Definition: matroskaenc.c:165
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:1006
MATROSKA_ID_SEEKID
#define MATROSKA_ID_SEEKID
Definition: matroska.h:232
ff_avc_parse_nal_units_buf
int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size)
Definition: avc.c:95
put_ebml_num
static void put_ebml_num(AVIOContext *pb, uint64_t num, int bytes)
Write a number as EBML variable length integer on bytes bytes.
Definition: matroskaenc.c:234
AV_DISPOSITION_METADATA
#define AV_DISPOSITION_METADATA
The subtitle stream contains time-aligned metadata that is not intended to be directly presented to t...
Definition: avformat.h:895
av_parse_time
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
Definition: parseutils.c:589
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:210
MATROSKA_ID_CHAPTERTIMESTART
#define MATROSKA_ID_CHAPTERTIMESTART
Definition: matroska.h:264
ff_codec_movvideo_tags
const AVCodecTag ff_codec_movvideo_tags[]
Definition: isom_tags.c:29
mkv_track::codecpriv_offset
int64_t codecpriv_offset
Definition: matroskaenc.c:124
ffio_fill
void ffio_fill(AVIOContext *s, int b, int64_t count)
Definition: aviobuf.c:218
mkv_add_seekhead_entry
static void mkv_add_seekhead_entry(MatroskaMuxContext *mkv, uint32_t elementid, uint64_t filepos)
Definition: matroskaenc.c:364
AV_DISPOSITION_ORIGINAL
#define AV_DISPOSITION_ORIGINAL
The stream is in original language.
Definition: avformat.h:834
mkv_track::sample_rate_offset
int64_t sample_rate_offset
Definition: matroskaenc.c:120
AV_CODEC_ID_QDM2
@ AV_CODEC_ID_QDM2
Definition: codec_id.h:442
mkv_get_uid
static uint64_t mkv_get_uid(const mkv_track *tracks, int i, AVLFG *c)
Definition: matroskaenc.c:2699
MATROSKA_TRACK_TYPE_VIDEO
@ MATROSKA_TRACK_TYPE_VIDEO
Definition: matroska.h:281
av_packet_ref
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:432
get_metadata_duration
static int64_t get_metadata_duration(AVFormatContext *s)
Definition: matroskaenc.c:1837
mkv_track::has_cue
int has_cue
Definition: matroskaenc.c:115
MATROSKA_ID_FILEMIMETYPE
#define MATROSKA_ID_FILEMIMETYPE
Definition: matroska.h:257
MATROSKA_ID_VIDEODISPLAYHEIGHT
#define MATROSKA_ID_VIDEODISPLAYHEIGHT
Definition: matroska.h:119
MATROSKA_ID_TRACKAUDIO
#define MATROSKA_ID_TRACKAUDIO
Definition: matroska.h:82
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:563
ff_vorbiscomment_length
int64_t ff_vorbiscomment_length(const AVDictionary *m, const char *vendor_string, AVChapter **chapters, unsigned int nb_chapters)
Calculate the length in bytes of a VorbisComment.
Definition: vorbiscomment.c:41
c
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
Definition: undefined.txt:32
MatroskaMuxContext::nb_attachments
unsigned nb_attachments
Definition: matroskaenc.c:147
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:170
put_ebml_float
static void put_ebml_float(AVIOContext *pb, uint32_t elementid, double val)
Definition: matroskaenc.c:299
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:47
MATROSKA_ID_VIDEOCOLORMAXCLL
#define MATROSKA_ID_VIDEOCOLORMAXCLL
Definition: matroska.h:147
MATROSKA_ID_TRACKENTRY
#define MATROSKA_ID_TRACKENTRY
Definition: matroska.h:75
ebml_stored_master
Definition: matroskaenc.c:83
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:78
AV_WB32
#define AV_WB32(p, v)
Definition: intreadwrite.h:419
ff_wv_parse_header
int ff_wv_parse_header(WvHeader *wv, const uint8_t *data)
Parse a WavPack block header.
Definition: wv.c:29
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: codec_id.h:425
mkv_write_header
static int mkv_write_header(AVFormatContext *s)
Definition: matroskaenc.c:1861
MatroskaMuxContext
Definition: matroskaenc.c:128
mkv_cuepoint::duration
int64_t duration
duration of the block according to time base
Definition: matroskaenc.c:105
AV_DISPOSITION_CAPTIONS
#define AV_DISPOSITION_CAPTIONS
The subtitle stream contains captions, providing a transcription and possibly a translation of audio.
Definition: avformat.h:884
MATROSKA_ID_AUDIOBITDEPTH
#define MATROSKA_ID_AUDIOBITDEPTH
Definition: matroska.h:173
AV_CODEC_ID_FFV1
@ AV_CODEC_ID_FFV1
Definition: codec_id.h:83
AVLFG
Context structure for the Lagged Fibonacci PRNG.
Definition: lfg.h:33
MATROSKA_VIDEO_STEREOMODE_TYPE_LEFT_RIGHT
@ MATROSKA_VIDEO_STEREOMODE_TYPE_LEFT_RIGHT
Definition: matroska.h:315
MATROSKA_ID_TRACKFLAGDEFAULT
#define MATROSKA_ID_TRACKFLAGDEFAULT
Definition: matroska.h:99
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
AV_SPHERICAL_CUBEMAP
@ AV_SPHERICAL_CUBEMAP
Video frame is split into 6 faces of a cube, and arranged on a 3x2 layout.
Definition: spherical.h:65
ff_matroska_muxer
const AVOutputFormat ff_matroska_muxer
put_xiph_codecpriv
static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, const AVCodecParameters *par)
Definition: matroskaenc.c:617
MATROSKA_ID_TRACKFLAGCOMMENTARY
#define MATROSKA_ID_TRACKFLAGCOMMENTARY
Definition: matroska.h:105
ffio_reset_dyn_buf
void ffio_reset_dyn_buf(AVIOContext *s)
Reset a dynamic buffer.
Definition: aviobuf.c:1505
AV_STEREO3D_CHECKERBOARD
@ AV_STEREO3D_CHECKERBOARD
Views are packed in a checkerboard-like structure per pixel.
Definition: stereo3d.h:104
AVMediaType
AVMediaType
Definition: avutil.h:199
MATROSKA_ID_TRACKFLAGLACING
#define MATROSKA_ID_TRACKFLAGLACING
Definition: matroska.h:106
AVPacket::size
int size
Definition: packet.h:374
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
id
enum AVCodecID id
Definition: extract_extradata_bsf.c:325
MATROSKA_ID_VIDEOCOLOR_GX
#define MATROSKA_ID_VIDEOCOLOR_GX
Definition: matroska.h:153
ff_codec_get_id
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:357
mkv_blockgroup_size
static int mkv_blockgroup_size(int pkt_size, int track_num_size)
Definition: matroskaenc.c:2016
master
const char * master
Definition: vf_curves.c:119
ff_isom_write_avcc
int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
Definition: avc.c:108
AVSphericalMapping::bound_right
uint32_t bound_right
Distance from the right edge.
Definition: spherical.h:169
FFIOContext::pub
AVIOContext pub
Definition: avio_internal.h:30
mkv_write_native_codecprivate
static int mkv_write_native_codecprivate(AVFormatContext *s, AVIOContext *pb, const AVCodecParameters *par, AVIOContext *dyn_cp)
Definition: matroskaenc.c:727
ff_convert_lang_to
const char * ff_convert_lang_to(const char *lang, enum AVLangCodespace target_codespace)
Convert a language code to a target codespace.
Definition: avlanguage.c:736
MATROSKA_ID_FILEDATA
#define MATROSKA_ID_FILEDATA
Definition: matroska.h:258
ebml_master::sizebytes
int sizebytes
how many bytes were reserved for the size
Definition: matroskaenc.c:80
DEFAULT_MODE_INFER_NO_SUBS
@ DEFAULT_MODE_INFER_NO_SUBS
Definition: matroskaenc.c:74
MATROSKA_ID_VIDEOPROJECTIONPOSEPITCH
#define MATROSKA_ID_VIDEOPROJECTIONPOSEPITCH
Definition: matroska.h:166
size
int size
Definition: twinvq_data.h:10344
MATROSKA_ID_BLOCKMORE
#define MATROSKA_ID_BLOCKMORE
Definition: matroska.h:241
MAX_SEEKHEAD_ENTRIES
#define MAX_SEEKHEAD_ENTRIES
Definition: matroskaenc.c:62
mkv_cuepoint::pts
uint64_t pts
Definition: matroskaenc.c:101
ebml_stored_master::bc
AVIOContext * bc
Definition: matroskaenc.c:84
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
MKBETAG
#define MKBETAG(a, b, c, d)
Definition: macros.h:56
AV_CODEC_ID_QDMC
@ AV_CODEC_ID_QDMC
Definition: codec_id.h:473
put_ebml_void
static void put_ebml_void(AVIOContext *pb, int size)
Write a void element of a given size.
Definition: matroskaenc.c:326
AV_RB32
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
Definition: bytestream.h:96
MATROSKA_ID_VIDEOCOLORMAXFALL
#define MATROSKA_ID_VIDEOCOLORMAXFALL
Definition: matroska.h:148
FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX
#define FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX
Tell ff_put_wav_header() to use WAVEFORMATEX even for PCM codecs.
Definition: riff.h:53
AVFMT_ALLOW_FLUSH
#define AVFMT_ALLOW_FLUSH
Format allows flushing.
Definition: avformat.h:484
format
ofilter format
Definition: ffmpeg_filter.c:172
AV_CODEC_ID_OPUS
@ AV_CODEC_ID_OPUS
Definition: codec_id.h:483
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:617
AV_DISPOSITION_DUB
#define AV_DISPOSITION_DUB
The stream is not in original language.
Definition: avformat.h:828
MatroskaMuxContext::cur_audio_pkt
AVPacket * cur_audio_pkt
Definition: matroskaenc.c:145
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:1004
AVIO_DATA_MARKER_SYNC_POINT
@ AVIO_DATA_MARKER_SYNC_POINT
A point in the output bytestream where a decoder can start decoding (i.e.
Definition: avio.h:122
start_ebml_master_crc32
static int start_ebml_master_crc32(AVIOContext **dyn_cp, MatroskaMuxContext *mkv)
Definition: matroskaenc.c:375
MATROSKA_ID_POINTENTRY
#define MATROSKA_ID_POINTENTRY
Definition: matroska.h:200
dovi_isom.h
header
static const uint8_t header[24]
Definition: sdr2.c:67
AV_DISPOSITION_HEARING_IMPAIRED
#define AV_DISPOSITION_HEARING_IMPAIRED
The stream is intended for hearing impaired audiences.
Definition: avformat.h:857
MATROSKA_ID_BLKADDIDEXTRADATA
#define MATROSKA_ID_BLKADDIDEXTRADATA
Definition: matroska.h:197
CASE
#define CASE(type, variable)
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:372
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:232
avio_wb32
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:394
AVSphericalMapping::padding
uint32_t padding
Number of pixels to pad from the edge of each cube face.
Definition: spherical.h:182
additional_subtitle_tags
static const AVCodecTag additional_subtitle_tags[]
Definition: matroskaenc.c:2840
avio_wl32
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:386
av_crc_get_table
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
AV_CODEC_ID_RV30
@ AV_CODEC_ID_RV30
Definition: codec_id.h:118
offset
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 offset
Definition: writing_filters.txt:86
AV_PKT_DATA_CONTENT_LIGHT_LEVEL
@ AV_PKT_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: packet.h:235
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:379
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:203
version
version
Definition: libkvazaar.c:313
mkv_write_trailer
static int mkv_write_trailer(AVFormatContext *s)
Definition: matroskaenc.c:2543
AV_STEREO3D_FLAG_INVERT
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
Definition: stereo3d.h:167
MATROSKA_ID_VIDEOPIXELHEIGHT
#define MATROSKA_ID_VIDEOPIXELHEIGHT
Definition: matroska.h:121
FF_COMPLIANCE_NORMAL
#define FF_COMPLIANCE_NORMAL
Definition: avcodec.h:1283
mkv_write_tags
static int mkv_write_tags(AVFormatContext *s)
Definition: matroskaenc.c:1609
AV_CODEC_ID_SVQ1
@ AV_CODEC_ID_SVQ1
Definition: codec_id.h:72
mkv_cuepoint::stream_idx
int stream_idx
Definition: matroskaenc.c:102
MATROSKA_ID_MUXINGAPP
#define MATROSKA_ID_MUXINGAPP
Definition: matroska.h:70
MatroskaMuxContext::duration
int64_t duration
Definition: matroskaenc.c:139
MATROSKA_ID_EDITIONFLAGDEFAULT
#define MATROSKA_ID_EDITIONFLAGDEFAULT
Definition: matroska.h:272
write_packet
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:727
MATROSKA_ID_FILEDESC
#define MATROSKA_ID_FILEDESC
Definition: matroska.h:255
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:443
AV_FIELD_BB
@ AV_FIELD_BB
Definition: codec_par.h:40
MAX_SEEKENTRY_SIZE
#define MAX_SEEKENTRY_SIZE
2 bytes * 3 for EBML IDs, 3 1-byte EBML lengths, 8 bytes for 64 bit offset, 4 bytes for target EBML I...
Definition: matroskaenc.c:174
MATROSKA_ID_VIDEOPROJECTIONTYPE
#define MATROSKA_ID_VIDEOPROJECTIONTYPE
Definition: matroska.h:163
ff_isom_write_hvcc
int ff_isom_write_hvcc(AVIOContext *pb, const uint8_t *data, int size, int ps_array_completeness)
Writes HEVC extradata (parameter sets, declarative SEI NAL units) to the provided AVIOContext.
Definition: hevc.c:1067
av_double2int
static av_always_inline uint64_t av_double2int(double f)
Reinterpret a double as a 64-bit integer.
Definition: intfloat.h:70
ebml_master
Definition: matroskaenc.c:78
MATROSKA_ID_FILENAME
#define MATROSKA_ID_FILENAME
Definition: matroska.h:256
AV_CODEC_ID_RA_288
@ AV_CODEC_ID_RA_288
Definition: codec_id.h:411
ebml_stored_master::pos
int64_t pos
Definition: matroskaenc.c:85
AVSphericalMapping::roll
int32_t roll
Rotation around the forward vector [-180, 180].
Definition: spherical.h:128
MATROSKA_ID_CODECID
#define MATROSKA_ID_CODECID
Definition: matroska.h:88
AV_CODEC_ID_RV10
@ AV_CODEC_ID_RV10
Definition: codec_id.h:55
AVFMT_GLOBALHEADER
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:474
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:48
AVOutputFormat
Definition: avformat.h:503
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:366
avio_internal.h
av_get_bytes_per_sample
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:106
put_ebml_length
static void put_ebml_length(AVIOContext *pb, uint64_t length, int bytes)
Write a length as EBML variable length integer.
Definition: matroskaenc.c:247
av_packet_get_side_data
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition: avpacket.c:253
AV_CODEC_ID_THEORA
@ AV_CODEC_ID_THEORA
Definition: codec_id.h:80
av_builtin_constant_p
#define av_builtin_constant_p
Definition: attributes.h:160
AVCodecParameters::height
int height
Definition: codec_par.h:127
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
MATROSKA_ID_CUECLUSTERPOSITION
#define MATROSKA_ID_CUECLUSTERPOSITION
Definition: matroska.h:208
mkv_cuepoint::cluster_pos
int64_t cluster_pos
offset of the cluster containing the block relative to the segment
Definition: matroskaenc.c:103
mkv_seekhead
Definition: matroskaenc.c:93
ffio_init_context
void ffio_init_context(FFIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Definition: aviobuf.c:81
MATROSKA_ID_CUETRACK
#define MATROSKA_ID_CUETRACK
Definition: matroska.h:207
mkv_seekhead::entries
mkv_seekhead_entry entries[MAX_SEEKHEAD_ENTRIES]
Definition: matroskaenc.c:95
MATROSKA_ID_SEEKPOSITION
#define MATROSKA_ID_SEEKPOSITION
Definition: matroska.h:233
AV_STEREO3D_TOPBOTTOM
@ AV_STEREO3D_TOPBOTTOM
Views are on top of each other.
Definition: stereo3d.h:79
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
MATROSKA_ID_CLUSTER
#define MATROSKA_ID_CLUSTER
Definition: matroska.h:62
av_le2ne32
#define av_le2ne32(x)
Definition: bswap.h:96
MATROSKA_ID_TRACKLANGUAGE
#define MATROSKA_ID_TRACKLANGUAGE
Definition: matroska.h:97
AV_CODEC_ID_RV20
@ AV_CODEC_ID_RV20
Definition: codec_id.h:56
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:224
ebml_master::pos
int64_t pos
absolute offset in the containing AVIOContext where the master's elements start
Definition: matroskaenc.c:79
AVMEDIA_TYPE_ATTACHMENT
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition: avutil.h:205
MATROSKA_ID_VIDEOFLAGINTERLACED
#define MATROSKA_ID_VIDEOFLAGINTERLACED
Definition: matroska.h:127
AV_CODEC_ID_PCM_S32BE
@ AV_CODEC_ID_PCM_S32BE
Definition: codec_id.h:323
EBML_ID_CRC32
#define EBML_ID_CRC32
Definition: matroska.h:46
ff_mkv_metadata_conv
const AVMetadataConv ff_mkv_metadata_conv[]
Definition: matroska.c:122
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
AV_PKT_DATA_SKIP_SAMPLES
@ AV_PKT_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
Definition: packet.h:156
AVCodecParameters::color_range
enum AVColorRange color_range
Video only.
Definition: codec_par.h:146
AVMasteringDisplayMetadata
Mastering display metadata capable of representing the color volume of the display used to master the...
Definition: mastering_display_metadata.h:38
len
int len
Definition: vorbis_enc_data.h:426
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:526
av_rescale
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:128
mkv_check_tag_name
static int mkv_check_tag_name(const char *name, uint32_t elementid)
Definition: matroskaenc.c:1558
MPEG4AudioConfig::ext_sample_rate
int ext_sample_rate
Definition: mpeg4audio.h:40
MATROSKA_ID_CHAPTERUID
#define MATROSKA_ID_CHAPTERUID
Definition: matroska.h:274
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:271
AVCodecParameters::field_order
enum AVFieldOrder field_order
Video only.
Definition: codec_par.h:141
MATROSKA_VIDEO_STEREOMODE_TYPE_RIGHT_LEFT
@ MATROSKA_VIDEO_STEREOMODE_TYPE_RIGHT_LEFT
Definition: matroska.h:325
MAX_EBML_HEADER_SIZE
#define MAX_EBML_HEADER_SIZE
2 bytes * 7 for EBML IDs, 7 1-byte EBML lengths, 6 1-byte uint, 8 byte for "matroska" doctype string
Definition: matroskaenc.c:170
mkv_end_cluster
static int mkv_end_cluster(AVFormatContext *s)
Definition: matroskaenc.c:2250
MATROSKA_ID_VIDEOPROJECTIONPOSEYAW
#define MATROSKA_ID_VIDEOPROJECTIONPOSEYAW
Definition: matroska.h:165
AVFMT_TS_NONSTRICT
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:485
av_cmp_q
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
OFFSET
#define OFFSET(x)
Definition: matroskaenc.c:2847
AVStream::disposition
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition: avformat.h:995
AV_DISPOSITION_VISUAL_IMPAIRED
#define AV_DISPOSITION_VISUAL_IMPAIRED
The stream is intended for visually impaired audiences.
Definition: avformat.h:861
tag
uint32_t tag
Definition: movenc.c:1596
ffio_free_dyn_buf
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
Definition: aviobuf.c:1544
AVFMT_FLAG_BITEXACT
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1335
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:935
mkv_track::sample_rate
int sample_rate
Definition: matroskaenc.c:119
AV_PKT_DATA_DOVI_CONF
@ AV_PKT_DATA_DOVI_CONF
DOVI configuration ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2....
Definition: packet.h:283
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:260
mkv_seekhead_entry::elementid
uint32_t elementid
Definition: matroskaenc.c:89
AVClass::class_name
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:71
AV_STEREO3D_COLUMNS
@ AV_STEREO3D_COLUMNS
Views are packed per column.
Definition: stereo3d.h:141
AVSphericalMapping::pitch
int32_t pitch
Rotation around the right vector [-90, 90].
Definition: spherical.h:127
AVStereo3D::type
enum AVStereo3DType type
How views are packed within the video.
Definition: stereo3d.h:180
mkv_track::last_timestamp
int64_t last_timestamp
Definition: matroskaenc.c:121
MATROSKA_ID_VIDEOCOLOR_BX
#define MATROSKA_ID_VIDEOCOLOR_BX
Definition: matroska.h:155
MatroskaMuxContext::wrote_tags
int wrote_tags
Definition: matroskaenc.c:151
MATROSKA_ID_TAGSTRING
#define MATROSKA_ID_TAGSTRING
Definition: matroska.h:217
mkv_seekhead_entry::segmentpos
uint64_t segmentpos
Definition: matroskaenc.c:90
put_ebml_string
static void put_ebml_string(AVIOContext *pb, uint32_t elementid, const char *str)
Definition: matroskaenc.c:314
MATROSKA_ID_VIDEOCOLORMATRIXCOEFF
#define MATROSKA_ID_VIDEOCOLORMATRIXCOEFF
Definition: matroska.h:135
pos
unsigned int pos
Definition: spdifenc.c:412
avformat.h
av_stream_get_side_data
uint8_t * av_stream_get_side_data(const AVStream *stream, enum AVPacketSideDataType type, size_t *size)
Get side information from stream.
Definition: utils.c:1722
dict.h
AV_CODEC_ID_TEXT
@ AV_CODEC_ID_TEXT
raw UTF-8 text
Definition: codec_id.h:524
MATROSKA_ID_SIMPLEBLOCK
#define MATROSKA_ID_SIMPLEBLOCK
Definition: matroska.h:244
mkv_check_tag
static int mkv_check_tag(const AVDictionary *m, uint32_t elementid)
Definition: matroskaenc.c:1598
AV_DISPOSITION_DESCRIPTIONS
#define AV_DISPOSITION_DESCRIPTIONS
The subtitle stream contains a textual description of the video content.
Definition: avformat.h:890
FLAGS
#define FLAGS
Definition: matroskaenc.c:2848
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
AVCodecParameters::chroma_location
enum AVChromaLocation chroma_location
Definition: codec_par.h:150
mkv_deinit
static void mkv_deinit(AVFormatContext *s)
Free the members allocated in the mux context.
Definition: matroskaenc.c:457
avio_printf
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
MATROSKA_ID_EDITIONENTRY
#define MATROSKA_ID_EDITIONENTRY
Definition: matroska.h:262
ff_codec_bmp_tags
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:34
mkv_write_block
static int mkv_write_block(AVFormatContext *s, AVIOContext *pb, uint32_t blockid, const AVPacket *pkt, int keyframe)
Definition: matroskaenc.c:2080
random_seed.h
EBML_ID_HEADER
#define EBML_ID_HEADER
Definition: matroska.h:33
channel_layout.h
EBML_ID_EBMLVERSION
#define EBML_ID_EBMLVERSION
Definition: matroska.h:36
mkv_track
Definition: matroskaenc.c:113
MatroskaMuxContext::seekhead
mkv_seekhead seekhead
Definition: matroskaenc.c:141
wv.h
ISOM_DVCC_DVVC_SIZE
#define ISOM_DVCC_DVVC_SIZE
Definition: dovi_isom.h:29
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
av_crc
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
Definition: crc.c:392
MATROSKA_ID_TAGLANG
#define MATROSKA_ID_TAGLANG
Definition: matroska.h:218
AV_PKT_DATA_NEW_EXTRADATA
@ 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...
Definition: packet.h:55
AVRational::den
int den
Denominator.
Definition: rational.h:60
MATROSKA_ID_VIDEOCOLOR
#define MATROSKA_ID_VIDEOCOLOR
Definition: matroska.h:133
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
MatroskaMuxContext::cues
mkv_cues cues
Definition: matroskaenc.c:142
mkv_check_bitstream
static int mkv_check_bitstream(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
Definition: matroskaenc.c:2802
ff_codec_get_tag
unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id)
Definition: utils.c:347
MATROSKA_ID_VIDEOCOLORTRANSFERCHARACTERISTICS
#define MATROSKA_ID_VIDEOCOLORTRANSFERCHARACTERISTICS
Definition: matroska.h:144
video
A Quick Description Of Rate Distortion Theory We want to encode a video
Definition: rate_distortion.txt:3
MatroskaMuxContext::default_mode
int default_mode
Definition: matroskaenc.c:163
MATROSKA_ID_VIDEOCOLOR_RX
#define MATROSKA_ID_VIDEOCOLOR_RX
Definition: matroska.h:151
filler
int(* filler)(InterplayACMContext *s, unsigned ind, unsigned col)
Definition: interplayacm.c:417
end_ebml_master_crc32_tentatively
static int end_ebml_master_crc32_tentatively(AVIOContext *pb, ebml_stored_master *elem, MatroskaMuxContext *mkv, uint32_t id)
Output EBML master.
Definition: matroskaenc.c:425
MATROSKA_TRACK_TYPE_SUBTITLE
@ MATROSKA_TRACK_TYPE_SUBTITLE
Definition: matroska.h:285
MatroskaMuxContext::duration_offset
int64_t duration_offset
Definition: matroskaenc.c:138
mkv_add_cuepoint
static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int stream, int64_t ts, int64_t cluster_pos, int64_t relative_pos, int64_t duration)
Definition: matroskaenc.c:536
AVStream::r_frame_rate
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:1084
ff_flac_write_header
int ff_flac_write_header(AVIOContext *pb, const uint8_t *extradata, int extradata_size, int last_block)
Definition: flacenc_header.c:29
mkv_seekhead::filepos
int64_t filepos
Definition: matroskaenc.c:94
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:1196
MATROSKA_VIDEO_PROJECTION_TYPE_EQUIRECTANGULAR
@ MATROSKA_VIDEO_PROJECTION_TYPE_EQUIRECTANGULAR
Definition: matroska.h:356
mkv_check_new_extra_data
static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt)
Definition: matroskaenc.c:2269
AVMasteringDisplayMetadata::min_luminance
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:52
AVPacket::stream_index
int stream_index
Definition: packet.h:375
avpriv_split_xiph_headers
int avpriv_split_xiph_headers(const uint8_t *extradata, int extradata_size, int first_header_size, const uint8_t *header_start[3], int header_len[3])
Split a single extradata buffer into the three headers that most Xiph codecs use.
Definition: xiph.c:24
mkv_seekhead::reserved_size
int reserved_size
Definition: matroskaenc.c:97
avio_wb64
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:460
MATROSKA_ID_VIDEOCOLORCHROMASITINGHORZ
#define MATROSKA_ID_VIDEOCOLORCHROMASITINGHORZ
Definition: matroska.h:141
MatroskaMuxContext::is_live
int is_live
Definition: matroskaenc.c:157
AV_CRC_32_IEEE_LE
@ AV_CRC_32_IEEE_LE
Definition: crc.h:53
mkv_track::track_num_size
int track_num_size
Definition: matroskaenc.c:118
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:279
MATROSKA_ID_BLOCKREFERENCE
#define MATROSKA_ID_BLOCKREFERENCE
Definition: matroska.h:249
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mkv_write_track
static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, AVStream *st, mkv_track *track, AVIOContext *pb, int is_default)
Definition: matroskaenc.c:1168
AVCodecParameters::bits_per_coded_sample
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: codec_par.h:102
CodecTags::id
enum AVCodecID id
Definition: matroska.h:367
MATROSKA_ID_VIDEOCOLOR_RY
#define MATROSKA_ID_VIDEOCOLOR_RY
Definition: matroska.h:152
AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL
@ AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL
Data found in BlockAdditional element of matroska container.
Definition: packet.h:191
MATROSKA_VIDEO_FIELDORDER_TB
@ MATROSKA_VIDEO_FIELDORDER_TB
Definition: matroska.h:309
mastering_display_metadata.h
AVSphericalMapping::bound_left
uint32_t bound_left
Distance from the left edge.
Definition: spherical.h:167
mkv_cues::num_entries
int num_entries
Definition: matroskaenc.c:110
FFFormatContext::pkt
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
Definition: internal.h:132
AV_FIELD_PROGRESSIVE
@ AV_FIELD_PROGRESSIVE
Definition: codec_par.h:38
ff_mkv_stereo3d_conv
int ff_mkv_stereo3d_conv(AVStream *st, MatroskaVideoStereoModeType stereo_mode)
Definition: matroska.c:152
AVCodecParameters::format
int format
Definition: codec_par.h:84
MatroskaMuxContext::track
ebml_stored_master track
Definition: matroskaenc.c:132
MATROSKA_ID_TRACKVIDEO
#define MATROSKA_ID_TRACKVIDEO
Definition: matroska.h:81
avio_wb24
void avio_wb24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:484
ff_mkv_codec_tags
const CodecTags ff_mkv_codec_tags[]
Definition: matroska.c:29
MATROSKA_ID_TRACKFLAGFORCED
#define MATROSKA_ID_TRACKFLAGFORCED
Definition: matroska.h:100
MATROSKA_VIDEO_STEREOMODE_TYPE_NB
@ MATROSKA_VIDEO_STEREOMODE_TYPE_NB
Definition: matroska.h:329
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDictionaryEntry
Definition: dict.h:79
EBML_ID_EBMLREADVERSION
#define EBML_ID_EBMLREADVERSION
Definition: matroska.h:37
AVFieldOrder
AVFieldOrder
Definition: codec_par.h:36
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
AVContentLightMetadata::MaxFALL
unsigned MaxFALL
Max average light level per frame (cd/m^2).
Definition: mastering_display_metadata.h:107
AVPacket
This structure stores compressed data.
Definition: packet.h:350
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:241
mkv_write_chapters
static int mkv_write_chapters(AVFormatContext *s)
Definition: matroskaenc.c:1694
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
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
riff.h
MATROSKA_ID_ATTACHEDFILE
#define MATROSKA_ID_ATTACHEDFILE
Definition: matroska.h:254
MATROSKA_ID_CODECDELAY
#define MATROSKA_ID_CODECDELAY
Definition: matroska.h:94
AVCodecParameters::channel_layout
uint64_t channel_layout
Audio only.
Definition: codec_par.h:162
convert_header.str
string str
Definition: convert_header.py:20
mkv_write_seekhead
static int mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv, int error_on_seek_failure, int64_t destpos)
Write the SeekHead to the file at the location reserved for it and seek to destpos afterwards.
Definition: matroskaenc.c:495
MAX_CUETRACKPOS_SIZE
#define MAX_CUETRACKPOS_SIZE
4 * (1-byte EBML ID, 1-byte EBML size, 8-byte uint max)
Definition: matroskaenc.c:177
avio_wb16
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:472
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:190
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
MATROSKA_ID_TAGTARGETS_TRACKUID
#define MATROSKA_ID_TAGTARGETS_TRACKUID
Definition: matroska.h:224
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AV_CODEC_ID_WAVPACK
@ AV_CODEC_ID_WAVPACK
Definition: codec_id.h:448
AV_CODEC_ID_COOK
@ AV_CODEC_ID_COOK
Definition: codec_id.h:443
MATROSKA_ID_CHAPTERTIMEEND
#define MATROSKA_ID_CHAPTERTIMEEND
Definition: matroska.h:265
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
MATROSKA_ID_TRACKS
#define MATROSKA_ID_TRACKS
Definition: matroska.h:57
av1.h
AV_PKT_DATA_WEBVTT_IDENTIFIER
@ AV_PKT_DATA_WEBVTT_IDENTIFIER
The optional first identifier line of a WebVTT cue.
Definition: packet.h:196
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3521
AV_CODEC_ID_VORBIS
@ AV_CODEC_ID_VORBIS
Definition: codec_id.h:428
AVStereo3D
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
Definition: stereo3d.h:176
AVDictionaryEntry::value
char * value
Definition: dict.h:81
avstring.h
write_header
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:347
MATROSKA_ID_SEEKPREROLL
#define MATROSKA_ID_SEEKPREROLL
Definition: matroska.h:95
AV_RB24
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_RB24
Definition: bytestream.h:97
MatroskaMuxContext::wrote_chapters
int wrote_chapters
Definition: matroskaenc.c:150
put_ebml_sint
static void put_ebml_sint(AVIOContext *pb, uint32_t elementid, int64_t val)
Definition: matroskaenc.c:285
MATROSKA_ID_SEEKHEAD
#define MATROSKA_ID_SEEKHEAD
Definition: matroska.h:60
mkv_write_simpletag
static int mkv_write_simpletag(AVIOContext *pb, const AVDictionaryEntry *t)
Definition: matroskaenc.c:1504
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
snprintf
#define snprintf
Definition: snprintf.h:34
mkv_cuepoint
Definition: matroskaenc.c:100
AVCodecParameters::initial_padding
int initial_padding
Audio only.
Definition: codec_par.h:189
MATROSKA_ID_VIDEOPROJECTIONPOSEROLL
#define MATROSKA_ID_VIDEOPROJECTIONPOSEROLL
Definition: matroska.h:167
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
mkv_seekhead::num_entries
int num_entries
Definition: matroskaenc.c:96
AV_CODEC_ID_PCM_S24BE
@ AV_CODEC_ID_PCM_S24BE
Definition: codec_id.h:327
mkv_write_tag
static int mkv_write_tag(MatroskaMuxContext *mkv, const AVDictionary *m, AVIOContext **pb, ebml_master *tag, uint32_t elementid, uint64_t uid)
Definition: matroskaenc.c:1572
MATROSKA_ID_BLOCKADDID
#define MATROSKA_ID_BLOCKADDID
Definition: matroska.h:242
put_ebml_uid
static void put_ebml_uid(AVIOContext *pb, uint32_t elementid, uint64_t uid)
Write a (random) UID with fixed size to make the output more deterministic.
Definition: matroskaenc.c:265
AVSphericalMapping
This structure describes how to handle spherical videos, outlining information about projection,...
Definition: spherical.h:82
AV_RB64
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_RB64
Definition: bytestream.h:95
MODE_WEBM
#define MODE_WEBM
Definition: matroskaenc.c:65
AVSphericalMapping::yaw
int32_t yaw
Rotation around the up vector [-180, 180].
Definition: spherical.h:126
MATROSKA_ID_TAGTARGETS_CHAPTERUID
#define MATROSKA_ID_TAGTARGETS_CHAPTERUID
Definition: matroska.h:225
MATROSKA_VIDEO_PROJECTION_TYPE_CUBEMAP
@ MATROSKA_VIDEO_PROJECTION_TYPE_CUBEMAP
Definition: matroska.h:357
AV_CODEC_ID_MLP
@ AV_CODEC_ID_MLP
Definition: codec_id.h:452
AV_CODEC_ID_PRORES
@ AV_CODEC_ID_PRORES
Definition: codec_id.h:198
AV_RB16
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
Definition: bytestream.h:98
ff_alloc_extradata
int ff_alloc_extradata(AVCodecParameters *par, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0.
Definition: utils.c:451
MPEG4AudioConfig::sample_rate
int sample_rate
Definition: mpeg4audio.h:35
AVDOVIDecoderConfigurationRecord
Definition: dovi_meta.h:52
MATROSKA_ID_BLOCKADDITIONS
#define MATROSKA_ID_BLOCKADDITIONS
Definition: matroska.h:240
AVIO_DATA_MARKER_FLUSH_POINT
@ AVIO_DATA_MARKER_FLUSH_POINT
A point in the output bytestream where the underlying AVIOContext might flush the buffer depending on...
Definition: avio.h:146
mkv_assemble_cues
static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp, mkv_cues *cues, mkv_track *tracks, int num_tracks)
Definition: matroskaenc.c:568
FFFormatContext::avoid_negative_ts_use_pts
int avoid_negative_ts_use_pts
Definition: internal.h:156