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_components.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 "nal.h"
37 #include "matroska.h"
38 #include "mux.h"
39 #include "riff.h"
40 #include "version.h"
41 #include "vorbiscomment.h"
42 #include "vvc.h"
43 #include "wv.h"
44 
45 #include "libavutil/avstring.h"
47 #include "libavutil/crc.h"
48 #include "libavutil/dict.h"
50 #include "libavutil/intfloat.h"
51 #include "libavutil/intreadwrite.h"
52 #include "libavutil/lfg.h"
54 #include "libavutil/mathematics.h"
55 #include "libavutil/mem.h"
56 #include "libavutil/opt.h"
57 #include "libavutil/parseutils.h"
58 #include "libavutil/pixdesc.h"
59 #include "libavutil/random_seed.h"
60 #include "libavutil/rational.h"
61 #include "libavutil/samplefmt.h"
62 #include "libavutil/stereo3d.h"
63 
64 #include "libavcodec/av1.h"
65 #include "libavcodec/bytestream.h"
66 #include "libavcodec/codec_desc.h"
67 #include "libavcodec/codec_par.h"
68 #include "libavcodec/defs.h"
69 #include "libavcodec/itut35.h"
70 #include "libavcodec/xiph.h"
71 #include "libavcodec/mpeg4audio.h"
72 
73 /* Level 1 elements we create a SeekHead entry for:
74  * Info, Tracks, Chapters, Attachments, Tags (potentially twice) and Cues */
75 #define MAX_SEEKHEAD_ENTRIES 7
76 
77 /* Largest known-length EBML length */
78 #define MAX_EBML_LENGTH ((1ULL << 56) - 2)
79 /* The dynamic buffer API we rely upon has a limit of INT_MAX;
80  * and so has avio_write(). */
81 #define MAX_SUPPORTED_EBML_LENGTH FFMIN(MAX_EBML_LENGTH, INT_MAX)
82 
83 #define MODE_MATROSKAv2 0x01
84 #define MODE_WEBM 0x02
85 
86 #define IS_WEBM(mkv) (CONFIG_WEBM_MUXER && CONFIG_MATROSKA_MUXER ? \
87  ((mkv)->mode == MODE_WEBM) : CONFIG_WEBM_MUXER)
88 #define IS_SEEKABLE(pb, mkv) (((pb)->seekable & AVIO_SEEKABLE_NORMAL) && \
89  !(mkv)->is_live)
90 
91 enum {
95 };
96 
97 typedef struct ebml_master {
98  int64_t pos; ///< absolute offset in the containing AVIOContext where the master's elements start
99  int sizebytes; ///< how many bytes were reserved for the size
100 } ebml_master;
101 
102 typedef struct ebml_stored_master {
106 
107 typedef enum EbmlType {
115  EBML_BLOCK, ///< pseudo-type for writing (Simple)Blocks
117 } EbmlType;
118 
119 typedef struct BlockContext {
120  struct mkv_track *track;
121  const AVPacket *pkt;
122  int16_t rel_ts;
123  uint8_t flags;
125 } BlockContext;
126 
127 typedef struct EbmlMaster {
128  int nb_elements; ///< -1 if not finished
129  int containing_master; ///< -1 if no parent exists
130 } EbmlMaster;
131 
132 typedef struct EbmlElement {
133  uint32_t id;
135  unsigned length_size;
136  uint64_t size; ///< excluding id and length field
137  union {
138  uint64_t uint;
140  double f;
141  const char *str;
142  const uint8_t *bin;
143  struct MatroskaMuxContext *mkv; ///< used by EBML_BLOCK
145  } priv;
146 } EbmlElement;
147 
148 typedef struct EbmlWriter {
149  unsigned nb_elements;
152 } EbmlWriter;
153 
154 #define EBML_WRITER(max_nb_elems) \
155  EbmlElement elements[max_nb_elems]; \
156  EbmlWriter writer = (EbmlWriter){ .elements = elements, \
157  .current_master_element = -1 }
158 
159 typedef struct mkv_seekhead_entry {
160  uint32_t elementid;
161  uint64_t segmentpos;
163 
164 typedef struct mkv_seekhead {
169 } mkv_seekhead;
170 
171 typedef struct mkv_cuepoint {
172  uint64_t pts;
174  int64_t cluster_pos; ///< offset of the cluster containing the block relative to the segment
175  int64_t relative_pos; ///< relative offset from the position of the cluster containing the block
176  int64_t duration; ///< duration of the block according to time base
177 } mkv_cuepoint;
178 
179 typedef struct mkv_cues {
182 } mkv_cues;
183 
184 struct MatroskaMuxContext;
185 
186 typedef struct mkv_track {
188  int has_cue;
189  uint64_t uid;
190  unsigned track_num;
193  unsigned offset;
198  uint64_t max_blockaddid;
201  unsigned codecpriv_size; ///< size reserved for CodecPrivate excluding header+length field
205  /* This callback will be called twice: First with a NULL AVIOContext
206  * to return the size of the (Simple)Block's data via size
207  * and a second time with the AVIOContext set when the data
208  * shall be written.
209  * The callback shall not return an error on the second call. */
211  const AVPacket *, int *size);
212 } mkv_track;
213 
214 typedef struct MatroskaMuxContext {
215  const AVClass *class;
217 
218  int mode;
224  int64_t cluster_pos; ///< file offset of the current Cluster
232 
234 
235  /* Used as temporary buffer to use the minimal amount of bytes
236  * to write the length field of EBML Masters.
237  * Every user has to reset the buffer after using it and
238  * different uses may not overlap. It is currently used in
239  * mkv_write_tag(), in mkv_assemble_cues() as well as in
240  * mkv_update_codecprivate() and mkv_write_track(). */
242 
244 
245  unsigned nb_attachments;
247 
250 
255  int is_live;
256 
257  int is_dash;
263 
264  uint32_t segment_uid[4];
266 
267 /** 2 bytes * 3 for EBML IDs, 3 1-byte EBML lengths, 8 bytes for 64 bit
268  * offset, 4 bytes for target EBML ID */
269 #define MAX_SEEKENTRY_SIZE 21
270 
271 /** 4 * (1-byte EBML ID, 1-byte EBML size, 8-byte uint max) */
272 #define MAX_CUETRACKPOS_SIZE 40
273 
274 /** DURATION_STRING_LENGTH must be <= 112 or the containing
275  * simpletag will need more than one byte for its length field. */
276 #define DURATION_STRING_LENGTH 19
277 
278 /** 2 + 1 Simpletag header, 2 + 1 + 8 Name "DURATION", rest for TagString */
279 #define DURATION_SIMPLETAG_SIZE (2 + 1 + (2 + 1 + 8) + (2 + 1 + DURATION_STRING_LENGTH))
280 
281 /** Seek preroll value for opus */
282 #define OPUS_SEEK_PREROLL 80000000
283 
284 static int ebml_id_size(uint32_t id)
285 {
286  return (av_log2(id) + 7U) / 8;
287 }
288 
289 static void put_ebml_id(AVIOContext *pb, uint32_t id)
290 {
291  int i = ebml_id_size(id);
292  while (i--)
293  avio_w8(pb, (uint8_t)(id >> (i * 8)));
294 }
295 
296 /**
297  * Write an EBML size meaning "unknown size".
298  *
299  * @param bytes The number of bytes the size should occupy (maximum: 8).
300  */
301 static void put_ebml_size_unknown(AVIOContext *pb, int bytes)
302 {
303  av_assert0(bytes <= 8);
304  avio_w8(pb, 0x1ff >> bytes);
305  if (av_builtin_constant_p(bytes) && bytes == 1)
306  return;
307  ffio_fill(pb, 0xff, bytes - 1);
308 }
309 
310 /**
311  * Returns how many bytes are needed to represent a number
312  * as EBML variable length integer.
313  */
314 static int ebml_num_size(uint64_t num)
315 {
316  int bytes = 0;
317  do {
318  bytes++;
319  } while (num >>= 7);
320  return bytes;
321 }
322 
323 /**
324  * Calculate how many bytes are needed to represent the length field
325  * of an EBML element whose payload has a given length.
326  */
327 static int ebml_length_size(uint64_t length)
328 {
329  return ebml_num_size(length + 1);
330 }
331 
332 /**
333  * Write a number as EBML variable length integer on `bytes` bytes.
334  * `bytes` is taken literally without checking.
335  */
336 static void put_ebml_num(AVIOContext *pb, uint64_t num, int bytes)
337 {
338  num |= 1ULL << bytes * 7;
339  for (int i = bytes - 1; i >= 0; i--)
340  avio_w8(pb, (uint8_t)(num >> i * 8));
341 }
342 
343 /**
344  * Write a length as EBML variable length integer.
345  *
346  * @param bytes The number of bytes that need to be used to write the number.
347  * If zero, the minimal number of bytes will be used.
348  */
349 static void put_ebml_length(AVIOContext *pb, uint64_t length, int bytes)
350 {
351  int needed_bytes = ebml_length_size(length);
352 
353  // sizes larger than this are currently undefined in EBML
354  av_assert0(length < (1ULL << 56) - 1);
355 
356  if (bytes == 0)
357  bytes = needed_bytes;
358  // The bytes needed to write the given size must not exceed
359  // the bytes that we ought to use.
360  av_assert0(bytes >= needed_bytes);
361  put_ebml_num(pb, length, bytes);
362 }
363 
364 /**
365  * Write a (random) UID with fixed size to make the output more deterministic
366  */
367 static void put_ebml_uid(AVIOContext *pb, uint32_t elementid, uint64_t uid)
368 {
369  put_ebml_id(pb, elementid);
370  put_ebml_length(pb, 8, 0);
371  avio_wb64(pb, uid);
372 }
373 
374 static void put_ebml_uint(AVIOContext *pb, uint32_t elementid, uint64_t val)
375 {
376  int i, bytes = 1;
377  uint64_t tmp = val;
378  while (tmp >>= 8)
379  bytes++;
380 
381  put_ebml_id(pb, elementid);
382  put_ebml_length(pb, bytes, 0);
383  for (i = bytes - 1; i >= 0; i--)
384  avio_w8(pb, (uint8_t)(val >> i * 8));
385 }
386 
387 static void put_ebml_float(AVIOContext *pb, uint32_t elementid, double val)
388 {
389  put_ebml_id(pb, elementid);
390  put_ebml_length(pb, 8, 0);
392 }
393 
394 static void put_ebml_binary(AVIOContext *pb, uint32_t elementid,
395  const void *buf, int size)
396 {
397  put_ebml_id(pb, elementid);
398  put_ebml_length(pb, size, 0);
399  avio_write(pb, buf, size);
400 }
401 
402 static void put_ebml_string(AVIOContext *pb, uint32_t elementid,
403  const char *str)
404 {
405  put_ebml_binary(pb, elementid, str, strlen(str));
406 }
407 
408 /**
409  * Write a void element of a given size. Useful for reserving space in
410  * the file to be written to later.
411  *
412  * @param size The number of bytes to reserve, which must be at least 2.
413  */
414 static void put_ebml_void(AVIOContext *pb, int size)
415 {
416  av_assert0(size >= 2);
417 
419  // we need to subtract the length needed to store the size from the
420  // size we need to reserve so 2 cases, we use 8 bytes to store the
421  // size if possible, 1 byte otherwise
422  if (size < 10) {
423  size -= 2;
424  put_ebml_length(pb, size, 0);
425  } else {
426  size -= 9;
427  put_ebml_length(pb, size, 8);
428  }
429  ffio_fill(pb, 0, size);
430 }
431 
432 static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid,
433  uint64_t expectedsize)
434 {
435  int bytes = expectedsize ? ebml_length_size(expectedsize) : 8;
436 
437  put_ebml_id(pb, elementid);
438  put_ebml_size_unknown(pb, bytes);
439  return (ebml_master) { avio_tell(pb), bytes };
440 }
441 
443 {
444  int64_t pos = avio_tell(pb);
445 
446  if (avio_seek(pb, master.pos - master.sizebytes, SEEK_SET) < 0)
447  return;
448  put_ebml_length(pb, pos - master.pos, master.sizebytes);
449  avio_seek(pb, pos, SEEK_SET);
450 }
451 
453  uint32_t id, EbmlType type)
454 {
455  writer->elements[writer->nb_elements].id = id;
456  writer->elements[writer->nb_elements].type = type;
457  return &writer->elements[writer->nb_elements++];
458 }
459 
460 static void ebml_writer_open_master(EbmlWriter *writer, uint32_t id)
461 {
462  EbmlElement *const elem = ebml_writer_add(writer, id, EBML_MASTER);
463  EbmlMaster *const master = &elem->priv.master;
464 
465  master->containing_master = writer->current_master_element;
466  master->nb_elements = -1;
467 
468  writer->current_master_element = writer->nb_elements - 1;
469 }
470 
472 {
473  EbmlElement *elem;
474  av_assert2(writer->current_master_element >= 0);
475  av_assert2(writer->current_master_element < writer->nb_elements);
476  elem = &writer->elements[writer->current_master_element];
477  av_assert2(elem->type == EBML_MASTER);
478  av_assert2(elem->priv.master.nb_elements < 0); /* means unset */
479  elem->priv.master.nb_elements = writer->nb_elements - writer->current_master_element - 1;
483 }
484 
486 {
487  av_assert2(writer->nb_elements > 0);
488  av_assert2(0 <= writer->current_master_element);
489  av_assert2(writer->current_master_element < writer->nb_elements);
490  if (writer->current_master_element == writer->nb_elements - 1) {
491  const EbmlElement *const elem = &writer->elements[writer->nb_elements - 1];
492  /* The master element has no children. Discard it. */
493  av_assert2(elem->type == EBML_MASTER);
497  writer->nb_elements--;
498  return;
499  }
500  ebml_writer_close_master(writer);
501 }
502 
503 static void ebml_writer_add_string(EbmlWriter *writer, uint32_t id,
504  const char *str)
505 {
506  EbmlElement *const elem = ebml_writer_add(writer, id, EBML_STR);
507 
508  elem->priv.str = str;
509 }
510 
511 static void ebml_writer_add_bin(EbmlWriter *writer, uint32_t id,
512  const uint8_t *data, size_t size)
513 {
514  EbmlElement *const elem = ebml_writer_add(writer, id, EBML_BIN);
515 
516 #if SIZE_MAX > UINT64_MAX
517  size = FFMIN(size, UINT64_MAX);
518 #endif
519  elem->size = size;
520  elem->priv.bin = data;
521 }
522 
523 static void ebml_writer_add_float(EbmlWriter *writer, uint32_t id,
524  double val)
525 {
526  EbmlElement *const elem = ebml_writer_add(writer, id, EBML_FLOAT);
527 
528  elem->priv.f = val;
529 }
530 
531 static void ebml_writer_add_uid(EbmlWriter *writer, uint32_t id,
532  uint64_t val)
533 {
534  EbmlElement *const elem = ebml_writer_add(writer, id, EBML_UID);
535  elem->priv.uint = val;
536 }
537 
538 static void ebml_writer_add_uint(EbmlWriter *writer, uint32_t id,
539  uint64_t val)
540 {
541  EbmlElement *elem = ebml_writer_add(writer, id, EBML_UINT);
542  elem->priv.uint = val;
543 }
544 
545 static void ebml_writer_add_sint(EbmlWriter *writer, uint32_t id,
546  int64_t val)
547 {
548  EbmlElement *elem = ebml_writer_add(writer, id, EBML_SINT);
549  elem->priv.sint = val;
550 }
551 
553 {
555  elem->priv.mkv = mkv;
556 }
557 
559 {
560  size_t len = strlen(elem->priv.str);
561 #if SIZE_MAX > UINT64_MAX
562  len = FF_MIN(len, UINT64_MAX);
563 #endif
564  elem->size = len;
565  return 0;
566 }
567 
568 static av_const int uint_size(uint64_t val)
569 {
570  int bytes = 0;
571  do {
572  bytes++;
573  } while (val >>= 8);
574  return bytes;
575 }
576 
578 {
579  elem->size = uint_size(elem->priv.uint);
580  return 0;
581 }
582 
584 {
585  uint64_t tmp = 2 * (uint64_t)(val < 0 ? val^-1 : val);
586  return uint_size(tmp);
587 }
588 
590 {
591  elem->size = sint_size(elem->priv.sint);
592  return 0;
593 }
594 
595 static int ebml_writer_elem_len(EbmlWriter *writer, EbmlElement *elem,
596  int remaining_elems);
597 
599  int remaining_elems)
600 {
601  int nb_elems = elem->priv.master.nb_elements >= 0 ? elem->priv.master.nb_elements : remaining_elems - 1;
602  EbmlElement *const master = elem;
603  uint64_t total_size = 0;
604 
605  master->priv.master.nb_elements = nb_elems;
606  for (; elem++, nb_elems > 0;) {
607  int ret = ebml_writer_elem_len(writer, elem, nb_elems);
608  if (ret < 0)
609  return ret;
610  av_assert2(ret < nb_elems);
611  /* No overflow is possible here, as both total_size and elem->size
612  * are bounded by MAX_SUPPORTED_EBML_LENGTH. */
613  total_size += ebml_id_size(elem->id) + elem->length_size + elem->size;
614  if (total_size > MAX_SUPPORTED_EBML_LENGTH)
615  return AVERROR(ERANGE);
616  nb_elems--; /* consume elem */
617  elem += ret, nb_elems -= ret; /* and elem's children */
618  }
619  master->size = total_size;
620 
621  return master->priv.master.nb_elements;
622 }
623 
625 {
626  MatroskaMuxContext *const mkv = elem->priv.mkv;
627  BlockContext *const block = &mkv->cur_block;
628  mkv_track *const track = block->track;
629  const AVPacket *const pkt = block->pkt;
630  int err, size;
631 
632  if (track->reformat) {
633  err = track->reformat(mkv, NULL, pkt, &size);
634  if (err < 0) {
635  av_log(mkv->ctx, AV_LOG_ERROR, "Error when reformatting data of "
636  "a packet from stream %d.\n", pkt->stream_index);
637  return err;
638  }
639  } else {
640  size = pkt->size;
641  if (track->offset <= size)
642  size -= track->offset;
643  }
644  elem->size = track->track_num_size + 3U + size;
645 
646  return 0;
647 }
648 
649 static void ebml_writer_write_block(const EbmlElement *elem, AVIOContext *pb)
650 {
651  MatroskaMuxContext *const mkv = elem->priv.mkv;
652  BlockContext *const block = &mkv->cur_block;
653  mkv_track *const track = block->track;
654  const AVPacket *const pkt = block->pkt;
655 
656  put_ebml_num(pb, track->track_num, track->track_num_size);
657  avio_wb16(pb, block->rel_ts);
658  avio_w8(pb, block->flags);
659 
660  if (track->reformat) {
661  int size;
662  track->reformat(mkv, pb, pkt, &size);
663  } else {
664  const uint8_t *data = pkt->data;
665  unsigned offset = track->offset <= pkt->size ? track->offset : 0;
666  avio_write(pb, data + offset, pkt->size - offset);
667  }
668 }
669 
670 static int ebml_writer_elem_len(EbmlWriter *writer, EbmlElement *elem,
671  int remaining_elems)
672 {
673  int ret = 0;
674 
675  switch (elem->type) {
676  case EBML_FLOAT:
677  case EBML_UID:
678  elem->size = 8;
679  break;
680  case EBML_STR:
681  ret = ebml_writer_str_len(elem);
682  break;
683  case EBML_UINT:
684  ret = ebml_writer_uint_len(elem);
685  break;
686  case EBML_SINT:
687  ret = ebml_writer_sint_len(elem);
688  break;
689  case EBML_BLOCK:
690  ret = ebml_writer_block_len(elem);
691  break;
692  case EBML_MASTER:
693  ret = ebml_writer_master_len(writer, elem, remaining_elems);
694  break;
695  }
696  if (ret < 0)
697  return ret;
698  if (elem->size > MAX_SUPPORTED_EBML_LENGTH)
699  return AVERROR(ERANGE);
700  elem->length_size = ebml_length_size(elem->size);
701  return ret; /* number of elements consumed excluding elem itself */
702 }
703 
704 static int ebml_writer_elem_write(const EbmlElement *elem, AVIOContext *pb)
705 {
706  put_ebml_id(pb, elem->id);
707  put_ebml_num(pb, elem->size, elem->length_size);
708  switch (elem->type) {
709  case EBML_UID:
710  case EBML_FLOAT: {
711  uint64_t val = elem->type == EBML_UID ? elem->priv.uint
712  : av_double2int(elem->priv.f);
713  avio_wb64(pb, val);
714  break;
715  }
716  case EBML_UINT:
717  case EBML_SINT: {
718  uint64_t val = elem->type == EBML_UINT ? elem->priv.uint
719  : elem->priv.sint;
720  for (int i = elem->size; --i >= 0; )
721  avio_w8(pb, (uint8_t)(val >> i * 8));
722  break;
723  }
724  case EBML_STR:
725  case EBML_BIN: {
726  const uint8_t *data = elem->type == EBML_BIN ? elem->priv.bin
727  : (const uint8_t*)elem->priv.str;
728  avio_write(pb, data, elem->size);
729  break;
730  }
731  case EBML_BLOCK:
732  ebml_writer_write_block(elem, pb);
733  break;
734  case EBML_MASTER: {
735  int nb_elems = elem->priv.master.nb_elements;
736 
737  elem++;
738  for (int i = 0; i < nb_elems; i++)
739  i += ebml_writer_elem_write(elem + i, pb);
740 
741  return nb_elems;
742  }
743  }
744  return 0;
745 }
746 
747 static int ebml_writer_write(EbmlWriter *writer, AVIOContext *pb)
748 {
749  int ret = ebml_writer_elem_len(writer, writer->elements,
750  writer->nb_elements);
751  if (ret < 0)
752  return ret;
753  ebml_writer_elem_write(writer->elements, pb);
754  return 0;
755 }
756 
757 static void mkv_add_seekhead_entry(MatroskaMuxContext *mkv, uint32_t elementid,
758  uint64_t filepos)
759 {
760  mkv_seekhead *seekhead = &mkv->seekhead;
761 
763 
764  seekhead->entries[seekhead->num_entries].elementid = elementid;
765  seekhead->entries[seekhead->num_entries++].segmentpos = filepos - mkv->segment_offset;
766 }
767 
769 {
770  int ret;
771 
772  if (!*dyn_cp && (ret = avio_open_dyn_buf(dyn_cp)) < 0)
773  return ret;
774 
775  if (mkv->write_crc)
776  put_ebml_void(*dyn_cp, 6); /* Reserve space for CRC32 so position/size calculations using avio_tell() take it into account */
777 
778  return 0;
779 }
780 
782  MatroskaMuxContext *mkv, uint32_t id,
783  int length_size, int keep_buffer,
784  int add_seekentry)
785 {
786  uint8_t *buf, crc[4];
787  int ret, size, skip = 0;
788 
789  size = avio_get_dyn_buf(*dyn_cp, &buf);
790  if ((ret = (*dyn_cp)->error) < 0)
791  goto fail;
792 
793  if (add_seekentry)
794  mkv_add_seekhead_entry(mkv, id, avio_tell(pb));
795 
796  put_ebml_id(pb, id);
797  put_ebml_length(pb, size, length_size);
798  if (mkv->write_crc) {
799  skip = 6; /* Skip reserved 6-byte long void element from the dynamic buffer. */
800  AV_WL32(crc, av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), UINT32_MAX, buf + skip, size - skip) ^ UINT32_MAX);
801  put_ebml_binary(pb, EBML_ID_CRC32, crc, sizeof(crc));
802  }
803  avio_write(pb, buf + skip, size - skip);
804 
805 fail:
806  if (keep_buffer) {
807  ffio_reset_dyn_buf(*dyn_cp);
808  } else {
809  ffio_free_dyn_buf(dyn_cp);
810  }
811  return ret;
812 }
813 
814 /**
815  * Output EBML master. Keep the buffer if seekable, allowing for later updates.
816  * Furthermore always add a SeekHead Entry for this element.
817  */
819  ebml_stored_master *elem,
820  MatroskaMuxContext *mkv, uint32_t id)
821 {
822  if (IS_SEEKABLE(pb, mkv)) {
823  uint8_t *buf;
824  int size = avio_get_dyn_buf(elem->bc, &buf);
825 
826  if (elem->bc->error < 0)
827  return elem->bc->error;
828 
829  elem->pos = avio_tell(pb);
830  mkv_add_seekhead_entry(mkv, id, elem->pos);
831 
832  put_ebml_id(pb, id);
833  put_ebml_length(pb, size, 0);
834  avio_write(pb, buf, size);
835 
836  return 0;
837  } else
838  return end_ebml_master_crc32(pb, &elem->bc, mkv, id, 0, 0, 1);
839 }
840 
841 static void put_xiph_size(AVIOContext *pb, int size)
842 {
843  ffio_fill(pb, 255, size / 255);
844  avio_w8(pb, size % 255);
845 }
846 
847 /**
848  * Free the members allocated in the mux context.
849  */
851 {
852  MatroskaMuxContext *mkv = s->priv_data;
853 
855  ffio_free_dyn_buf(&mkv->info.bc);
856  ffio_free_dyn_buf(&mkv->track.bc);
857  ffio_free_dyn_buf(&mkv->tags.bc);
858  ffio_free_dyn_buf(&mkv->tmp_bc);
859 
861  av_freep(&mkv->cues.entries);
862  av_freep(&mkv->tracks);
863 }
864 
865 /**
866  * Initialize the SeekHead element to be ready to index level 1 Matroska
867  * elements. Enough space to write MAX_SEEKHEAD_ENTRIES SeekHead entries
868  * will be reserved at the current file location.
869  */
871 {
872  mkv->seekhead.filepos = avio_tell(pb);
873  // 21 bytes max for a Seek entry, 6 bytes max for the SeekHead ID
874  // and size, 6 bytes for a CRC32 element, and 2 bytes to guarantee
875  // that an EBML void element will fit afterwards
878 }
879 
880 /**
881  * Write the SeekHead to the file at the location reserved for it
882  * and seek to destpos afterwards. When error_on_seek_failure
883  * is not set, failure to seek to the position designated for the
884  * SeekHead is not considered an error and it is presumed that
885  * destpos is the current position; failure to seek to destpos
886  * afterwards is always an error.
887  *
888  * @return 0 on success, < 0 on error.
889  */
891  int error_on_seek_failure, int64_t destpos)
892 {
893  AVIOContext *dyn_cp = NULL;
894  mkv_seekhead *seekhead = &mkv->seekhead;
895  int64_t remaining, ret64;
896  int i, ret;
897 
898  if ((ret64 = avio_seek(pb, seekhead->filepos, SEEK_SET)) < 0)
899  return error_on_seek_failure ? ret64 : 0;
900 
901  ret = start_ebml_master_crc32(&dyn_cp, mkv);
902  if (ret < 0)
903  return ret;
904 
905  for (i = 0; i < seekhead->num_entries; i++) {
906  mkv_seekhead_entry *entry = &seekhead->entries[i];
909 
911  put_ebml_length(dyn_cp, ebml_id_size(entry->elementid), 0);
912  put_ebml_id(dyn_cp, entry->elementid);
913 
914  put_ebml_uint(dyn_cp, MATROSKA_ID_SEEKPOSITION, entry->segmentpos);
915  end_ebml_master(dyn_cp, seekentry);
916  }
917  ret = end_ebml_master_crc32(pb, &dyn_cp, mkv,
918  MATROSKA_ID_SEEKHEAD, 0, 0, 0);
919  if (ret < 0)
920  return ret;
921 
922  remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb);
923  put_ebml_void(pb, remaining);
924 
925  if ((ret64 = avio_seek(pb, destpos, SEEK_SET)) < 0)
926  return ret64;
927 
928  return 0;
929 }
930 
931 static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int stream, int64_t ts,
932  int64_t cluster_pos, int64_t relative_pos, int64_t duration)
933 {
934  mkv_cues *cues = &mkv->cues;
935  mkv_cuepoint *entries = cues->entries;
936  unsigned idx = cues->num_entries;
937 
938  if (ts < 0)
939  return 0;
940 
941  entries = av_realloc_array(entries, cues->num_entries + 1, sizeof(mkv_cuepoint));
942  if (!entries)
943  return AVERROR(ENOMEM);
944  cues->entries = entries;
945 
946  /* Make sure the cues entries are sorted by pts. */
947  while (idx > 0 && entries[idx - 1].pts > ts)
948  idx--;
949  memmove(&entries[idx + 1], &entries[idx],
950  (cues->num_entries - idx) * sizeof(entries[0]));
951 
952  entries[idx].pts = ts;
953  entries[idx].stream_idx = stream;
954  entries[idx].cluster_pos = cluster_pos - mkv->segment_offset;
955  entries[idx].relative_pos = relative_pos;
956  entries[idx].duration = duration;
957 
958  cues->num_entries++;
959 
960  return 0;
961 }
962 
963 static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp, AVIOContext *cuepoint,
964  const mkv_cues *cues, mkv_track *tracks, int num_tracks,
965  uint64_t offset)
966 {
967  for (mkv_cuepoint *entry = cues->entries, *end = entry + cues->num_entries;
968  entry < end;) {
969  uint64_t pts = entry->pts;
970  uint8_t *buf;
971  int size;
972 
974 
975  // put all the entries from different tracks that have the exact same
976  // timestamp into the same CuePoint
977  for (int j = 0; j < num_tracks; j++)
978  tracks[j].has_cue = 0;
979  do {
980  ebml_master track_positions;
981  int idx = entry->stream_idx;
982 
983  av_assert0(idx >= 0 && idx < num_tracks);
984  if (tracks[idx].has_cue && streams[idx]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE)
985  continue;
986  tracks[idx].has_cue = 1;
988  put_ebml_uint(cuepoint, MATROSKA_ID_CUETRACK , tracks[idx].track_num);
989  put_ebml_uint(cuepoint, MATROSKA_ID_CUECLUSTERPOSITION , entry->cluster_pos + offset);
990  put_ebml_uint(cuepoint, MATROSKA_ID_CUERELATIVEPOSITION, entry->relative_pos);
991  if (entry->duration > 0)
992  put_ebml_uint(cuepoint, MATROSKA_ID_CUEDURATION , entry->duration);
993  end_ebml_master(cuepoint, track_positions);
994  } while (++entry < end && entry->pts == pts);
995  size = avio_get_dyn_buf(cuepoint, &buf);
996  if (cuepoint->error < 0)
997  return cuepoint->error;
999  ffio_reset_dyn_buf(cuepoint);
1000  }
1001 
1002  return 0;
1003 }
1004 
1006  const AVCodecParameters *par,
1007  const uint8_t *extradata, int extradata_size)
1008 {
1009  const uint8_t *header_start[3];
1010  int header_len[3];
1011  int first_header_size;
1012  int err, j;
1013 
1014  if (par->codec_id == AV_CODEC_ID_VORBIS)
1015  first_header_size = 30;
1016  else
1017  first_header_size = 42;
1018 
1019  err = avpriv_split_xiph_headers(extradata, extradata_size,
1020  first_header_size, header_start, header_len);
1021  if (err < 0) {
1022  av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n");
1023  return err;
1024  }
1025 
1026  avio_w8(pb, 2); // number packets - 1
1027  for (j = 0; j < 2; j++) {
1028  put_xiph_size(pb, header_len[j]);
1029  }
1030  for (j = 0; j < 3; j++)
1031  avio_write(pb, header_start[j], header_len[j]);
1032 
1033  return 0;
1034 }
1035 
1036 #if CONFIG_MATROSKA_MUXER
1037 static int put_wv_codecpriv(AVIOContext *pb, const uint8_t *extradata, int extradata_size)
1038 {
1039  if (extradata && extradata_size == 2)
1040  avio_write(pb, extradata, 2);
1041  else
1042  avio_wl16(pb, 0x410); // fallback to the most recent version
1043  return 0;
1044 }
1045 
1046 static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb,
1047  const AVCodecParameters *par,
1048  const uint8_t *extradata, int extradata_size)
1049 {
1050  int write_comment = (par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE &&
1051  !(par->ch_layout.u.mask & ~0x3ffffULL) &&
1053  int ret = ff_flac_write_header(pb, extradata, extradata_size,
1054  !write_comment);
1055 
1056  if (ret < 0)
1057  return ret;
1058 
1059  if (write_comment) {
1060  const char *vendor = (s->flags & AVFMT_FLAG_BITEXACT) ?
1061  "Lavf" : LIBAVFORMAT_IDENT;
1062  AVDictionary *dict = NULL;
1063  uint8_t buf[32];
1064  int64_t len;
1065 
1066  snprintf(buf, sizeof(buf), "0x%"PRIx64, par->ch_layout.u.mask);
1067  av_dict_set(&dict, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0);
1068 
1069  len = ff_vorbiscomment_length(dict, vendor, NULL, 0);
1070  av_assert1(len < (1 << 24) - 4);
1071 
1072  avio_w8(pb, 0x84);
1073  avio_wb24(pb, len);
1074 
1075  ff_vorbiscomment_write(pb, dict, vendor, NULL, 0);
1076 
1077  av_dict_free(&dict);
1078  }
1079 
1080  return 0;
1081 }
1082 
1083 static int get_aac_sample_rates(AVFormatContext *s, MatroskaMuxContext *mkv,
1084  const uint8_t *extradata, int extradata_size,
1085  int *sample_rate, int *output_sample_rate)
1086 {
1087  MPEG4AudioConfig mp4ac;
1088  int ret;
1089 
1090  ret = avpriv_mpeg4audio_get_config2(&mp4ac, extradata, extradata_size, 1, s);
1091  /* Don't abort if the failure is because of missing extradata. Assume in that
1092  * case a bitstream filter will provide the muxer with the extradata in the
1093  * first packet.
1094  * Abort however if s->pb is not seekable, as we would not be able to seek back
1095  * to write the sample rate elements once the extradata shows up, anyway. */
1096  if (ret < 0 && (extradata_size || !IS_SEEKABLE(s->pb, mkv))) {
1098  "Error parsing AAC extradata, unable to determine samplerate.\n");
1099  return AVERROR(EINVAL);
1100  }
1101 
1102  if (ret < 0) {
1103  /* This will only happen when this function is called while writing the
1104  * header and no extradata is available. The space for this element has
1105  * to be reserved for when this function is called again after the
1106  * extradata shows up in the first packet, as there's no way to know if
1107  * output_sample_rate will be different than sample_rate or not. */
1108  *output_sample_rate = *sample_rate;
1109  } else {
1110  *sample_rate = mp4ac.sample_rate;
1111  *output_sample_rate = mp4ac.ext_sample_rate;
1112  }
1113  return 0;
1114 }
1115 #endif
1116 
1118  const AVCodecParameters *par,
1119  const uint8_t *extradata,
1120  int extradata_size,
1121  unsigned *size_to_reserve)
1122 {
1123  switch (par->codec_id) {
1124  case AV_CODEC_ID_VORBIS:
1125  case AV_CODEC_ID_THEORA:
1126  return put_xiph_codecpriv(s, dyn_cp, par, extradata, extradata_size);
1127  case AV_CODEC_ID_AV1:
1128  if (extradata_size)
1129  return ff_isom_write_av1c(dyn_cp, extradata,
1130  extradata_size, 1);
1131  else
1132  *size_to_reserve = (AV1_SANE_SEQUENCE_HEADER_MAX_BITS + 7) / 8 + 100;
1133  break;
1134 #if CONFIG_MATROSKA_MUXER
1135  case AV_CODEC_ID_FLAC:
1136  return put_flac_codecpriv(s, dyn_cp, par, extradata, extradata_size);
1137  case AV_CODEC_ID_WAVPACK:
1138  return put_wv_codecpriv(dyn_cp, extradata, extradata_size);
1139  case AV_CODEC_ID_H264:
1140  return ff_isom_write_avcc(dyn_cp, extradata,
1141  extradata_size);
1142  case AV_CODEC_ID_HEVC:
1143  return ff_isom_write_hvcc(dyn_cp, extradata,
1144  extradata_size, 0, s);
1145  case AV_CODEC_ID_VVC:
1146  return ff_isom_write_vvcc(dyn_cp, extradata,
1147  extradata_size, 0);
1148  case AV_CODEC_ID_ALAC:
1149  if (extradata_size < 36) {
1151  "Invalid extradata found, ALAC expects a 36-byte "
1152  "QuickTime atom.");
1153  return AVERROR_INVALIDDATA;
1154  } else
1155  avio_write(dyn_cp, extradata + 12,
1156  extradata_size - 12);
1157  break;
1158  case AV_CODEC_ID_AAC:
1159  if (extradata_size)
1160  avio_write(dyn_cp, extradata, extradata_size);
1161  else
1162  *size_to_reserve = MAX_PCE_SIZE;
1163  break;
1164  case AV_CODEC_ID_ARIB_CAPTION: {
1165  unsigned stream_identifier, data_component_id;
1166  switch (par->profile) {
1168  stream_identifier = 0x30;
1169  data_component_id = 0x0008;
1170  break;
1172  stream_identifier = 0x87;
1173  data_component_id = 0x0012;
1174  break;
1175  default:
1177  "Unset/unknown ARIB caption profile %d utilized!\n",
1178  par->profile);
1179  return AVERROR_INVALIDDATA;
1180  }
1181  avio_w8(dyn_cp, stream_identifier);
1182  avio_wb16(dyn_cp, data_component_id);
1183  break;
1184  }
1185 #endif
1186  default:
1187  if (CONFIG_MATROSKA_MUXER && par->codec_id == AV_CODEC_ID_PRORES &&
1189  avio_wl32(dyn_cp, par->codec_tag);
1190  } else if (extradata_size && par->codec_id != AV_CODEC_ID_TTA)
1191  avio_write(dyn_cp, extradata, extradata_size);
1192  }
1193 
1194  return 0;
1195 }
1196 
1198  AVCodecParameters *par,
1199  const uint8_t *extradata, int extradata_size,
1200  int native_id, int qt_id,
1201  uint8_t **codecpriv, int *codecpriv_size,
1202  unsigned *max_payload_size)
1203 {
1204  MatroskaMuxContext av_unused *const mkv = s->priv_data;
1205  unsigned size_to_reserve = 0;
1206  int ret;
1207 
1208  if (native_id) {
1209  ret = mkv_assemble_native_codecprivate(s, dyn_cp, par,
1210  extradata, extradata_size,
1211  &size_to_reserve);
1212  if (ret < 0)
1213  return ret;
1214 #if CONFIG_MATROSKA_MUXER
1215  } else if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
1216  if (qt_id) {
1217  if (!par->codec_tag)
1219  par->codec_id);
1221  && (!extradata_size || ff_codec_get_id(ff_codec_movvideo_tags, AV_RL32(extradata + 4)) != par->codec_id)
1222  ) {
1223  avio_wb32(dyn_cp, 0x5a + extradata_size);
1224  avio_wl32(dyn_cp, par->codec_tag);
1225  ffio_fill(dyn_cp, 0, 0x5a - 8);
1226  }
1227  avio_write(dyn_cp, extradata, extradata_size);
1228  } else {
1230  av_log(s, AV_LOG_WARNING, "codec %s is not supported by this format\n",
1231  avcodec_get_name(par->codec_id));
1232 
1233  if (!par->codec_tag)
1235  par->codec_id);
1236  if (!par->codec_tag && par->codec_id != AV_CODEC_ID_RAWVIDEO) {
1237  av_log(s, AV_LOG_ERROR, "No bmp codec tag found for codec %s\n",
1238  avcodec_get_name(par->codec_id));
1239  return AVERROR(EINVAL);
1240  }
1241 
1242  /* If vfw extradata updates are supported, this will have
1243  * to be updated to pass extradata(_size) explicitly. */
1244  ff_put_bmp_header(dyn_cp, par, 0, 0, mkv->flipped_raw_rgb);
1245  }
1246  } else if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
1247  unsigned int tag;
1249  if (!tag) {
1250  av_log(s, AV_LOG_ERROR, "No wav codec tag found for codec %s\n",
1251  avcodec_get_name(par->codec_id));
1252  return AVERROR(EINVAL);
1253  }
1254  if (!par->codec_tag)
1255  par->codec_tag = tag;
1256 
1257  /* Same comment as for ff_put_bmp_header applies here. */
1259  if (ret < 0)
1260  return ret;
1261 #endif
1262  }
1263 
1264  *codecpriv_size = avio_get_dyn_buf(dyn_cp, codecpriv);
1265  if (dyn_cp->error < 0)
1266  return dyn_cp->error;
1267  *max_payload_size = *codecpriv_size + size_to_reserve;
1268 
1269  return 0;
1270 }
1271 
1272 static void mkv_put_codecprivate(AVIOContext *pb, unsigned max_payload_size,
1273  const uint8_t *codecpriv, unsigned codecpriv_size)
1274 {
1275  unsigned total_codecpriv_size = 0, total_size;
1276 
1277  av_assert1(codecpriv_size <= max_payload_size);
1278 
1279  if (!max_payload_size)
1280  return;
1281 
1282  total_size = 2 + ebml_length_size(max_payload_size) + max_payload_size;
1283 
1284  if (codecpriv_size) {
1285  unsigned length_size = ebml_length_size(codecpriv_size);
1286 
1287  total_codecpriv_size = 2U + length_size + codecpriv_size;
1288  if (total_codecpriv_size + 1 == total_size) {
1289  /* It is impossible to add one byte of padding via an EBML Void. */
1290  length_size++;
1291  total_codecpriv_size++;
1292  }
1294  put_ebml_length(pb, codecpriv_size, length_size);
1295  avio_write(pb, codecpriv, codecpriv_size);
1296  }
1297  if (total_codecpriv_size < total_size)
1298  put_ebml_void(pb, total_size - total_codecpriv_size);
1299 }
1300 
1302  uint8_t *side_data, int side_data_size,
1303  AVCodecParameters *par, AVIOContext *pb,
1304  mkv_track *track, unsigned alternative_size)
1305 {
1306  AVIOContext *const dyn_bc = mkv->tmp_bc;
1307  uint8_t *codecpriv;
1308  unsigned max_payload_size;
1309  int ret, codecpriv_size;
1310 
1311  ret = mkv_assemble_codecprivate(s, dyn_bc, par,
1312  side_data, side_data_size, 1, 0,
1313  &codecpriv, &codecpriv_size, &max_payload_size);
1314  if (ret < 0)
1315  goto fail;
1316  if (codecpriv_size > track->codecpriv_size && !alternative_size) {
1317  ret = AVERROR(ENOSPC);
1318  goto fail;
1319  } else if (codecpriv_size > track->codecpriv_size) {
1320  av_assert1(alternative_size < track->codecpriv_size);
1321  codecpriv_size = alternative_size;
1322  }
1323  avio_seek(pb, track->codecpriv_offset, SEEK_SET);
1325  codecpriv, codecpriv_size);
1326 
1327  if (!par->extradata_size) {
1328  ret = ff_alloc_extradata(par, side_data_size);
1329  if (ret < 0)
1330  goto fail;
1331  memcpy(par->extradata, side_data, side_data_size);
1332  }
1333 fail:
1334  ffio_reset_dyn_buf(dyn_bc);
1335  return ret;
1336 }
1337 
1338 #define MAX_VIDEO_COLOR_ELEMS 20
1339 static void mkv_write_video_color(EbmlWriter *writer, const AVStream *st,
1340  const AVCodecParameters *par)
1341 {
1342  const AVPacketSideData *side_data;
1343 
1345 
1346  if (par->color_trc != AVCOL_TRC_UNSPECIFIED &&
1347  par->color_trc < AVCOL_TRC_NB) {
1349  par->color_trc);
1350  }
1351  if (par->color_space != AVCOL_SPC_UNSPECIFIED &&
1352  par->color_space < AVCOL_SPC_NB) {
1354  par->color_space);
1355  }
1356  if (par->color_primaries != AVCOL_PRI_UNSPECIFIED &&
1357  par->color_primaries < AVCOL_PRI_NB) {
1359  par->color_primaries);
1360  }
1361  if (par->color_range != AVCOL_RANGE_UNSPECIFIED &&
1362  par->color_range < AVCOL_RANGE_NB) {
1364  }
1367  int xpos, ypos;
1368 
1369  av_chroma_location_enum_to_pos(&xpos, &ypos, par->chroma_location);
1371  (xpos >> 7) + 1);
1373  (ypos >> 7) + 1);
1374  }
1375 
1378  if (side_data) {
1379  const AVContentLightMetadata *metadata = (AVContentLightMetadata *)side_data->data;
1381  metadata->MaxCLL);
1383  metadata->MaxFALL);
1384  }
1385 
1388  if (side_data) {
1389  const AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)side_data->data;
1391  if (metadata->has_primaries) {
1393  av_q2d(metadata->display_primaries[0][0]));
1395  av_q2d(metadata->display_primaries[0][1]));
1397  av_q2d(metadata->display_primaries[1][0]));
1399  av_q2d(metadata->display_primaries[1][1]));
1401  av_q2d(metadata->display_primaries[2][0]));
1403  av_q2d(metadata->display_primaries[2][1]));
1405  av_q2d(metadata->white_point[0]));
1407  av_q2d(metadata->white_point[1]));
1408  }
1409  if (metadata->has_luminance) {
1411  av_q2d(metadata->max_luminance));
1413  av_q2d(metadata->min_luminance));
1414  }
1416  }
1417 
1419 }
1420 
1421 #define MAX_VIDEO_PROJECTION_ELEMS 6
1422 static void mkv_handle_rotation(void *logctx, const AVCodecParameters *par,
1423  double *yaw, double *roll)
1424 {
1425  const int32_t *matrix;
1426  const AVPacketSideData *side_data =
1429 
1430  if (!side_data)
1431  return;
1432 
1433  matrix = (int32_t *)side_data->data;
1434 
1435  /* Check whether this is an affine transformation */
1436  if (matrix[2] || matrix[5])
1437  goto ignore;
1438 
1439  /* This together with the checks below test whether
1440  * the upper-left 2x2 matrix is nonsingular. */
1441  if (!matrix[0] && !matrix[1])
1442  goto ignore;
1443 
1444  /* We ignore the translation part of the matrix (matrix[6] and matrix[7])
1445  * as well as any scaling, i.e. we only look at the upper left 2x2 matrix.
1446  * We only accept matrices that are an exact multiple of an orthogonal one.
1447  * Apart from the multiple, every such matrix can be obtained by
1448  * potentially flipping in the x-direction (corresponding to yaw = 180)
1449  * followed by a rotation of (say) an angle phi in the counterclockwise
1450  * direction. The upper-left 2x2 matrix then looks like this:
1451  * | (+/-)cos(phi) (-/+)sin(phi) |
1452  * scale * | |
1453  * | sin(phi) cos(phi) |
1454  * The first set of signs in the first row apply in case of no flipping,
1455  * the second set applies in case of flipping. */
1456 
1457  /* The casts to int64_t are needed because -INT32_MIN doesn't fit
1458  * in an int32_t. */
1459  if (matrix[0] == matrix[4] && -(int64_t)matrix[1] == matrix[3]) {
1460  /* No flipping case */
1461  *yaw = 0;
1462  } else if (-(int64_t)matrix[0] == matrix[4] && matrix[1] == matrix[3]) {
1463  /* Horizontal flip */
1464  *yaw = 180;
1465  } else {
1466 ignore:
1467  av_log(logctx, AV_LOG_INFO, "Ignoring display matrix indicating "
1468  "non-orthogonal transformation.\n");
1469  return;
1470  }
1471  *roll = 180 / M_PI * atan2(matrix[3], matrix[4]);
1472 
1473  /* We do not write a ProjectionType element indicating "rectangular",
1474  * because this is the default value. */
1475 }
1476 
1477 static int mkv_handle_spherical(void *logctx, EbmlWriter *writer,
1478  const AVCodecParameters *par, uint8_t private[],
1479  double *yaw, double *pitch, double *roll)
1480 {
1482  par->nb_coded_side_data,
1484  const AVSphericalMapping *spherical;
1485 
1486  if (!sd)
1487  return 0;
1488 
1489  spherical = (const AVSphericalMapping *)sd->data;
1490  if (spherical->projection != AV_SPHERICAL_EQUIRECTANGULAR &&
1492  spherical->projection != AV_SPHERICAL_CUBEMAP) {
1493  av_log(logctx, AV_LOG_WARNING, "Unknown projection type\n");
1494  return 0;
1495  }
1496 
1497  switch (spherical->projection) {
1502  AV_WB32(private, 0); // version + flags
1503  if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR) {
1504  AV_WB32(private + 4, 0);
1505  AV_WB32(private + 8, 0);
1506  AV_WB32(private + 12, 0);
1507  AV_WB32(private + 16, 0);
1508  } else {
1509  AV_WB32(private + 4, spherical->bound_top);
1510  AV_WB32(private + 8, spherical->bound_bottom);
1511  AV_WB32(private + 12, spherical->bound_left);
1512  AV_WB32(private + 16, spherical->bound_right);
1513  }
1515  private, 20);
1516  break;
1517  case AV_SPHERICAL_CUBEMAP:
1520  AV_WB32(private, 0); // version + flags
1521  AV_WB32(private + 4, 0); // layout
1522  AV_WB32(private + 8, spherical->padding);
1524  private, 12);
1525  break;
1526  default:
1527  av_assert0(0);
1528  }
1529 
1530  *yaw = (double) spherical->yaw / (1 << 16);
1531  *pitch = (double) spherical->pitch / (1 << 16);
1532  *roll = (double) spherical->roll / (1 << 16);
1533 
1534  return 1; /* Projection included */
1535 }
1536 
1537 static void mkv_write_video_projection(void *logctx, EbmlWriter *wr,
1538  const AVCodecParameters *par,
1539  uint8_t private[])
1540 {
1541  double yaw = 0, pitch = 0, roll = 0;
1542  int ret;
1543 
1545 
1546  ret = mkv_handle_spherical(logctx, wr, par, private, &yaw, &pitch, &roll);
1547  if (!ret)
1548  mkv_handle_rotation(logctx, par, &yaw, &roll);
1549 
1550  if (yaw)
1552  if (pitch)
1554  if (roll)
1556 
1558 }
1559 
1560 #define MAX_FIELD_ORDER_ELEMS 2
1561 static void mkv_write_field_order(EbmlWriter *writer, int is_webm,
1562  enum AVFieldOrder field_order)
1563 {
1564  switch (field_order) {
1565  case AV_FIELD_UNKNOWN:
1566  break;
1567  case AV_FIELD_PROGRESSIVE:
1570  break;
1571  case AV_FIELD_TT:
1572  case AV_FIELD_BB:
1573  case AV_FIELD_TB:
1574  case AV_FIELD_BT:
1577  if (!is_webm) {
1578  switch (field_order) {
1579  case AV_FIELD_TT:
1582  break;
1583  case AV_FIELD_BB:
1586  break;
1587  case AV_FIELD_TB:
1590  break;
1591  case AV_FIELD_BT:
1594  break;
1595  }
1596  }
1597  }
1598 }
1599 
1600 #define MAX_STEREO_MODE_ELEMS 1
1602  const AVCodecParameters *par,
1603  const AVStream *st, int is_webm,
1604  int *h_width, int *h_height)
1605 {
1606  const char *error_message_addendum = "";
1607  const AVDictionaryEntry *tag;
1609 
1610  /* The following macros create bitfields where the ith bit
1611  * indicates whether the MatroskaVideoStereoModeType with that value
1612  * uses double width/height or is WebM compatible. */
1613 #define FLAG(STEREOMODETYPE, BOOL) | (BOOL) << (STEREOMODETYPE)
1614 #define WDIV1(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM) \
1615  FLAG(STEREOMODETYPE, WDIV)
1616 #define WDIV2(STEREOMODETYPE, WDIV, HDIV, WEBM) \
1617  FLAG(STEREOMODETYPE, WDIV)
1618  // The zero in the following line consumes the first '|'.
1619  const unsigned width_bitfield = 0 STEREOMODE_STEREO3D_MAPPING(WDIV1, WDIV2);
1620 
1621 #define HDIV1(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM) \
1622  FLAG(STEREOMODETYPE, HDIV)
1623 #define HDIV2(STEREOMODETYPE, WDIV, HDIV, WEBM) \
1624  FLAG(STEREOMODETYPE, HDIV)
1625  const unsigned height_bitfield = 0 STEREOMODE_STEREO3D_MAPPING(HDIV1, HDIV2);
1626 
1627 #define WEBM1(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM) \
1628  FLAG(STEREOMODETYPE, WEBM)
1629 #define WEBM2(STEREOMODETYPE, WDIV, HDIV, WEBM) \
1630  FLAG(STEREOMODETYPE, WEBM)
1631  const unsigned webm_bitfield = 0 STEREOMODE_STEREO3D_MAPPING(WEBM1, WEBM2);
1632 
1633  *h_width = 1;
1634  *h_height = 1;
1635 
1636  if ((tag = av_dict_get(st->metadata, "stereo_mode", NULL, 0)) ||
1637  (tag = av_dict_get( s->metadata, "stereo_mode", NULL, 0))) {
1638 
1639  for (int i = 0; i < MATROSKA_VIDEO_STEREOMODE_TYPE_NB; i++)
1640  if (!strcmp(tag->value, ff_matroska_video_stereo_mode[i])){
1641  format = i;
1642  break;
1643  }
1645  long stereo_mode = strtol(tag->value, NULL, 0);
1646  if ((unsigned long)stereo_mode >= MATROSKA_VIDEO_STEREOMODE_TYPE_NB)
1647  goto fail;
1648  format = stereo_mode;
1649  }
1650  } else {
1651  const AVPacketSideData *sd;
1652  const AVStereo3D *stereo;
1653  /* The following macro presumes all MATROSKA_VIDEO_STEREOMODE_TYPE_*
1654  * values to be in the range 0..254. */
1655 #define STEREOMODE(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM) \
1656  [(STEREO3DTYPE)][!!((FLAGS) & AV_STEREO3D_FLAG_INVERT)] = (STEREOMODETYPE) + 1,
1657 #define NOTHING(STEREOMODETYPE, WDIV, HDIV, WEBM)
1658  static const unsigned char conversion_table[][2] = {
1660  };
1661  int fmt;
1662 
1665  if (!sd)
1666  return 0;
1667 
1668  stereo = (const AVStereo3D*)sd->data;
1669 
1670  /* A garbage AVStereo3D or something with no Matroska analogon. */
1671  if ((unsigned)stereo->type >= FF_ARRAY_ELEMS(conversion_table))
1672  return 0;
1673 
1674  fmt = conversion_table[stereo->type][!!(stereo->flags & AV_STEREO3D_FLAG_INVERT)];
1675  /* Format with no Matroska analogon; ignore it */
1676  if (!fmt)
1677  return 0;
1678  format = fmt - 1;
1679  }
1680 
1681  // if webm, do not write unsupported modes
1682  if (is_webm && !(webm_bitfield >> format)) {
1683  error_message_addendum = " for WebM";
1684  goto fail;
1685  }
1686 
1687  *h_width = 1 << ((width_bitfield >> format) & 1);
1688  *h_height = 1 << ((height_bitfield >> format) & 1);
1689 
1690  // write StereoMode if format is valid
1692 
1693  return 0;
1694 fail:
1696  "The specified stereo mode is not valid%s.\n",
1697  error_message_addendum);
1698  return AVERROR(EINVAL);
1699 }
1700 
1702  const AVCodecParameters *par, AVIOContext *pb,
1703  mkv_track *track, const AVStream *st)
1704 {
1705 #if CONFIG_MATROSKA_MUXER
1707  const AVPacketSideData *sd;
1708 
1709  if (IS_SEEKABLE(s->pb, mkv)) {
1711  // We can't know at this point if there will be a block with BlockAdditions, so
1712  // we either write the default value here, or a void element. Either of them will
1713  // be overwritten when finishing the track.
1715  if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
1716  // Similarly, reserve space for an eventual
1717  // HDR10+ ITU T.35 metadata BlockAdditionMapping.
1718  put_ebml_void(pb, 3 /* BlockAdditionMapping */
1719  + 4 /* BlockAddIDValue */
1720  + 4 /* BlockAddIDType */);
1721  }
1722  }
1723 
1726 
1727  if (!sd)
1728  return;
1729 
1730  dovi = (const AVDOVIDecoderConfigurationRecord *)sd->data;
1731  if (dovi->dv_profile <= 10) {
1732  ebml_master mapping;
1733  uint8_t buf[ISOM_DVCC_DVVC_SIZE];
1734  uint32_t type;
1735 
1736  uint64_t expected_size = (2 + 1 + (sizeof(DVCC_DVVC_BLOCK_TYPE_NAME) - 1))
1737  + (2 + 1 + 4) + (2 + 1 + ISOM_DVCC_DVVC_SIZE);
1738 
1739  if (dovi->dv_profile > 7) {
1741  } else {
1743  }
1744 
1745  ff_isom_put_dvcc_dvvc(s, buf, dovi);
1746 
1747  mapping = start_ebml_master(pb, MATROSKA_ID_TRACKBLKADDMAPPING, expected_size);
1748 
1751  put_ebml_binary(pb, MATROSKA_ID_BLKADDIDEXTRADATA, buf, sizeof(buf));
1752 
1753  end_ebml_master(pb, mapping);
1754  }
1755 #endif
1756 }
1757 
1759  const AVStream *st, const AVCodecParameters *par,
1760  AVIOContext *pb)
1761 {
1762  const AVDictionaryEntry *tag;
1763  int display_width_div = 1, display_height_div = 1;
1764  uint8_t color_space[4], projection_private[20];
1765  const AVPacketSideData *sd;
1768  int cropped_width = par->width, cropped_height = par->height;
1769  int ret;
1770 
1772 
1775 
1776  mkv_write_field_order(&writer, IS_WEBM(mkv), par->field_order);
1777 
1778  // check both side data and metadata for stereo information,
1779  // write the result to the bitstream if any is found
1780  ret = mkv_write_stereo_mode(s, &writer, par, st, IS_WEBM(mkv),
1781  &display_width_div,
1782  &display_height_div);
1783  if (ret < 0)
1784  return ret;
1785 
1786  if (par->format == AV_PIX_FMT_YUVA420P ||
1787  ((tag = av_dict_get(st->metadata, "alpha_mode", NULL, 0)) ||
1788  (tag = av_dict_get( s->metadata, "alpha_mode", NULL, 0))) && strtol(tag->value, NULL, 0))
1790 
1792  par->nb_coded_side_data,
1794  if (sd && sd->size == sizeof(uint32_t) * 4) {
1795  uint64_t top, bottom, left, right;
1796 
1797  top = AV_RL32(sd->data + 0);
1798  bottom = AV_RL32(sd->data + 4);
1799  left = AV_RL32(sd->data + 8);
1800  right = AV_RL32(sd->data + 12);
1801 
1802  if ((left + right) >= par->width ||
1803  (top + bottom) >= par->height) {
1804  av_log(s, AV_LOG_ERROR, "Invalid cropping dimensions in stream side data\n");
1805  return AVERROR(EINVAL);
1806  }
1807 
1808  if (bottom)
1810  if (top)
1812  if (left)
1814  if (right)
1816 
1817  cropped_width -= left + right;
1818  cropped_height -= top + bottom;
1819  }
1820 
1821  // write DisplayWidth and DisplayHeight, they contain the size of
1822  // a single source view and/or the display aspect ratio
1823  if (st->sample_aspect_ratio.num) {
1824  int64_t d_width = av_rescale(cropped_width, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
1825  if (d_width > INT_MAX) {
1826  av_log(s, AV_LOG_ERROR, "Overflow in display width\n");
1827  return AVERROR(EINVAL);
1828  }
1829  if (d_width != cropped_width || display_width_div != 1 || display_height_div != 1) {
1830  if (IS_WEBM(mkv) || display_width_div != 1 || display_height_div != 1) {
1832  d_width / display_width_div);
1834  cropped_height / display_height_div);
1835  } else {
1836  AVRational display_aspect_ratio;
1837  av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
1838  cropped_width * (int64_t)st->sample_aspect_ratio.num,
1839  cropped_height * (int64_t)st->sample_aspect_ratio.den,
1840  1024 * 1024);
1842  display_aspect_ratio.num);
1844  display_aspect_ratio.den);
1847  }
1848  }
1849  } else if (display_width_div != 1 || display_height_div != 1) {
1851  cropped_width / display_width_div);
1853  cropped_height / display_height_div);
1854  } else if (!IS_WEBM(mkv))
1857 
1858  if (par->codec_id == AV_CODEC_ID_RAWVIDEO) {
1859  AV_WL32(color_space, par->codec_tag);
1861  color_space, sizeof(color_space));
1862  }
1863  mkv_write_video_color(&writer, st, par);
1864  mkv_write_video_projection(s, &writer, par, projection_private);
1865 
1866  return ebml_writer_write(&writer, pb);
1867 }
1868 
1871 {
1873  1000000000LL * duration.num / duration.den);
1874  track->default_duration_low = 1000LL * duration.num / duration.den;
1876  !!(1000LL * duration.num % duration.den);
1877 }
1878 
1880  AVStream *st, mkv_track *track, AVIOContext *pb,
1881  int is_default)
1882 {
1883  AVCodecParameters *par = st->codecpar;
1884  ebml_master subinfo, track_master;
1885  int native_id = 0;
1886  int qt_id = 0;
1887  int bit_depth;
1888  int sample_rate = par->sample_rate;
1889  int output_sample_rate = 0;
1890  int j, ret;
1891  const AVDictionaryEntry *tag;
1892 
1893  if (par->codec_type == AVMEDIA_TYPE_ATTACHMENT)
1894  return 0;
1895 
1896  track_master = start_ebml_master(pb, MATROSKA_ID_TRACKENTRY, 0);
1898  put_ebml_uid (pb, MATROSKA_ID_TRACKUID, track->uid);
1899  put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGLACING, 0); // no lacing (yet)
1900 
1901  if ((tag = av_dict_get(st->metadata, "title", NULL, 0)))
1903  tag = av_dict_get(st->metadata, "language", NULL, 0);
1905  tag && tag->value[0] ? tag->value : "und");
1906 
1907  // The default value for TRACKFLAGDEFAULT is 1, so add element
1908  // if we need to clear it.
1909  if (!is_default)
1911 
1914 
1915  if (IS_WEBM(mkv)) {
1916  const char *codec_id;
1917  if (par->codec_id != AV_CODEC_ID_WEBVTT) {
1918  for (j = 0; ff_webm_codec_tags[j].id != AV_CODEC_ID_NONE; j++) {
1919  if (ff_webm_codec_tags[j].id == par->codec_id) {
1921  native_id = 1;
1922  break;
1923  }
1924  }
1925  } else {
1927  codec_id = "D_WEBVTT/CAPTIONS";
1928  native_id = MATROSKA_TRACK_TYPE_SUBTITLE;
1929  } else if (st->disposition & AV_DISPOSITION_DESCRIPTIONS) {
1930  codec_id = "D_WEBVTT/DESCRIPTIONS";
1931  native_id = MATROSKA_TRACK_TYPE_METADATA;
1932  } else if (st->disposition & AV_DISPOSITION_METADATA) {
1933  codec_id = "D_WEBVTT/METADATA";
1934  native_id = MATROSKA_TRACK_TYPE_METADATA;
1935  } else {
1936  codec_id = "D_WEBVTT/SUBTITLES";
1937  native_id = MATROSKA_TRACK_TYPE_SUBTITLE;
1938  }
1939  }
1940 
1941  if (!native_id) {
1943  "Only VP8 or VP9 or AV1 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM.\n");
1944  return AVERROR(EINVAL);
1945  }
1946 
1948  } else {
1960 
1961  // look for a codec ID string specific to mkv to use,
1962  // if none are found, use AVI codes
1963  if (par->codec_id == AV_CODEC_ID_FFV1) {
1964  /* FFV1 is actually supported natively in Matroska,
1965  * yet we use the VfW way to mux it for compatibility
1966  * with old demuxers. (FIXME: Are they really important?) */
1967  } else if (par->codec_id != AV_CODEC_ID_RAWVIDEO || par->codec_tag) {
1968  for (j = 0; ff_mkv_codec_tags[j].id != AV_CODEC_ID_NONE; j++) {
1969  if (ff_mkv_codec_tags[j].id == par->codec_id) {
1971  native_id = 1;
1972  break;
1973  }
1974  }
1975  } else {
1976  if (mkv->allow_raw_vfw) {
1977  native_id = 0;
1978  } else {
1979  av_log(s, AV_LOG_ERROR, "Raw RGB is not supported Natively in Matroska, you can use AVI or NUT or\n"
1980  "If you would like to store it anyway using VFW mode, enable allow_raw_vfw (-allow_raw_vfw 1)\n");
1981  return AVERROR(EINVAL);
1982  }
1983  }
1984  }
1985 
1986  switch (par->codec_type) {
1987  AVRational frame_rate;
1988  int audio_frame_samples;
1989 
1990  case AVMEDIA_TYPE_VIDEO:
1991  mkv->have_video = 1;
1993 
1994  frame_rate = (AVRational){ 0, 1 };
1995  if (st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0)
1996  frame_rate = st->avg_frame_rate;
1997  else if (st->r_frame_rate.num > 0 && st->r_frame_rate.den > 0)
1998  frame_rate = st->r_frame_rate;
1999 
2000  if (frame_rate.num > 0)
2001  mkv_write_default_duration(track, pb, av_inv_q(frame_rate));
2002 
2003  if (CONFIG_MATROSKA_MUXER && !native_id &&
2006  par->codec_id == AV_CODEC_ID_SVQ1 ||
2007  par->codec_id == AV_CODEC_ID_SVQ3 ||
2008  par->codec_id == AV_CODEC_ID_CINEPAK))
2009  qt_id = 1;
2010 
2011  if (qt_id)
2012  put_ebml_string(pb, MATROSKA_ID_CODECID, "V_QUICKTIME");
2013  else if (!native_id) {
2014  // if there is no mkv-specific codec ID, use VFW mode
2015  put_ebml_string(pb, MATROSKA_ID_CODECID, "V_MS/VFW/FOURCC");
2016  track->write_dts = 1;
2018  }
2019 
2020  ret = mkv_write_track_video(s, mkv, st, par, pb);
2021  if (ret < 0)
2022  return ret;
2023 
2024  break;
2025 
2026  case AVMEDIA_TYPE_AUDIO:
2027  if (par->initial_padding) {
2028  int64_t codecdelay = av_rescale_q(par->initial_padding,
2029  (AVRational){ 1, par->sample_rate },
2030  (AVRational){ 1, 1000000000 });
2031  if (codecdelay < 0) {
2032  av_log(s, AV_LOG_ERROR, "Initial padding is invalid\n");
2033  return AVERROR(EINVAL);
2034  }
2035  put_ebml_uint(pb, MATROSKA_ID_CODECDELAY, codecdelay);
2036 
2037  track->ts_offset = av_rescale_q(par->initial_padding,
2038  (AVRational){ 1, par->sample_rate },
2039  st->time_base);
2040  ffstream(st)->lowest_ts_allowed = -track->ts_offset;
2041  }
2042  if (par->codec_id == AV_CODEC_ID_OPUS)
2044 #if CONFIG_MATROSKA_MUXER
2045  else if (par->codec_id == AV_CODEC_ID_AAC) {
2046  ret = get_aac_sample_rates(s, mkv, par->extradata, par->extradata_size,
2047  &sample_rate, &output_sample_rate);
2048  if (ret < 0)
2049  return ret;
2050  }
2051 #endif
2052 
2054 
2055  audio_frame_samples = av_get_audio_frame_duration2(par, 0);
2056  if (audio_frame_samples)
2057  mkv_write_default_duration(track, pb, (AVRational){ audio_frame_samples,
2058  par->sample_rate });
2059  if (!native_id)
2060  // no mkv-specific ID, use ACM mode
2061  put_ebml_string(pb, MATROSKA_ID_CODECID, "A_MS/ACM");
2062 
2063  subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKAUDIO, 6 + 4 * 9);
2065 
2066  track->sample_rate_offset = avio_tell(pb);
2067  put_ebml_float (pb, MATROSKA_ID_AUDIOSAMPLINGFREQ, sample_rate);
2068  if (output_sample_rate)
2069  put_ebml_float(pb, MATROSKA_ID_AUDIOOUTSAMPLINGFREQ, output_sample_rate);
2070 
2072  if (!bit_depth && par->codec_id != AV_CODEC_ID_ADPCM_G726) {
2073  if (par->bits_per_raw_sample)
2075  else
2077  }
2078  if (!bit_depth)
2080  if (bit_depth)
2082  end_ebml_master(pb, subinfo);
2083  break;
2084 
2085  case AVMEDIA_TYPE_SUBTITLE:
2086  if (!native_id) {
2087  av_log(s, AV_LOG_ERROR, "Subtitle codec %d is not supported.\n", par->codec_id);
2088  return AVERROR(ENOSYS);
2089  }
2090  if (!IS_WEBM(mkv) && st->disposition & AV_DISPOSITION_DESCRIPTIONS)
2092 
2093  if (!IS_WEBM(mkv) || par->codec_id != AV_CODEC_ID_WEBVTT)
2094  native_id = MATROSKA_TRACK_TYPE_SUBTITLE;
2095 
2096  put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, native_id);
2097  break;
2098  default:
2099  av_log(s, AV_LOG_ERROR, "Only audio, video, and subtitles are supported for Matroska.\n");
2100  return AVERROR(EINVAL);
2101  }
2102 
2103  if (!IS_WEBM(mkv))
2104  mkv_write_blockadditionmapping(s, mkv, par, pb, track, st);
2105 
2106  if (!IS_WEBM(mkv) || par->codec_id != AV_CODEC_ID_WEBVTT) {
2107  uint8_t *codecpriv;
2108  int codecpriv_size, max_payload_size;
2109  track->codecpriv_offset = avio_tell(pb);
2110  ret = mkv_assemble_codecprivate(s, mkv->tmp_bc, par,
2111  par->extradata, par->extradata_size,
2112  native_id, qt_id,
2113  &codecpriv, &codecpriv_size, &max_payload_size);
2114  if (ret < 0)
2115  goto fail;
2116  mkv_put_codecprivate(pb, max_payload_size, codecpriv, codecpriv_size);
2117  track->codecpriv_size = max_payload_size;
2118  }
2119 
2120  end_ebml_master(pb, track_master);
2121  ret = 0;
2122 fail:
2123  ffio_reset_dyn_buf(mkv->tmp_bc);
2124 
2125  return ret;
2126 }
2127 
2129 {
2130  MatroskaMuxContext *mkv = s->priv_data;
2131  AVIOContext *pb = s->pb;
2132  int video_default_idx = -1, audio_default_idx = -1, subtitle_default_idx = -1;
2133  int i, ret;
2134 
2135  if (mkv->nb_attachments == s->nb_streams)
2136  return 0;
2137 
2138  ret = start_ebml_master_crc32(&mkv->track.bc, mkv);
2139  if (ret < 0)
2140  return ret;
2141 
2142  if (mkv->default_mode != DEFAULT_MODE_PASSTHROUGH) {
2143  int video_idx = -1, audio_idx = -1, subtitle_idx = -1;
2144 
2145  for (i = s->nb_streams - 1; i >= 0; i--) {
2146  AVStream *st = s->streams[i];
2147 
2148  switch (st->codecpar->codec_type) {
2149 #define CASE(type, variable) \
2150  case AVMEDIA_TYPE_ ## type: \
2151  variable ## _idx = i; \
2152  if (st->disposition & AV_DISPOSITION_DEFAULT) \
2153  variable ## _default_idx = i; \
2154  break;
2155  CASE(VIDEO, video)
2156  CASE(AUDIO, audio)
2157  CASE(SUBTITLE, subtitle)
2158 #undef CASE
2159  }
2160  }
2161 
2162  video_default_idx = FFMAX(video_default_idx, video_idx);
2163  audio_default_idx = FFMAX(audio_default_idx, audio_idx);
2165  subtitle_default_idx = FFMAX(subtitle_default_idx, subtitle_idx);
2166  }
2167  for (i = 0; i < s->nb_streams; i++) {
2168  AVStream *st = s->streams[i];
2169  int is_default = st->disposition & AV_DISPOSITION_DEFAULT ||
2170  i == video_default_idx || i == audio_default_idx ||
2171  i == subtitle_default_idx;
2172  ret = mkv_write_track(s, mkv, st, &mkv->tracks[i],
2173  mkv->track.bc, is_default);
2174  if (ret < 0)
2175  return ret;
2176  }
2177 
2178  return end_ebml_master_crc32_tentatively(pb, &mkv->track, mkv,
2180 }
2181 
2183 {
2184  EBML_WRITER(4);
2185  uint8_t *key = av_strdup(t->key);
2186  uint8_t *p = key;
2187  const uint8_t *lang = NULL;
2188  int ret;
2189 
2190  if (!key)
2191  return AVERROR(ENOMEM);
2192 
2193  if ((p = strrchr(p, '-')) &&
2194  (lang = ff_convert_lang_to(p + 1, AV_LANG_ISO639_2_BIBL)))
2195  *p = 0;
2196 
2197  p = key;
2198  while (*p) {
2199  if (*p == ' ')
2200  *p = '_';
2201  else if (*p >= 'a' && *p <= 'z')
2202  *p -= 'a' - 'A';
2203  p++;
2204  }
2205 
2208  if (lang)
2211  ret = ebml_writer_write(&writer, pb);
2212 
2213  av_freep(&key);
2214  return ret;
2215 }
2216 
2218  uint32_t elementid, uint64_t uid)
2219 {
2221  4 + 1 + 8);
2222  if (elementid)
2223  put_ebml_uid(pb, elementid, uid);
2224  end_ebml_master(pb, targets);
2225 }
2226 
2227 static int mkv_check_tag_name(const char *name, uint32_t elementid)
2228 {
2229  return av_strcasecmp(name, "title") &&
2230  av_strcasecmp(name, "stereo_mode") &&
2231  av_strcasecmp(name, "creation_time") &&
2232  av_strcasecmp(name, "encoding_tool") &&
2233  av_strcasecmp(name, "duration") &&
2234  (elementid != MATROSKA_ID_TAGTARGETS_TRACKUID ||
2235  av_strcasecmp(name, "language")) &&
2236  (elementid != MATROSKA_ID_TAGTARGETS_ATTACHUID ||
2237  (av_strcasecmp(name, "filename") &&
2238  av_strcasecmp(name, "mimetype")));
2239 }
2240 
2242  AVIOContext **pb, unsigned reserved_size,
2243  uint32_t elementid, uint64_t uid)
2244 {
2245  const AVDictionaryEntry *t = NULL;
2246  AVIOContext *const tmp_bc = mkv->tmp_bc;
2247  uint8_t *buf;
2248  int ret = 0, size, tag_written = 0;
2249 
2250  mkv_write_tag_targets(mkv, tmp_bc, elementid, uid);
2251 
2252  while ((t = av_dict_iterate(m, t))) {
2253  if (mkv_check_tag_name(t->key, elementid)) {
2254  ret = mkv_write_simpletag(tmp_bc, t);
2255  if (ret < 0)
2256  goto end;
2257  tag_written = 1;
2258  }
2259  }
2260  if (reserved_size)
2261  put_ebml_void(tmp_bc, reserved_size);
2262  else if (!tag_written)
2263  goto end;
2264 
2265  size = avio_get_dyn_buf(tmp_bc, &buf);
2266  if (tmp_bc->error) {
2267  ret = tmp_bc->error;
2268  goto end;
2269  }
2270  if (!*pb) {
2271  ret = start_ebml_master_crc32(pb, mkv);
2272  if (ret < 0)
2273  goto end;
2274  }
2275  put_ebml_binary(*pb, MATROSKA_ID_TAG, buf, size);
2276 
2277 end:
2278  ffio_reset_dyn_buf(tmp_bc);
2279  return ret;
2280 }
2281 
2283 {
2284  MatroskaMuxContext *mkv = s->priv_data;
2285  int i, ret, seekable = IS_SEEKABLE(s->pb, mkv);
2286 
2287  mkv->wrote_tags = 1;
2288 
2290 
2291  ret = mkv_write_tag(mkv, s->metadata, &mkv->tags.bc, 0, 0, 0);
2292  if (ret < 0)
2293  return ret;
2294 
2295  for (i = 0; i < s->nb_streams; i++) {
2296  const AVStream *st = s->streams[i];
2297  mkv_track *track = &mkv->tracks[i];
2298 
2300  continue;
2301 
2302  ret = mkv_write_tag(mkv, st->metadata, &mkv->tags.bc,
2303  seekable ? DURATION_SIMPLETAG_SIZE : 0,
2305  if (ret < 0)
2306  return ret;
2307  if (seekable)
2309  }
2310 
2311  if (mkv->nb_attachments && !IS_WEBM(mkv)) {
2312  for (i = 0; i < s->nb_streams; i++) {
2313  const mkv_track *track = &mkv->tracks[i];
2314  const AVStream *st = s->streams[i];
2315 
2317  continue;
2318 
2319  ret = mkv_write_tag(mkv, st->metadata, &mkv->tags.bc, 0,
2321  if (ret < 0)
2322  return ret;
2323  }
2324  }
2325 
2326  if (mkv->tags.bc) {
2327  return end_ebml_master_crc32_tentatively(s->pb, &mkv->tags, mkv,
2329  }
2330  return 0;
2331 }
2332 
2334 {
2335  for (unsigned i = 0; i < s->nb_chapters; i++) {
2336  if (!s->chapters[i]->id)
2337  return 1;
2338  for (unsigned j = 0; j < i; j++)
2339  if (s->chapters[j]->id == s->chapters[i]->id)
2340  return 1;
2341  }
2342  return 0;
2343 }
2344 
2346 {
2347  MatroskaMuxContext *mkv = s->priv_data;
2348  AVIOContext *dyn_cp = NULL, *dyn_tags = NULL, **tags, *pb = s->pb;
2349  ebml_master editionentry;
2350  AVRational scale = {1, 1E9};
2351  int ret, create_new_ids;
2352 
2353  if (!s->nb_chapters || mkv->wrote_chapters)
2354  return 0;
2355 
2356  ret = start_ebml_master_crc32(&dyn_cp, mkv);
2357  if (ret < 0)
2358  return ret;
2359 
2360  editionentry = start_ebml_master(dyn_cp, MATROSKA_ID_EDITIONENTRY, 0);
2361  if (!IS_WEBM(mkv)) {
2363  /* If mkv_write_tags() has already been called, then any tags
2364  * corresponding to chapters will be put into a new Tags element. */
2365  tags = mkv->wrote_tags ? &dyn_tags : &mkv->tags.bc;
2366  } else
2367  tags = NULL;
2368 
2369  create_new_ids = mkv_new_chapter_ids_needed(s);
2370 
2371  for (unsigned i = 0; i < s->nb_chapters; i++) {
2372  AVChapter *const c = s->chapters[i];
2373  int64_t chapterstart = av_rescale_q(c->start, c->time_base, scale);
2374  int64_t chapterend = av_rescale_q(c->end, c->time_base, scale);
2375  const AVDictionaryEntry *t;
2376  uint64_t uid = create_new_ids ? i + 1ULL : c->id;
2377  EBML_WRITER(7);
2378 
2379  if (chapterstart < 0 || chapterstart > chapterend || chapterend < 0) {
2381  "Invalid chapter start (%"PRId64") or end (%"PRId64").\n",
2382  chapterstart, chapterend);
2384  goto fail;
2385  }
2386 
2389  ebml_writer_add_uint(&writer, MATROSKA_ID_CHAPTERTIMESTART, chapterstart);
2390  ebml_writer_add_uint(&writer, MATROSKA_ID_CHAPTERTIMEEND, chapterend);
2391  if ((t = av_dict_get(c->metadata, "title", NULL, 0))) {
2394  ebml_writer_add_string(&writer, MATROSKA_ID_CHAPLANG , "und");
2395  }
2396  ret = ebml_writer_write(&writer, dyn_cp);
2397  if (ret < 0)
2398  goto fail;
2399 
2400  if (tags) {
2402 
2403  ret = mkv_write_tag(mkv, c->metadata, tags, 0,
2405  if (ret < 0)
2406  goto fail;
2407  }
2408  }
2409  end_ebml_master(dyn_cp, editionentry);
2410  mkv->wrote_chapters = 1;
2411 
2412  ret = end_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CHAPTERS, 0, 0, 1);
2413  if (ret < 0)
2414  goto fail;
2415  if (dyn_tags)
2416  return end_ebml_master_crc32(pb, &dyn_tags, mkv,
2417  MATROSKA_ID_TAGS, 0, 0, 1);
2418  return 0;
2419 
2420 fail:
2421  if (tags) {
2422  /* tags == &mkv->tags.bc can only happen if mkv->tags.bc was
2423  * initially NULL, so we never free older tags. */
2424  ffio_free_dyn_buf(tags);
2425  }
2426  ffio_free_dyn_buf(&dyn_cp);
2427  return ret;
2428 }
2429 
2430 static const char *get_mimetype(const AVStream *st)
2431 {
2432  const AVDictionaryEntry *t;
2433 
2434  if (t = av_dict_get(st->metadata, "mimetype", NULL, 0))
2435  return t->value;
2436  if (st->codecpar->codec_id != AV_CODEC_ID_NONE) {
2438  if (desc && desc->mime_types) {
2439  return desc->mime_types[0];
2440  } else if (st->codecpar->codec_id == AV_CODEC_ID_TEXT)
2441  return "text/plain";
2442  }
2443 
2444  return NULL;
2445 }
2446 
2448 {
2449  MatroskaMuxContext *mkv = s->priv_data;
2450  AVIOContext *dyn_cp = NULL, *pb = s->pb;
2451  int i, ret;
2452 
2453  if (!mkv->nb_attachments)
2454  return 0;
2455 
2456  ret = start_ebml_master_crc32(&dyn_cp, mkv);
2457  if (ret < 0)
2458  return ret;
2459 
2460  for (i = 0; i < s->nb_streams; i++) {
2461  const AVStream *st = s->streams[i];
2462  mkv_track *track = &mkv->tracks[i];
2463  EBML_WRITER(6);
2464  const AVDictionaryEntry *t;
2465  const char *mimetype;
2466 
2468  continue;
2469 
2471 
2472  if (t = av_dict_get(st->metadata, "title", NULL, 0))
2474  if (!(t = av_dict_get(st->metadata, "filename", NULL, 0))) {
2475  av_log(s, AV_LOG_ERROR, "Attachment stream %d has no filename tag.\n", i);
2476  ffio_free_dyn_buf(&dyn_cp);
2477  return AVERROR(EINVAL);
2478  }
2480 
2481  mimetype = get_mimetype(st);
2482  av_assert0(mimetype);
2486  ebml_writer_add_uid(&writer, MATROSKA_ID_FILEUID, track->uid);
2487  ret = ebml_writer_write(&writer, dyn_cp);
2488  if (ret < 0) {
2489  ffio_free_dyn_buf(&dyn_cp);
2490  return ret;
2491  }
2492  }
2493  return end_ebml_master_crc32(pb, &dyn_cp, mkv,
2494  MATROSKA_ID_ATTACHMENTS, 0, 0, 1);
2495 }
2496 
2498 {
2499  const AVDictionaryEntry *duration = av_dict_get(s->metadata, "DURATION",
2500  NULL, 0);
2501  int64_t max = 0;
2502  int64_t us;
2503 
2504  if (duration && (av_parse_time(&us, duration->value, 1) == 0) && us > 0) {
2505  av_log(s, AV_LOG_DEBUG, "get_metadata_duration found duration in context metadata: %" PRId64 "\n", us);
2506  return us;
2507  }
2508 
2509  for (unsigned i = 0; i < s->nb_streams; i++) {
2510  int64_t us;
2511  duration = av_dict_get(s->streams[i]->metadata, "DURATION", NULL, 0);
2512 
2513  if (duration && (av_parse_time(&us, duration->value, 1) == 0))
2514  max = FFMAX(max, us);
2515  }
2516 
2517  av_log(s, AV_LOG_DEBUG, "get_metadata_duration returned: %" PRId64 "\n", max);
2518  return max;
2519 }
2520 
2522  const char *doctype, int version)
2523 {
2524  EBML_WRITER(8);
2530  ebml_writer_add_string(&writer, EBML_ID_DOCTYPE, doctype);
2533  /* The size is bounded, so no need to check this. */
2534  ebml_writer_write(&writer, pb);
2535 }
2536 
2538 {
2539  MatroskaMuxContext *mkv = s->priv_data;
2540  const AVDictionaryEntry *tag;
2541  int64_t creation_time;
2542  AVIOContext *pb;
2543  int ret = start_ebml_master_crc32(&mkv->info.bc, mkv);
2544  if (ret < 0)
2545  return ret;
2546  pb = mkv->info.bc;
2547 
2549  if ((tag = av_dict_get(s->metadata, "title", NULL, 0)))
2550  put_ebml_string(pb, MATROSKA_ID_TITLE, tag->value);
2551  if (!(s->flags & AVFMT_FLAG_BITEXACT)) {
2553  if ((tag = av_dict_get(s->metadata, "encoding_tool", NULL, 0)))
2555  else
2557 
2558  if (!IS_WEBM(mkv))
2560  } else {
2561  const char *ident = "Lavf";
2564  }
2565 
2566  if (ff_parse_creation_time_metadata(s, &creation_time, 0) > 0) {
2567  // Adjust time so it's relative to 2001-01-01 and convert to nanoseconds.
2568  int64_t date_utc = (creation_time - 978307200000000LL) * 1000;
2569  uint8_t date_utc_buf[8];
2570  AV_WB64(date_utc_buf, date_utc);
2571  put_ebml_binary(pb, MATROSKA_ID_DATEUTC, date_utc_buf, 8);
2572  }
2573 
2574  // reserve space for the duration
2575  mkv->duration = 0;
2576  mkv->duration_offset = avio_tell(pb);
2577  if (!mkv->is_live) {
2578  int64_t metadata_duration = get_metadata_duration(s);
2579 
2580  if (s->duration > 0) {
2581  int64_t scaledDuration = av_rescale(s->duration, 1000, AV_TIME_BASE);
2582  put_ebml_float(pb, MATROSKA_ID_DURATION, scaledDuration);
2583  av_log(s, AV_LOG_DEBUG, "Write early duration from recording time = %" PRIu64 "\n", scaledDuration);
2584  } else if (metadata_duration > 0) {
2585  int64_t scaledDuration = av_rescale(metadata_duration, 1000, AV_TIME_BASE);
2586  put_ebml_float(pb, MATROSKA_ID_DURATION, scaledDuration);
2587  av_log(s, AV_LOG_DEBUG, "Write early duration from metadata = %" PRIu64 "\n", scaledDuration);
2588  } else if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
2589  put_ebml_void(pb, 11); // assumes double-precision float to be written
2590  }
2591  }
2592  return end_ebml_master_crc32_tentatively(s->pb, &mkv->info,
2593  mkv, MATROSKA_ID_INFO);
2594 }
2595 
2597 {
2598  MatroskaMuxContext *mkv = s->priv_data;
2599  AVIOContext *pb = s->pb;
2600  int ret, version = 2;
2601 
2602  ret = avio_open_dyn_buf(&mkv->tmp_bc);
2603  if (ret < 0)
2604  return ret;
2605 
2606  if (!IS_WEBM(mkv) ||
2607  av_dict_get(s->metadata, "stereo_mode", NULL, 0) ||
2608  av_dict_get(s->metadata, "alpha_mode", NULL, 0))
2609  version = 4;
2610 
2611  for (unsigned i = 0; i < s->nb_streams; i++) {
2612  if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_OPUS ||
2613  av_dict_get(s->streams[i]->metadata, "stereo_mode", NULL, 0) ||
2614  av_dict_get(s->streams[i]->metadata, "alpha_mode", NULL, 0))
2615  version = 4;
2616  }
2617 
2618  ebml_write_header(pb, s->oformat->name, version);
2620  put_ebml_size_unknown(pb, 8);
2621  mkv->segment_offset = avio_tell(pb);
2622 
2623  // We write a SeekHead at the beginning to point to all other level
2624  // one elements (except Clusters).
2625  mkv_start_seekhead(mkv, pb);
2626 
2627  ret = mkv_write_info(s);
2628  if (ret < 0)
2629  return ret;
2630 
2631  ret = mkv_write_tracks(s);
2632  if (ret < 0)
2633  return ret;
2634 
2636  if (ret < 0)
2637  return ret;
2638 
2639  if (!IS_WEBM(mkv)) {
2641  if (ret < 0)
2642  return ret;
2643  }
2644 
2645  /* Must come after mkv_write_chapters() to write chapter tags
2646  * into the same Tags element as the other tags. */
2647  ret = mkv_write_tags(s);
2648  if (ret < 0)
2649  return ret;
2650 
2651  if (!IS_SEEKABLE(pb, mkv)) {
2652  ret = mkv_write_seekhead(pb, mkv, 0, avio_tell(pb));
2653  if (ret < 0)
2654  return ret;
2655  }
2656 
2657  if (s->metadata_header_padding > 0) {
2658  if (s->metadata_header_padding == 1)
2659  s->metadata_header_padding++;
2660  put_ebml_void(pb, s->metadata_header_padding);
2661  }
2662 
2663  if (mkv->reserve_cues_space || mkv->move_cues_to_front) {
2664  if (IS_SEEKABLE(pb, mkv)) {
2665  mkv->cues_pos = avio_tell(pb);
2666  if (mkv->reserve_cues_space >= 1) {
2667  if (mkv->reserve_cues_space == 1)
2668  mkv->reserve_cues_space++;
2670  }
2671  } else
2672  mkv->reserve_cues_space = -1;
2673  }
2674 
2675  mkv->cluster_pos = -1;
2676 
2677  // start a new cluster every 5 MB or 5 sec, or 32k / 1 sec for streaming or
2678  // after 4k and on a keyframe
2679  if (IS_SEEKABLE(pb, mkv)) {
2680  if (mkv->cluster_time_limit < 0)
2681  mkv->cluster_time_limit = 5000;
2682  if (mkv->cluster_size_limit < 0)
2683  mkv->cluster_size_limit = 5 * 1024 * 1024;
2684  } else {
2685  if (mkv->cluster_time_limit < 0)
2686  mkv->cluster_time_limit = 1000;
2687  if (mkv->cluster_size_limit < 0)
2688  mkv->cluster_size_limit = 32 * 1024;
2689  }
2690 
2691  return 0;
2692 }
2693 
2694 #if CONFIG_MATROSKA_MUXER
2695 static int mkv_reformat_h2645(MatroskaMuxContext *mkv, AVIOContext *pb,
2696  const AVPacket *pkt, int *size)
2697 {
2698  int ret;
2699  if (pb) {
2701  } else {
2703  if (ret < 0)
2704  return ret;
2705  *size = ret;
2706  }
2707  return 0;
2708 }
2709 
2710 static int mkv_reformat_wavpack(MatroskaMuxContext *mkv, AVIOContext *pb,
2711  const AVPacket *pkt, int *size)
2712 {
2713  const uint8_t *src = pkt->data;
2714  int srclen = pkt->size;
2715  int offset = 0;
2716  int ret;
2717 
2718  while (srclen >= WV_HEADER_SIZE) {
2719  WvHeader header;
2720 
2722  if (ret < 0)
2723  return ret;
2724  src += WV_HEADER_SIZE;
2725  srclen -= WV_HEADER_SIZE;
2726 
2727  if (srclen < header.blocksize)
2728  return AVERROR_INVALIDDATA;
2729 
2730  offset += 4 * !!header.initial + 8 + 4 * !(header.initial && header.final);
2731  if (pb) {
2732  if (header.initial)
2733  avio_wl32(pb, header.samples);
2734  avio_wl32(pb, header.flags);
2735  avio_wl32(pb, header.crc);
2736 
2737  if (!(header.initial && header.final))
2738  avio_wl32(pb, header.blocksize);
2739 
2740  avio_write(pb, src, header.blocksize);
2741  }
2742  src += header.blocksize;
2743  srclen -= header.blocksize;
2744  offset += header.blocksize;
2745  }
2746  *size = offset;
2747 
2748  return 0;
2749 }
2750 #endif
2751 
2753  const AVPacket *pkt, int *size)
2754 {
2755  int ret = ff_av1_filter_obus(pb, pkt->data, pkt->size);
2756  if (ret < 0)
2757  return ret;
2758  *size = ret;
2759  return 0;
2760 }
2761 
2763  const AVPacket *pkt, int *size)
2764 {
2765  const uint8_t *id, *settings;
2766  size_t id_size, settings_size;
2767  unsigned total = pkt->size + 2U;
2768 
2769  if (total > INT_MAX)
2770  return AVERROR(ERANGE);
2771 
2773  &id_size);
2775  &settings_size);
2776  if (id_size > INT_MAX - total || settings_size > INT_MAX - (total += id_size))
2777  return AVERROR(ERANGE);
2778  *size = total += settings_size;
2779  if (pb) {
2780  avio_write(pb, id, id_size);
2781  avio_w8(pb, '\n');
2782  avio_write(pb, settings, settings_size);
2783  avio_w8(pb, '\n');
2784  avio_write(pb, pkt->data, pkt->size);
2785  }
2786  return 0;
2787 }
2788 
2789 static void mkv_write_blockadditional(EbmlWriter *writer, const uint8_t *buf,
2790  size_t size, uint64_t additional_id)
2791 {
2793  ebml_writer_add_uint(writer, MATROSKA_ID_BLOCKADDID, additional_id);
2795  ebml_writer_close_master(writer);
2796 }
2797 
2798 static int mkv_write_block(void *logctx, MatroskaMuxContext *mkv,
2799  AVIOContext *pb, const AVCodecParameters *par,
2800  mkv_track *track, const AVPacket *pkt,
2801  int keyframe, int64_t ts, uint64_t duration,
2802  int force_blockgroup, int64_t relative_packet_pos)
2803 {
2804  uint8_t t35_buf[6 + AV_HDR_PLUS_MAX_PAYLOAD_SIZE];
2805  uint8_t *side_data;
2806  size_t side_data_size;
2807  uint64_t additional_id;
2808  unsigned track_number = track->track_num;
2809  EBML_WRITER(12);
2810  int ret;
2811 
2812  mkv->cur_block.track = track;
2813  mkv->cur_block.pkt = pkt;
2814  mkv->cur_block.rel_ts = ts - mkv->cluster_pts;
2815  mkv->cur_block.flags = 0;
2816 
2817  /* Open a BlockGroup with a Block now; it will later be converted
2818  * to a SimpleBlock if possible. */
2820  ebml_writer_add_block(&writer, mkv);
2821 
2822  if (duration > 0 && (par->codec_type == AVMEDIA_TYPE_SUBTITLE ||
2823  /* If the packet's duration is inconsistent with the default duration,
2824  * add an explicit duration element. */
2825  track->default_duration_high > 0 &&
2826  duration != track->default_duration_high &&
2827  duration != track->default_duration_low))
2829 
2830  av_log(logctx, AV_LOG_DEBUG,
2831  "Writing block of size %d with pts %" PRId64 ", dts %" PRId64 ", "
2832  "duration %" PRId64 " at relative offset %" PRId64 " in cluster "
2833  "at offset %" PRId64 ". TrackNumber %u, keyframe %d\n",
2834  pkt->size, pkt->pts, pkt->dts, pkt->duration, relative_packet_pos,
2835  mkv->cluster_pos, track_number, keyframe != 0);
2836 
2837  side_data = av_packet_get_side_data(pkt,
2839  &side_data_size);
2840  if (side_data && side_data_size >= 10) {
2841  int64_t discard_padding = AV_RL32(side_data + 4);
2842  if (discard_padding) {
2843  discard_padding = av_rescale_q(discard_padding,
2844  (AVRational){1, par->sample_rate},
2845  (AVRational){1, 1000000000});
2846  ebml_writer_add_sint(&writer, MATROSKA_ID_DISCARDPADDING, discard_padding);
2847  }
2848  }
2849 
2851  side_data = av_packet_get_side_data(pkt,
2853  &side_data_size);
2854  if (side_data && side_data_size >= 8 &&
2855  // Only the Codec-specific BlockMore (id == 1) is currently supported.
2856  (additional_id = AV_RB64(side_data)) == MATROSKA_BLOCK_ADD_ID_TYPE_OPAQUE) {
2857  mkv_write_blockadditional(&writer, side_data + 8, side_data_size - 8,
2858  additional_id);
2859  track->max_blockaddid = FFMAX(track->max_blockaddid, additional_id);
2860  }
2861 
2862  if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
2863  side_data = av_packet_get_side_data(pkt,
2865  &side_data_size);
2866  if (side_data && side_data_size) {
2867  uint8_t *payload = t35_buf;
2868  size_t payload_size = sizeof(t35_buf) - 6;
2869 
2870  bytestream_put_byte(&payload, ITU_T_T35_COUNTRY_CODE_US);
2871  bytestream_put_be16(&payload, ITU_T_T35_PROVIDER_CODE_SMTPE);
2872  bytestream_put_be16(&payload, 0x01); // provider_oriented_code
2873  bytestream_put_byte(&payload, 0x04); // application_identifier
2874 
2875  ret = av_dynamic_hdr_plus_to_t35((AVDynamicHDRPlus *)side_data, &payload,
2876  &payload_size);
2877  if (ret < 0)
2878  return ret;
2879 
2880  mkv_write_blockadditional(&writer, t35_buf, payload_size + 6,
2882  track->max_blockaddid = FFMAX(track->max_blockaddid,
2884  }
2885  }
2886 
2888 
2889  if (!force_blockgroup && writer.nb_elements == 2) {
2890  /* Nothing except the BlockGroup + Block. Can use a SimpleBlock. */
2891  writer.elements++; // Skip the BlockGroup.
2892  writer.nb_elements--;
2893  av_assert2(writer.elements[0].id == MATROSKA_ID_BLOCK);
2894  writer.elements[0].id = MATROSKA_ID_SIMPLEBLOCK;
2895  if (keyframe)
2896  mkv->cur_block.flags |= 1 << 7;
2897  } else if (!keyframe)
2899  track->last_timestamp - ts);
2900 
2901  return ebml_writer_write(&writer, pb);
2902 }
2903 
2905 {
2906  MatroskaMuxContext *mkv = s->priv_data;
2907  int ret;
2908 
2909  if (!mkv->have_video) {
2910  for (unsigned i = 0; i < s->nb_streams; i++)
2911  mkv->tracks[i].has_cue = 0;
2912  }
2913  mkv->cluster_pos = -1;
2914  ret = end_ebml_master_crc32(s->pb, &mkv->cluster_bc, mkv,
2915  MATROSKA_ID_CLUSTER, 0, 1, 0);
2916  if (ret < 0)
2917  return ret;
2918 
2920  return 0;
2921 }
2922 
2924 {
2925  MatroskaMuxContext *mkv = s->priv_data;
2926  mkv_track *track = &mkv->tracks[pkt->stream_index];
2927  AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar;
2928  uint8_t *side_data;
2929  size_t side_data_size;
2930  int ret;
2931 
2933  &side_data_size);
2934 
2935  switch (par->codec_id) {
2936 #if CONFIG_MATROSKA_MUXER
2937  case AV_CODEC_ID_AAC:
2938  if (side_data_size && mkv->track.bc) {
2939  int output_sample_rate = 0;
2940  ret = get_aac_sample_rates(s, mkv, side_data, side_data_size,
2941  &track->sample_rate, &output_sample_rate);
2942  if (ret < 0)
2943  return ret;
2944  if (!output_sample_rate)
2945  output_sample_rate = track->sample_rate; // Space is already reserved, so it's this or a void element.
2946  ret = mkv_update_codecprivate(s, mkv, side_data, side_data_size,
2947  par, mkv->track.bc, track, 0);
2948  if (ret < 0)
2949  return ret;
2950  avio_seek(mkv->track.bc, track->sample_rate_offset, SEEK_SET);
2952  put_ebml_float(mkv->track.bc, MATROSKA_ID_AUDIOOUTSAMPLINGFREQ, output_sample_rate);
2953  } else if (!par->extradata_size && !track->sample_rate) {
2954  // No extradata (codecpar or packet side data).
2955  av_log(s, AV_LOG_ERROR, "Error parsing AAC extradata, unable to determine samplerate.\n");
2956  return AVERROR(EINVAL);
2957  }
2958  break;
2959  case AV_CODEC_ID_FLAC:
2960  if (side_data_size && mkv->track.bc) {
2961  if (side_data_size != par->extradata_size) {
2962  av_log(s, AV_LOG_ERROR, "Invalid FLAC STREAMINFO metadata for output stream %d\n",
2963  pkt->stream_index);
2964  return AVERROR(EINVAL);
2965  }
2966  ret = mkv_update_codecprivate(s, mkv, side_data, side_data_size,
2967  par, mkv->track.bc, track, 0);
2968  if (ret < 0)
2969  return ret;
2970  }
2971  break;
2972 #endif
2973  // FIXME: Remove the following once libaom starts propagating proper extradata during init()
2974  // See https://bugs.chromium.org/p/aomedia/issues/detail?id=2208
2975  case AV_CODEC_ID_AV1:
2976  if (side_data_size && mkv->track.bc && !par->extradata_size) {
2977  // If the reserved space doesn't suffice, only write
2978  // the first four bytes of the av1C.
2979  ret = mkv_update_codecprivate(s, mkv, side_data, side_data_size,
2980  par, mkv->track.bc, track, 4);
2981  if (ret < 0)
2982  return ret;
2983  } else if (!par->extradata_size)
2984  return AVERROR_INVALIDDATA;
2985  break;
2986  default:
2987  if (side_data_size)
2988  av_log(s, AV_LOG_DEBUG, "Ignoring new extradata in a packet for stream %d.\n", pkt->stream_index);
2989  break;
2990  }
2991 
2992  return 0;
2993 }
2994 
2996 {
2997  MatroskaMuxContext *mkv = s->priv_data;
2998  AVIOContext *pb;
2999  AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar;
3000  mkv_track *track = &mkv->tracks[pkt->stream_index];
3001  int is_sub = par->codec_type == AVMEDIA_TYPE_SUBTITLE;
3002  /* All subtitle blocks are considered to be keyframes. */
3003  int keyframe = is_sub || !!(pkt->flags & AV_PKT_FLAG_KEY);
3005  int64_t cue_duration = is_sub ? duration : 0;
3006  int ret;
3007  int64_t ts = track->write_dts ? pkt->dts : pkt->pts;
3008  int64_t relative_packet_pos;
3009 
3010  if (ts == AV_NOPTS_VALUE) {
3011  av_log(s, AV_LOG_ERROR, "Can't write packet with unknown timestamp\n");
3012  return AVERROR(EINVAL);
3013  }
3014  ts += track->ts_offset;
3015 
3016  if (mkv->cluster_pos != -1) {
3017  int64_t cluster_time = ts - mkv->cluster_pts;
3018  if ((int16_t)cluster_time != cluster_time) {
3019  ret = mkv_end_cluster(s);
3020  if (ret < 0)
3021  return ret;
3022  av_log(s, AV_LOG_WARNING, "Starting new cluster due to timestamp\n");
3023  }
3024  }
3025 
3026  if (mkv->cluster_pos == -1) {
3027  ret = start_ebml_master_crc32(&mkv->cluster_bc, mkv);
3028  if (ret < 0)
3029  return ret;
3030  mkv->cluster_bc->direct = 1;
3031  mkv->cluster_pos = avio_tell(s->pb);
3033  mkv->cluster_pts = FFMAX(0, ts);
3035  "Starting new cluster with timestamp "
3036  "%" PRId64 " at offset %" PRId64 " bytes\n",
3037  mkv->cluster_pts, mkv->cluster_pos);
3038  }
3039  pb = mkv->cluster_bc;
3040 
3041  relative_packet_pos = avio_tell(pb);
3042 
3043  /* The WebM spec requires WebVTT to be muxed in BlockGroups;
3044  * so we force it even for packets without duration. */
3045  ret = mkv_write_block(s, mkv, pb, par, track, pkt,
3046  keyframe, ts, duration,
3047  par->codec_id == AV_CODEC_ID_WEBVTT,
3048  relative_packet_pos);
3049  if (ret < 0)
3050  return ret;
3051  if (keyframe && IS_SEEKABLE(s->pb, mkv) &&
3052  (par->codec_type == AVMEDIA_TYPE_VIDEO ||
3054  !mkv->have_video && !track->has_cue)) {
3055  ret = mkv_add_cuepoint(mkv, pkt->stream_index, ts,
3056  mkv->cluster_pos, relative_packet_pos,
3057  cue_duration);
3058  if (ret < 0)
3059  return ret;
3060  track->has_cue = 1;
3061  }
3062 
3063  track->last_timestamp = ts;
3064  mkv->duration = FFMAX(mkv->duration, ts + duration);
3065  track->duration = FFMAX(track->duration, ts + duration);
3066 
3067  return 0;
3068 }
3069 
3071 {
3072  MatroskaMuxContext *mkv = s->priv_data;
3073  int codec_type = s->streams[pkt->stream_index]->codecpar->codec_type;
3074  int keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY);
3075  int cluster_size;
3076  int64_t cluster_time;
3077  int ret;
3078  int start_new_cluster;
3079 
3081  if (ret < 0)
3082  return ret;
3083 
3084  if (mkv->cluster_pos != -1) {
3085  if (mkv->tracks[pkt->stream_index].write_dts)
3086  cluster_time = pkt->dts - mkv->cluster_pts;
3087  else
3088  cluster_time = pkt->pts - mkv->cluster_pts;
3089  cluster_time += mkv->tracks[pkt->stream_index].ts_offset;
3090 
3091  cluster_size = avio_tell(mkv->cluster_bc);
3092 
3093  if (mkv->is_dash && codec_type == AVMEDIA_TYPE_VIDEO) {
3094  // WebM DASH specification states that the first block of
3095  // every Cluster has to be a key frame. So for DASH video,
3096  // we only create a Cluster on seeing key frames.
3097  start_new_cluster = keyframe;
3098  } else if (mkv->is_dash && codec_type == AVMEDIA_TYPE_AUDIO &&
3099  cluster_time > mkv->cluster_time_limit) {
3100  // For DASH audio, we create a Cluster based on cluster_time_limit.
3101  start_new_cluster = 1;
3102  } else if (!mkv->is_dash &&
3103  (cluster_size > mkv->cluster_size_limit ||
3104  cluster_time > mkv->cluster_time_limit ||
3105  (codec_type == AVMEDIA_TYPE_VIDEO && keyframe &&
3106  cluster_size > 4 * 1024))) {
3107  start_new_cluster = 1;
3108  } else
3109  start_new_cluster = 0;
3110 
3111  if (start_new_cluster) {
3112  ret = mkv_end_cluster(s);
3113  if (ret < 0)
3114  return ret;
3115  }
3116  }
3117 
3118  if (mkv->cluster_pos == -1)
3119  avio_write_marker(s->pb,
3120  av_rescale_q(pkt->dts, s->streams[pkt->stream_index]->time_base, AV_TIME_BASE_Q),
3122 
3123  // check if we have an audio packet cached
3124  if (mkv->cur_audio_pkt->size > 0) {
3127  if (ret < 0) {
3129  "Could not write cached audio packet ret:%d\n", ret);
3130  return ret;
3131  }
3132  }
3133 
3134  // buffer an audio packet to ensure the packet containing the video
3135  // keyframe's timecode is contained in the same cluster for WebM
3136  if (codec_type == AVMEDIA_TYPE_AUDIO) {
3137  if (pkt->size > 0)
3139  } else
3141  return ret;
3142 }
3143 
3145 {
3146  MatroskaMuxContext *mkv = s->priv_data;
3147 
3148  if (!pkt) {
3149  if (mkv->cluster_pos != -1) {
3150  int ret = mkv_end_cluster(s);
3151  if (ret < 0)
3152  return ret;
3154  "Flushing cluster at offset %" PRIu64 " bytes\n",
3155  avio_tell(s->pb));
3156  }
3157  return 1;
3158  }
3159  return mkv_write_packet(s, pkt);
3160 }
3161 
3163 {
3164  MatroskaMuxContext *mkv = s->priv_data;
3165  AVIOContext *pb = s->pb;
3166  int64_t endpos, ret64;
3167  int ret, ret2 = 0;
3168 
3169  // check if we have an audio packet cached
3170  if (mkv->cur_audio_pkt->size > 0) {
3172  if (ret < 0) {
3174  "Could not write cached audio packet ret:%d\n", ret);
3175  return ret;
3176  }
3177  }
3178 
3179  if (mkv->cluster_pos != -1) {
3180  ret = end_ebml_master_crc32(pb, &mkv->cluster_bc, mkv,
3181  MATROSKA_ID_CLUSTER, 0, 0, 0);
3182  if (ret < 0)
3183  return ret;
3184  }
3185 
3187  if (ret < 0)
3188  return ret;
3189 
3190  if (!IS_SEEKABLE(pb, mkv))
3191  return 0;
3192 
3193  endpos = avio_tell(pb);
3194 
3195  if (mkv->cues.num_entries && mkv->reserve_cues_space >= 0) {
3196  AVIOContext *cues = NULL;
3197  uint64_t size, offset = 0;
3198  int length_size = 0;
3199 
3200 redo_cues:
3201  ret = start_ebml_master_crc32(&cues, mkv);
3202  if (ret < 0)
3203  return ret;
3204 
3205  ret = mkv_assemble_cues(s->streams, cues, mkv->tmp_bc, &mkv->cues,
3206  mkv->tracks, s->nb_streams, offset);
3207  if (ret < 0) {
3208  ffio_free_dyn_buf(&cues);
3209  return ret;
3210  }
3211 
3212  if (mkv->reserve_cues_space || mkv->move_cues_to_front) {
3213  size = avio_tell(cues);
3214  length_size = ebml_length_size(size);
3215  size += 4 + length_size;
3216  if (offset + mkv->reserve_cues_space < size) {
3217  if (mkv->move_cues_to_front) {
3218  offset = size - mkv->reserve_cues_space;
3219  ffio_reset_dyn_buf(cues);
3220  goto redo_cues;
3221  }
3223  "Insufficient space reserved for Cues: "
3224  "%d < %"PRIu64". No Cues will be output.\n",
3225  mkv->reserve_cues_space, size);
3226  ret2 = AVERROR(EINVAL);
3227  goto after_cues;
3228  } else {
3229  if (offset) {
3231  offset);
3232  if (ret < 0) {
3233  ffio_free_dyn_buf(&cues);
3234  return ret;
3235  }
3236  endpos += offset;
3237  }
3238  if ((ret64 = avio_seek(pb, mkv->cues_pos, SEEK_SET)) < 0) {
3239  ffio_free_dyn_buf(&cues);
3240  return ret64;
3241  }
3242  if (mkv->reserve_cues_space == size + 1) {
3243  /* There is no way to reserve a single byte because
3244  * the minimal size of an EBML Void element is 2
3245  * (1 byte ID, 1 byte length field). This problem
3246  * is solved by writing the Cues' length field on
3247  * one byte more than necessary. */
3248  length_size++;
3249  size++;
3250  }
3251  }
3252  }
3253  ret = end_ebml_master_crc32(pb, &cues, mkv, MATROSKA_ID_CUES,
3254  length_size, 0, 1);
3255  if (ret < 0)
3256  return ret;
3257  if (mkv->reserve_cues_space) {
3258  if (size < mkv->reserve_cues_space)
3260  } else if (!mkv->move_cues_to_front)
3261  endpos = avio_tell(pb);
3262  }
3263 
3264 after_cues:
3265  /* Lengths greater than (1ULL << 56) - 1 can't be represented
3266  * via an EBML number, so leave the unknown length field. */
3267  if (endpos - mkv->segment_offset < (1ULL << 56) - 1) {
3268  if ((ret64 = avio_seek(pb, mkv->segment_offset - 8, SEEK_SET)) < 0)
3269  return ret64;
3270  put_ebml_length(pb, endpos - mkv->segment_offset, 8);
3271  }
3272 
3273  ret = mkv_write_seekhead(pb, mkv, 1, mkv->info.pos);
3274  if (ret < 0)
3275  return ret;
3276 
3277  if (mkv->info.bc) {
3278  // update the duration
3279  av_log(s, AV_LOG_DEBUG, "end duration = %" PRIu64 "\n", mkv->duration);
3280  avio_seek(mkv->info.bc, mkv->duration_offset, SEEK_SET);
3282  ret = end_ebml_master_crc32(pb, &mkv->info.bc, mkv,
3283  MATROSKA_ID_INFO, 0, 0, 0);
3284  if (ret < 0)
3285  return ret;
3286  }
3287 
3288  if (mkv->track.bc) {
3289  // write Tracks master
3290  if (!IS_WEBM(mkv)) {
3291  AVIOContext *track_bc = mkv->track.bc;
3292 
3293  for (unsigned i = 0; i < s->nb_streams; i++) {
3294  const mkv_track *track = &mkv->tracks[i];
3295 
3296  if (!track->max_blockaddid)
3297  continue;
3298 
3299  // We reserved a single byte to write this value.
3300  av_assert0(track->max_blockaddid <= 0xFF);
3301 
3302  avio_seek(track_bc, track->blockadditionmapping_offset, SEEK_SET);
3303 
3305  track->max_blockaddid);
3307  ebml_master mapping_master = start_ebml_master(track_bc, MATROSKA_ID_TRACKBLKADDMAPPING, 8);
3312  end_ebml_master(track_bc, mapping_master);
3313  }
3314  }
3315  }
3316 
3317  avio_seek(pb, mkv->track.pos, SEEK_SET);
3318  ret = end_ebml_master_crc32(pb, &mkv->track.bc, mkv,
3319  MATROSKA_ID_TRACKS, 0, 0, 0);
3320  if (ret < 0)
3321  return ret;
3322  }
3323 
3324  // update stream durations
3325  if (mkv->tags.bc) {
3326  AVIOContext *tags_bc = mkv->tags.bc;
3327  int i;
3328  for (i = 0; i < s->nb_streams; ++i) {
3329  const AVStream *st = s->streams[i];
3330  const mkv_track *track = &mkv->tracks[i];
3331 
3332  if (track->duration_offset > 0) {
3333  double duration_sec = track->duration * av_q2d(st->time_base);
3334  char duration_string[DURATION_STRING_LENGTH + 1] = "";
3335  ebml_master simpletag;
3336 
3337  av_log(s, AV_LOG_DEBUG, "stream %d end duration = %" PRIu64 "\n", i,
3338  track->duration);
3339 
3340  avio_seek(tags_bc, track->duration_offset, SEEK_SET);
3341  simpletag = start_ebml_master(tags_bc, MATROSKA_ID_SIMPLETAG,
3342  2 + 1 + 8 + 23);
3343  put_ebml_string(tags_bc, MATROSKA_ID_TAGNAME, "DURATION");
3344 
3345  snprintf(duration_string, sizeof(duration_string), "%02d:%02d:%012.9f",
3346  (int) duration_sec / 3600, ((int) duration_sec / 60) % 60,
3347  fmod(duration_sec, 60));
3348 
3350  duration_string, DURATION_STRING_LENGTH);
3351  end_ebml_master(tags_bc, simpletag);
3352  }
3353  }
3354 
3355  avio_seek(pb, mkv->tags.pos, SEEK_SET);
3356  ret = end_ebml_master_crc32(pb, &mkv->tags.bc, mkv,
3357  MATROSKA_ID_TAGS, 0, 0, 0);
3358  if (ret < 0)
3359  return ret;
3360  }
3361 
3362  avio_seek(pb, endpos, SEEK_SET);
3363 
3364  return ret2;
3365 }
3366 
3367 static uint64_t mkv_get_uid(const mkv_track *tracks, int i, AVLFG *c)
3368 {
3369  while (1) {
3370  uint64_t uid;
3371  int k;
3372  uid = (uint64_t)av_lfg_get(c) << 32;
3373  uid |= av_lfg_get(c);
3374  if (!uid)
3375  continue;
3376  for (k = 0; k < i; k++) {
3377  if (tracks[k].uid == uid)
3378  break;
3379  }
3380  if (k == i)
3381  return uid;
3382  }
3383 }
3384 
3385 static int mkv_init(struct AVFormatContext *s)
3386 {
3387  FFFormatContext *const si = ffformatcontext(s);
3388  MatroskaMuxContext *mkv = s->priv_data;
3389  AVLFG c;
3390  unsigned nb_tracks = 0;
3391  int i;
3392 
3393  mkv->ctx = s;
3394 
3395  for (i = 0; i < s->nb_streams; i++) {
3396  if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_ATRAC3 ||
3397  s->streams[i]->codecpar->codec_id == AV_CODEC_ID_COOK ||
3398  s->streams[i]->codecpar->codec_id == AV_CODEC_ID_RA_288 ||
3399  s->streams[i]->codecpar->codec_id == AV_CODEC_ID_SIPR ||
3400  s->streams[i]->codecpar->codec_id == AV_CODEC_ID_RV10 ||
3401  s->streams[i]->codecpar->codec_id == AV_CODEC_ID_RV20 ||
3402  s->streams[i]->codecpar->codec_id == AV_CODEC_ID_RV30) {
3404  "The Matroska muxer does not yet support muxing %s\n",
3405  avcodec_get_name(s->streams[i]->codecpar->codec_id));
3406  return AVERROR_PATCHWELCOME;
3407  }
3408  }
3409 
3410  if (s->avoid_negative_ts < 0) {
3411  s->avoid_negative_ts = 1;
3412  si->avoid_negative_ts_use_pts = 1;
3413  }
3414 
3415  if (!CONFIG_MATROSKA_MUXER ||
3416  (CONFIG_WEBM_MUXER && !strcmp(s->oformat->name, "webm"))) {
3417  mkv->mode = MODE_WEBM;
3418  mkv->write_crc = 0;
3419  } else
3420  mkv->mode = MODE_MATROSKAv2;
3421 
3423 
3424  mkv->tracks = av_calloc(s->nb_streams, sizeof(*mkv->tracks));
3425  if (!mkv->tracks)
3426  return AVERROR(ENOMEM);
3427 
3428  if (!(s->flags & AVFMT_FLAG_BITEXACT)) {
3430 
3431  // Calculate the SegmentUID now in order not to waste our random seed.
3432  for (i = 0; i < 4; i++)
3433  mkv->segment_uid[i] = av_lfg_get(&c);
3434  }
3435 
3436  for (i = 0; i < s->nb_streams; i++) {
3437  AVStream *st = s->streams[i];
3438  const AVCodecParameters *const par = st->codecpar;
3439  mkv_track *track = &mkv->tracks[i];
3440 
3441  switch (par->codec_id) {
3442 #if CONFIG_MATROSKA_MUXER
3443  case AV_CODEC_ID_WAVPACK:
3444  track->reformat = mkv_reformat_wavpack;
3445  break;
3446  case AV_CODEC_ID_H264:
3447  case AV_CODEC_ID_HEVC:
3448  case AV_CODEC_ID_VVC:
3449  if (((par->codec_id == AV_CODEC_ID_H264 && par->extradata_size > 0) ||
3450  (par->codec_id == AV_CODEC_ID_HEVC && par->extradata_size > 6) ||
3451  (par->codec_id == AV_CODEC_ID_VVC && par->extradata_size >= 6)) &&
3452  (AV_RB24(par->extradata) == 1 || AV_RB32(par->extradata) == 1))
3453  track->reformat = mkv_reformat_h2645;
3454  break;
3455  case AV_CODEC_ID_PRORES:
3456  /* Matroska specification requires to remove
3457  * the first QuickTime atom. */
3458  track->offset = 8;
3459  break;
3460 #endif
3461  case AV_CODEC_ID_AV1:
3462  track->reformat = mkv_reformat_av1;
3463  break;
3464  case AV_CODEC_ID_WEBVTT:
3465  track->reformat = webm_reformat_vtt;
3466  break;
3467  }
3468 
3469  if (s->flags & AVFMT_FLAG_BITEXACT) {
3470  track->uid = i + 1;
3471  } else {
3472  track->uid = mkv_get_uid(mkv->tracks, i, &c);
3473  }
3474 
3475  // ms precision is the de-facto standard timescale for mkv files
3476  avpriv_set_pts_info(st, 64, 1, 1000);
3477 
3479  if (IS_WEBM(mkv)) {
3480  av_log(s, AV_LOG_WARNING, "Stream %d will be ignored "
3481  "as WebM doesn't support attachments.\n", i);
3482  } else if (!get_mimetype(st)) {
3483  av_log(s, AV_LOG_ERROR, "Attachment stream %d has no mimetype "
3484  "tag and it cannot be deduced from the codec id.\n", i);
3485  return AVERROR(EINVAL);
3486  }
3487  mkv->nb_attachments++;
3488  continue;
3489  }
3490 
3491  nb_tracks++;
3492  track->track_num = mkv->is_dash ? mkv->dash_track_number : nb_tracks;
3493  track->track_num_size = ebml_num_size(track->track_num);
3494  }
3495 
3496  if (mkv->is_dash && nb_tracks != 1)
3497  return AVERROR(EINVAL);
3498 
3499  return 0;
3500 }
3501 
3503  const AVPacket *pkt)
3504 {
3505  int ret = 1;
3506 
3507  if (CONFIG_MATROSKA_MUXER && st->codecpar->codec_id == AV_CODEC_ID_AAC) {
3508  if (pkt->size > 2 && (AV_RB16(pkt->data) & 0xfff0) == 0xfff0)
3509  ret = ff_stream_add_bitstream_filter(st, "aac_adtstoasc", NULL);
3510  } else if (st->codecpar->codec_id == AV_CODEC_ID_VP9) {
3511  ret = ff_stream_add_bitstream_filter(st, "vp9_superframe", NULL);
3512  } else if (CONFIG_MATROSKA_MUXER &&
3514  ret = ff_stream_add_bitstream_filter(st, "pgs_frame_merge", NULL);
3515  }
3516 
3517  return ret;
3518 }
3519 
3521  { AV_CODEC_ID_ALAC, 0XFFFFFFFF },
3522  { AV_CODEC_ID_ATRAC1, 0xFFFFFFFF },
3523  { AV_CODEC_ID_MLP, 0xFFFFFFFF },
3524  { AV_CODEC_ID_OPUS, 0xFFFFFFFF },
3525  { AV_CODEC_ID_PCM_S16BE, 0xFFFFFFFF },
3526  { AV_CODEC_ID_PCM_S24BE, 0xFFFFFFFF },
3527  { AV_CODEC_ID_PCM_S32BE, 0xFFFFFFFF },
3528  { AV_CODEC_ID_QDMC, 0xFFFFFFFF },
3529  { AV_CODEC_ID_QDM2, 0xFFFFFFFF },
3530  { AV_CODEC_ID_RA_144, 0xFFFFFFFF },
3531  { AV_CODEC_ID_TRUEHD, 0xFFFFFFFF },
3532  { AV_CODEC_ID_NONE, 0xFFFFFFFF }
3533 };
3534 
3536  { AV_CODEC_ID_DVB_SUBTITLE, 0xFFFFFFFF },
3537  { AV_CODEC_ID_DVD_SUBTITLE, 0xFFFFFFFF },
3538  { AV_CODEC_ID_HDMV_PGS_SUBTITLE, 0xFFFFFFFF },
3539  { AV_CODEC_ID_ARIB_CAPTION, 0xFFFFFFFF },
3540  { AV_CODEC_ID_NONE, 0xFFFFFFFF }
3541 };
3542 
3543 #define OFFSET(x) offsetof(MatroskaMuxContext, x)
3544 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM
3545 static const AVOption options[] = {
3546  { "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 },
3547  { "cues_to_front", "move Cues (the index) to the front by shifting data if necessary", OFFSET(move_cues_to_front), AV_OPT_TYPE_BOOL, { .i64 = 0}, 0, 1, FLAGS },
3548  { "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 },
3549  { "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 },
3550  { "dash", "create a WebM file conforming to WebM DASH specification", OFFSET(is_dash), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
3551  { "dash_track_number", "track number for the DASH stream", OFFSET(dash_track_number), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, INT_MAX, FLAGS },
3552  { "live", "write files assuming it is a live stream", OFFSET(is_live), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
3553  { "allow_raw_vfw", "allow raw VFW mode", OFFSET(allow_raw_vfw), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
3554  { "flipped_raw_rgb", "store raw RGB bitmaps in VFW mode in bottom-up mode", OFFSET(flipped_raw_rgb), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
3555  { "write_crc32", "write a CRC32 element inside every Level 1 element", OFFSET(write_crc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
3556  { "default_mode", "control 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, .unit = "default_mode" },
3557  { "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, .unit = "default_mode" },
3558  { "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, .unit = "default_mode" },
3559  { "passthrough", "use the disposition flag as-is", 0, AV_OPT_TYPE_CONST, { .i64 = DEFAULT_MODE_PASSTHROUGH }, 0, 0, FLAGS, .unit = "default_mode" },
3560  { NULL },
3561 };
3562 
3564  .class_name = "matroska/webm muxer",
3565  .item_name = av_default_item_name,
3566  .option = options,
3567  .version = LIBAVUTIL_VERSION_INT,
3568 };
3569 
3570 #if CONFIG_MATROSKA_MUXER
3571 static int mkv_query_codec(enum AVCodecID codec_id, int std_compliance)
3572 {
3573  for (int i = 0; ff_mkv_codec_tags[i].id != AV_CODEC_ID_NONE; i++)
3574  if (ff_mkv_codec_tags[i].id == codec_id)
3575  return 1;
3576 
3577  if (std_compliance < FF_COMPLIANCE_NORMAL) {
3579  // mkv theoretically supports any video/audio through VFW/ACM
3581  return 1;
3582  }
3583 
3584  return 0;
3585 }
3586 
3588  .p.name = "matroska",
3589  .p.long_name = NULL_IF_CONFIG_SMALL("Matroska"),
3590  .p.mime_type = "video/x-matroska",
3591  .p.extensions = "mkv",
3592  .priv_data_size = sizeof(MatroskaMuxContext),
3593  .p.audio_codec = CONFIG_LIBVORBIS_ENCODER ?
3595  .p.video_codec = CONFIG_LIBX264_ENCODER ?
3597  .init = mkv_init,
3598  .deinit = mkv_deinit,
3599  .write_header = mkv_write_header,
3600  .write_packet = mkv_write_flush_packet,
3601  .write_trailer = mkv_write_trailer,
3602  .p.flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS |
3604  AVFMT_TS_NONSTRICT | AVFMT_ALLOW_FLUSH,
3605 #else
3607 #endif
3608  .p.codec_tag = (const AVCodecTag* const []){
3611  },
3612  .p.subtitle_codec = AV_CODEC_ID_ASS,
3613  .query_codec = mkv_query_codec,
3614  .check_bitstream = mkv_check_bitstream,
3615  .p.priv_class = &matroska_webm_class,
3616  .flags_internal = FF_OFMT_FLAG_ALLOW_FLUSH,
3617 };
3618 #endif
3619 
3620 #if CONFIG_WEBM_MUXER
3621 static int webm_query_codec(enum AVCodecID codec_id, int std_compliance)
3622 {
3623  for (int i = 0; ff_webm_codec_tags[i].id != AV_CODEC_ID_NONE; i++)
3624  if (ff_webm_codec_tags[i].id == codec_id)
3625  return 1;
3626 
3627  return 0;
3628 }
3629 
3630 const FFOutputFormat ff_webm_muxer = {
3631  .p.name = "webm",
3632  .p.long_name = NULL_IF_CONFIG_SMALL("WebM"),
3633  .p.mime_type = "video/webm",
3634  .p.extensions = "webm",
3635  .priv_data_size = sizeof(MatroskaMuxContext),
3636  .p.audio_codec = CONFIG_LIBOPUS_ENCODER ? AV_CODEC_ID_OPUS : AV_CODEC_ID_VORBIS,
3637  .p.video_codec = CONFIG_LIBVPX_VP9_ENCODER? AV_CODEC_ID_VP9 : AV_CODEC_ID_VP8,
3638  .p.subtitle_codec = AV_CODEC_ID_WEBVTT,
3639  .init = mkv_init,
3640  .deinit = mkv_deinit,
3641  .write_header = mkv_write_header,
3642  .write_packet = mkv_write_flush_packet,
3643  .write_trailer = mkv_write_trailer,
3644  .query_codec = webm_query_codec,
3645  .check_bitstream = mkv_check_bitstream,
3646  .p.flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS |
3648  AVFMT_TS_NONSTRICT | AVFMT_ALLOW_FLUSH,
3649 #else
3651 #endif
3652  .p.priv_class = &matroska_webm_class,
3653  .flags_internal = FF_OFMT_FLAG_ALLOW_FLUSH,
3654 };
3655 #endif
3656 
3657 #if CONFIG_MATROSKA_AUDIO_MUXER
3659  .p.name = "matroska",
3660  .p.long_name = NULL_IF_CONFIG_SMALL("Matroska Audio"),
3661  .p.mime_type = "audio/x-matroska",
3662  .p.extensions = "mka",
3663  .priv_data_size = sizeof(MatroskaMuxContext),
3664  .p.audio_codec = CONFIG_LIBVORBIS_ENCODER ?
3666  .p.video_codec = AV_CODEC_ID_NONE,
3667  .init = mkv_init,
3668  .deinit = mkv_deinit,
3669  .write_header = mkv_write_header,
3670  .write_packet = mkv_write_flush_packet,
3671  .write_trailer = mkv_write_trailer,
3672  .check_bitstream = mkv_check_bitstream,
3674  .p.flags = AVFMT_GLOBALHEADER | AVFMT_TS_NONSTRICT |
3675  AVFMT_ALLOW_FLUSH,
3676 #else
3678 #endif
3679  .p.codec_tag = (const AVCodecTag* const []){
3681  },
3682  .p.priv_class = &matroska_webm_class,
3683  .flags_internal = FF_OFMT_FLAG_ALLOW_FLUSH,
3684 };
3685 #endif
MatroskaMuxContext::reserve_cues_space
int reserve_cues_space
Definition: matroskaenc.c:251
MATROSKA_ID_TAGTARGETS_ATTACHUID
#define MATROSKA_ID_TAGTARGETS_ATTACHUID
Definition: matroska.h:225
AVMasteringDisplayMetadata::has_primaries
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
Definition: mastering_display_metadata.h:62
AV_PKT_DATA_DISPLAYMATRIX
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: packet.h:105
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:430
MATROSKA_ID_VIDEODISPLAYUNIT
#define MATROSKA_ID_VIDEODISPLAYUNIT
Definition: matroska.h:125
MATROSKA_ID_CODECPRIVATE
#define MATROSKA_ID_CODECPRIVATE
Definition: matroska.h:88
MATROSKA_ID_TRACKNUMBER
#define MATROSKA_ID_TRACKNUMBER
Definition: matroska.h:77
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
EBML_BIN
@ EBML_BIN
Definition: matroskaenc.c:114
MATROSKA_ID_TRACKFLAGVISUALIMPAIRED
#define MATROSKA_ID_TRACKFLAGVISUALIMPAIRED
Definition: matroska.h:101
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
MatroskaMuxContext::is_dash
int is_dash
Definition: matroskaenc.c:257
MATROSKA_ID_CHAPSTRING
#define MATROSKA_ID_CHAPSTRING
Definition: matroska.h:266
IS_SEEKABLE
#define IS_SEEKABLE(pb, mkv)
Definition: matroskaenc.c:88
mkv_init
static int mkv_init(struct AVFormatContext *s)
Definition: matroskaenc.c:3385
MATROSKA_ID_TAGTARGETS
#define MATROSKA_ID_TAGTARGETS
Definition: matroska.h:220
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:69
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:235
LIBAVFORMAT_IDENT
#define LIBAVFORMAT_IDENT
Definition: version.h:45
entry
#define entry
Definition: aom_film_grain_template.c:66
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:314
AV_CODEC_ID_AC3
@ AV_CODEC_ID_AC3
Definition: codec_id.h:451
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:127
mkv_write_packet
static int mkv_write_packet(AVFormatContext *s, const AVPacket *pkt)
Definition: matroskaenc.c:3070
AVOutputFormat::name
const char * name
Definition: avformat.h:510
MATROSKA_ID_TITLE
#define MATROSKA_ID_TITLE
Definition: matroska.h:67
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:2428
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:301
ebml_writer_add_string
static void ebml_writer_add_string(EbmlWriter *writer, uint32_t id, const char *str)
Definition: matroskaenc.c:503
mkv_write_packet_internal
static int mkv_write_packet_internal(AVFormatContext *s, const AVPacket *pkt)
Definition: matroskaenc.c:2995
MatroskaMuxContext::allow_raw_vfw
int allow_raw_vfw
Definition: matroskaenc.c:259
ebml_writer_add_float
static void ebml_writer_add_float(EbmlWriter *writer, uint32_t id, double val)
Definition: matroskaenc.c:523
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
AVSphericalMapping::projection
enum AVSphericalProjection projection
Projection type.
Definition: spherical.h:98
AV1_SANE_SEQUENCE_HEADER_MAX_BITS
#define AV1_SANE_SEQUENCE_HEADER_MAX_BITS
Definition: av1.h:190
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:422
hevc.h
AVSphericalMapping::bound_bottom
uint32_t bound_bottom
Distance from the bottom edge.
Definition: spherical.h:182
MATROSKA_ID_VIDEOCOLORMASTERINGMETA
#define MATROSKA_ID_VIDEOCOLORMASTERINGMETA
Definition: matroska.h:149
ebml_writer_master_len
static int ebml_writer_master_len(EbmlWriter *writer, EbmlElement *elem, int remaining_elems)
Definition: matroskaenc.c:598
AVFieldOrder
AVFieldOrder
Definition: defs.h:200
MatroskaMuxContext::segment_offset
int64_t segment_offset
Definition: matroskaenc.c:222
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:228
AV_PKT_DATA_FRAME_CROPPING
@ AV_PKT_DATA_FRAME_CROPPING
The number of pixels to discard from the top/bottom/left/right border of the decoded frame to obtain ...
Definition: packet.h:340
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
EBML_ID_EBMLMAXSIZELENGTH
#define EBML_ID_EBMLMAXSIZELENGTH
Definition: matroska.h:38
ffformatcontext
static av_always_inline FFFormatContext * ffformatcontext(AVFormatContext *s)
Definition: internal.h:127
mkv_new_chapter_ids_needed
static int mkv_new_chapter_ids_needed(const AVFormatContext *s)
Definition: matroskaenc.c:2333
AVCodecParameters::color_space
enum AVColorSpace color_space
Definition: codec_par.h:169
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:781
MATROSKA_ID_TRACKFLAGTEXTDESCRIPTIONS
#define MATROSKA_ID_TRACKFLAGTEXTDESCRIPTIONS
Definition: matroska.h:102
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:56
AVFMT_VARIABLE_FPS
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:482
avcodec_get_type
enum AVMediaType avcodec_get_type(enum AVCodecID codec_id)
Get the type of the given codec.
Definition: codec_desc.c:3799
AV_FIELD_PROGRESSIVE
@ AV_FIELD_PROGRESSIVE
Definition: defs.h:202
MATROSKA_ID_VIDEOPIXELWIDTH
#define MATROSKA_ID_VIDEOPIXELWIDTH
Definition: matroska.h:119
EbmlMaster::containing_master
int containing_master
-1 if no parent exists
Definition: matroskaenc.c:129
mkv_track::duration
int64_t duration
Definition: matroskaenc.c:196
MATROSKA_ID_AUDIOSAMPLINGFREQ
#define MATROSKA_ID_AUDIOSAMPLINGFREQ
Definition: matroska.h:169
AV_PKT_DATA_MASTERING_DISPLAY_METADATA
@ AV_PKT_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata (based on SMPTE-2086:2014).
Definition: packet.h:219
MatroskaMuxContext::cluster_bc
AVIOContext * cluster_bc
Definition: matroskaenc.c:223
OPUS_SEEK_PREROLL
#define OPUS_SEEK_PREROLL
Seek preroll value for opus.
Definition: matroskaenc.c:282
matrix
Definition: vc1dsp.c:43
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
EbmlElement
Definition: matroskaenc.c:132
MODE_MATROSKAv2
#define MODE_MATROSKAv2
Definition: matroskaenc.c:83
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:215
rational.h
MATROSKA_ID_DISCARDPADDING
#define MATROSKA_ID_DISCARDPADDING
Definition: matroska.h:250
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:264
MATROSKA_VIDEO_FIELDORDER_BB
@ MATROSKA_VIDEO_FIELDORDER_BB
Definition: matroska.h:307
int64_t
long long int64_t
Definition: coverity.c:34
ebml_writer_add_uint
static void ebml_writer_add_uint(EbmlWriter *writer, uint32_t id, uint64_t val)
Definition: matroskaenc.c:538
MATROSKA_ID_DURATION
#define MATROSKA_ID_DURATION
Definition: matroska.h:66
MATROSKA_ID_VIDEOCOLORCHROMASITINGVERT
#define MATROSKA_ID_VIDEOCOLORCHROMASITINGVERT
Definition: matroska.h:141
BlockContext::pkt
const AVPacket * pkt
Definition: matroskaenc.c:121
avlanguage.h
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:207
MATROSKA_ID_VIDEOCOLORPRIMARIES
#define MATROSKA_ID_VIDEOCOLORPRIMARIES
Definition: matroska.h:145
AV_CODEC_ID_RAWVIDEO
@ AV_CODEC_ID_RAWVIDEO
Definition: codec_id.h:65
vvc.h
av_unused
#define av_unused
Definition: attributes.h:131
MATROSKA_ID_SEGMENT
#define MATROSKA_ID_SEGMENT
Definition: matroska.h:52
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:621
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
MATROSKA_ID_BLKADDIDTYPE
#define MATROSKA_ID_BLKADDIDTYPE
Definition: matroska.h:195
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:111
ff_isom_write_vvcc
int ff_isom_write_vvcc(AVIOContext *pb, const uint8_t *data, int size, int ps_array_completeness)
Writes H.266/VVC extradata (parameter sets, declarative SEI NAL units) to the provided AVIOContext.
Definition: vvc.c:879
MatroskaMuxContext::dash_track_number
int dash_track_number
Definition: matroskaenc.c:258
AV_CODEC_ID_RA_144
@ AV_CODEC_ID_RA_144
Definition: codec_id.h:433
ff_metadata_conv
void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:26
ebml_writer_write
static int ebml_writer_write(EbmlWriter *writer, AVIOContext *pb)
Definition: matroskaenc.c:747
MATROSKA_ID_CHAPTERS
#define MATROSKA_ID_CHAPTERS
Definition: matroska.h:62
AVCOL_TRC_NB
@ AVCOL_TRC_NB
Not part of ABI.
Definition: pixfmt.h:633
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
ebml_writer_elem_write
static int ebml_writer_elem_write(const EbmlElement *elem, AVIOContext *pb)
Definition: matroskaenc.c:704
MATROSKA_ID_VIDEOCOLOR_BY
#define MATROSKA_ID_VIDEOCOLOR_BY
Definition: matroska.h:155
pixdesc.h
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:390
MATROSKA_ID_BLOCKDURATION
#define MATROSKA_ID_BLOCKDURATION
Definition: matroska.h:247
MATROSKA_ID_VIDEOCOLORRANGE
#define MATROSKA_ID_VIDEOCOLORRANGE
Definition: matroska.h:142
MATROSKA_ID_BLOCK
#define MATROSKA_ID_BLOCK
Definition: matroska.h:246
av_dynamic_hdr_plus_to_t35
int av_dynamic_hdr_plus_to_t35(const AVDynamicHDRPlus *s, uint8_t **data, size_t *size)
Serialize dynamic HDR10+ metadata to a user data registered ITU-T T.35 buffer, excluding the first 48...
Definition: hdr_dynamic_metadata.c:239
AVPacket::data
uint8_t * data
Definition: packet.h:539
MATROSKA_ID_TRACKDEFAULTDURATION
#define MATROSKA_ID_TRACKDEFAULTDURATION
Definition: matroska.h:108
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
av_const
#define av_const
Definition: attributes.h:84
put_xiph_size
static void put_xiph_size(AVIOContext *pb, int size)
Definition: matroskaenc.c:841
AVOption
AVOption.
Definition: opt.h:429
AVCOL_SPC_NB
@ AVCOL_SPC_NB
Not part of ABI.
Definition: pixfmt.h:660
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:614
MatroskaMuxContext::mode
int mode
Definition: matroskaenc.c:218
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:837
mkv_track::duration_offset
int64_t duration_offset
Definition: matroskaenc.c:197
data
const char data[16]
Definition: mxf.c:149
MATROSKA_VIDEO_INTERLACE_FLAG_INTERLACED
@ MATROSKA_VIDEO_INTERLACE_FLAG_INTERLACED
Definition: matroska.h:299
MatroskaMuxContext::cluster_pts
int64_t cluster_pts
Definition: matroskaenc.c:225
mkv_write_attachments
static int mkv_write_attachments(AVFormatContext *s)
Definition: matroskaenc.c:2447
AV_CODEC_ID_ALAC
@ AV_CODEC_ID_ALAC
Definition: codec_id.h:464
MATROSKA_ID_DATEUTC
#define MATROSKA_ID_DATEUTC
Definition: matroska.h:70
ebml_id_size
static int ebml_id_size(uint32_t id)
Definition: matroskaenc.c:284
flacenc.h
AVIOContext::error
int error
contains the error code or 0 if no error happened
Definition: avio.h:239
MatroskaMuxContext::tags
ebml_stored_master tags
Definition: matroskaenc.c:221
EBML_UID
@ EBML_UID
Definition: matroskaenc.c:111
matroska.h
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: mux_utils.c:138
ff_codec_wav_tags
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:530
MATROSKA_ID_VIDEOPIXELCROPT
#define MATROSKA_ID_VIDEOPIXELCROPT
Definition: matroska.h:122
mkv_track::ts_offset
int64_t ts_offset
Definition: matroskaenc.c:202
MATROSKA_ID_VIDEOPIXELCROPB
#define MATROSKA_ID_VIDEOPIXELCROPB
Definition: matroska.h:121
put_ebml_binary
static void put_ebml_binary(AVIOContext *pb, uint32_t elementid, const void *buf, int size)
Definition: matroskaenc.c:394
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:557
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:59
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:68
MAX_VIDEO_COLOR_ELEMS
#define MAX_VIDEO_COLOR_ELEMS
Definition: matroskaenc.c:1338
max
#define max(a, b)
Definition: cuda_runtime.h:33
BlockContext
Definition: matroskaenc.c:119
mathematics.h
MATROSKA_ID_CUES
#define MATROSKA_ID_CUES
Definition: matroska.h:57
AVDictionary
Definition: dict.c:34
AV_CODEC_ID_FLAC
@ AV_CODEC_ID_FLAC
Definition: codec_id.h:460
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:324
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
MATROSKA_ID_CUETIME
#define MATROSKA_ID_CUETIME
Definition: matroska.h:202
IS_WEBM
#define IS_WEBM(mkv)
Definition: matroskaenc.c:86
AV_PROFILE_ARIB_PROFILE_C
#define AV_PROFILE_ARIB_PROFILE_C
Definition: defs.h:189
AVChannelLayout::mask
uint64_t mask
This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used for AV_CHANNEL_ORDER_AMBISONIC ...
Definition: channel_layout.h:351
WvHeader
Definition: wv.h:34
MATROSKA_ID_CUERELATIVEPOSITION
#define MATROSKA_ID_CUERELATIVEPOSITION
Definition: matroska.h:208
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:329
MAX_PCE_SIZE
#define MAX_PCE_SIZE
Maximum size of a PCE including the 3-bit ID_PCE.
Definition: mpeg4audio.h:118
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:564
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:246
AV_SPHERICAL_EQUIRECTANGULAR
@ AV_SPHERICAL_EQUIRECTANGULAR
Video represents a sphere mapped on a flat surface using equirectangular projection.
Definition: spherical.h:52
intfloat.h
codec_type
enum AVMediaType codec_type
Definition: rtp.c:37
AVChannelLayout::u
union AVChannelLayout::@432 u
Details about which channels are present in this layout.
MatroskaMuxContext::flipped_raw_rgb
int flipped_raw_rgb
Definition: matroskaenc.c:260
MATROSKA_ID_CHAPLANG
#define MATROSKA_ID_CHAPLANG
Definition: matroska.h:267
AV_CODEC_ID_TRUEHD
@ AV_CODEC_ID_TRUEHD
Definition: codec_id.h:492
MATROSKA_ID_CUEDURATION
#define MATROSKA_ID_CUEDURATION
Definition: matroska.h:209
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:1374
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:594
AV_WB64
#define AV_WB64(p, v)
Definition: intreadwrite.h:429
FFOutputFormat::p
AVOutputFormat p
The public AVOutputFormat.
Definition: mux.h:65
MatroskaMuxContext::cues_pos
int64_t cues_pos
Definition: matroskaenc.c:231
AV_FIELD_BT
@ AV_FIELD_BT
Bottom coded first, top displayed first.
Definition: defs.h:206
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:167
xiph.h
MatroskaMuxContext::cluster_size_limit
int cluster_size_limit
Definition: matroskaenc.c:252
MATROSKA_VIDEO_DISPLAYUNIT_UNKNOWN
@ MATROSKA_VIDEO_DISPLAYUNIT_UNKNOWN
Definition: matroska.h:336
mkv_track::codecpriv_offset
int codecpriv_offset
Definition: matroskaenc.c:200
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:107
MATROSKA_ID_VIDEOCOLOR_LUMINANCEMAX
#define MATROSKA_ID_VIDEOCOLOR_LUMINANCEMAX
Definition: matroska.h:158
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:280
MPEG4AudioConfig
Definition: mpeg4audio.h:29
crc.h
avio_wl16
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:437
AVCodecParameters::color_primaries
enum AVColorPrimaries color_primaries
Definition: codec_par.h:167
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:461
MATROSKA_ID_VIDEOCOLOR_WHITEY
#define MATROSKA_ID_VIDEOCOLOR_WHITEY
Definition: matroska.h:157
NOTHING
#define NOTHING(STEREOMODETYPE, WDIV, HDIV, WEBM)
AVPacketSideData::size
size_t size
Definition: packet.h:392
AV_PROFILE_ARIB_PROFILE_A
#define AV_PROFILE_ARIB_PROFILE_A
Definition: defs.h:188
HDIV1
#define HDIV1(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM)
start_ebml_master
static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid, uint64_t expectedsize)
Definition: matroskaenc.c:432
AV_FIELD_TT
@ AV_FIELD_TT
Top coded_first, top displayed first.
Definition: defs.h:203
DVCC_DVVC_BLOCK_TYPE_NAME
#define DVCC_DVVC_BLOCK_TYPE_NAME
Definition: matroska.h:439
AV_CODEC_ID_ASS
@ AV_CODEC_ID_ASS
Definition: codec_id.h:580
MATROSKA_ID_AUDIOOUTSAMPLINGFREQ
#define MATROSKA_ID_AUDIOOUTSAMPLINGFREQ
Definition: matroska.h:170
MAX_SUPPORTED_EBML_LENGTH
#define MAX_SUPPORTED_EBML_LENGTH
Definition: matroskaenc.c:81
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: avformat.c:868
mpeg4audio.h
MATROSKA_ID_VIDEOPROJECTIONPRIVATE
#define MATROSKA_ID_VIDEOPROJECTIONPRIVATE
Definition: matroska.h:163
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:358
AV_CODEC_ID_PCM_S16BE
@ AV_CODEC_ID_PCM_S16BE
Definition: codec_id.h:336
mkv_cues
Definition: matroskaenc.c:179
MatroskaMuxContext::move_cues_to_front
int move_cues_to_front
Definition: matroskaenc.c:262
fail
#define fail()
Definition: checkasm.h:193
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:123
ebml_writer_sint_len
static int ebml_writer_sint_len(EbmlElement *elem)
Definition: matroskaenc.c:589
EbmlElement::sint
int64_t sint
Definition: matroskaenc.c:139
MATROSKA_ID_CHAPTERDISPLAY
#define MATROSKA_ID_CHAPTERDISPLAY
Definition: matroska.h:265
MATROSKA_ID_TRACKUID
#define MATROSKA_ID_TRACKUID
Definition: matroska.h:78
samplefmt.h
EBML_ID_DOCTYPEVERSION
#define EBML_ID_DOCTYPEVERSION
Definition: matroska.h:40
AVCOL_RANGE_NB
@ AVCOL_RANGE_NB
Not part of ABI.
Definition: pixfmt.h:718
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:374
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:494
ff_matroska_video_stereo_mode
const char *const ff_matroska_video_stereo_mode[MATROSKA_VIDEO_STEREOMODE_TYPE_NB]
Definition: matroska.c:131
AVChapter
Definition: avformat.h:1259
AV_DISPOSITION_FORCED
#define AV_DISPOSITION_FORCED
Track should be used during playback by default.
Definition: avformat.h:654
val
static double val(void *priv, double ch)
Definition: aeval.c:77
MATROSKA_BLOCK_ADD_ID_TYPE_ITU_T_T35
@ MATROSKA_BLOCK_ADD_ID_TYPE_ITU_T_T35
Definition: matroska.h:363
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:129
pts
static int64_t pts
Definition: transcode_aac.c:644
us
#define us(width, name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:263
EBML_ID_DOCTYPE
#define EBML_ID_DOCTYPE
Definition: matroska.h:39
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
MATROSKA_ID_VIDEOCOLOR_WHITEX
#define MATROSKA_ID_VIDEOCOLOR_WHITEX
Definition: matroska.h:156
AVRational::num
int num
Numerator.
Definition: rational.h:59
AV_FIELD_TB
@ AV_FIELD_TB
Top coded first, bottom displayed first.
Definition: defs.h:205
MATROSKA_TRACK_TYPE_METADATA
@ MATROSKA_TRACK_TYPE_METADATA
Definition: matroska.h:287
DEFAULT_MODE_INFER
@ DEFAULT_MODE_INFER
Definition: matroskaenc.c:92
AV_CODEC_ID_ATRAC3
@ AV_CODEC_ID_ATRAC3
Definition: codec_id.h:479
mkv_track::max_blockaddid
uint64_t max_blockaddid
Definition: matroskaenc.c:198
MATROSKA_VIDEO_FIELDORDER_TT
@ MATROSKA_VIDEO_FIELDORDER_TT
Definition: matroska.h:305
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:199
AV_CODEC_ID_DVB_SUBTITLE
@ AV_CODEC_ID_DVB_SUBTITLE
Definition: codec_id.h:559
MatroskaVideoStereoModeType
MatroskaVideoStereoModeType
Definition: matroska.h:312
av_get_bits_per_sample
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:550
AV_CODEC_ID_SIPR
@ AV_CODEC_ID_SIPR
Definition: codec_id.h:489
AVCodecParameters::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: codec_par.h:168
MATROSKA_ID_BLKADDIDNAME
#define MATROSKA_ID_BLKADDIDNAME
Definition: matroska.h:194
mkv_write_tracks
static int mkv_write_tracks(AVFormatContext *s)
Definition: matroskaenc.c:2128
MatroskaMuxContext::ctx
AVFormatContext * ctx
Definition: matroskaenc.c:216
mkv_seekhead_entry
Definition: matroskaenc.c:159
MATROSKA_ID_BLOCKADDITIONAL
#define MATROSKA_ID_BLOCKADDITIONAL
Definition: matroska.h:242
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
EBML_ID_VOID
#define EBML_ID_VOID
Definition: matroska.h:44
MATROSKA_ID_VIDEOFIELDORDER
#define MATROSKA_ID_VIDEOFIELDORDER
Definition: matroska.h:127
AVCodecTag
Definition: internal.h:42
MATROSKA_ID_VIDEOPIXELCROPR
#define MATROSKA_ID_VIDEOPIXELCROPR
Definition: matroska.h:124
MATROSKA_ID_TAGS
#define MATROSKA_ID_TAGS
Definition: matroska.h:58
AV_CODEC_ID_TTA
@ AV_CODEC_ID_TTA
Definition: codec_id.h:470
options
static const AVOption options[]
Definition: matroskaenc.c:3545
duration
int64_t duration
Definition: movenc.c:65
put_ebml_id
static void put_ebml_id(AVIOContext *pb, uint32_t id)
Definition: matroskaenc.c:289
AV_FIELD_UNKNOWN
@ AV_FIELD_UNKNOWN
Definition: defs.h:201
EBML_ID_EBMLMAXIDLENGTH
#define EBML_ID_EBMLMAXIDLENGTH
Definition: matroska.h:37
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:62
avio_open_dyn_buf
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1362
mkv_cuepoint::relative_pos
int64_t relative_pos
relative offset from the position of the cluster containing the block
Definition: matroskaenc.c:175
mkv_update_codecprivate
static int mkv_update_codecprivate(AVFormatContext *s, MatroskaMuxContext *mkv, uint8_t *side_data, int side_data_size, AVCodecParameters *par, AVIOContext *pb, mkv_track *track, unsigned alternative_size)
Definition: matroskaenc.c:1301
AV_CODEC_ID_ADPCM_G726
@ AV_CODEC_ID_ADPCM_G726
Definition: codec_id.h:385
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
ebml_writer_block_len
static int ebml_writer_block_len(EbmlElement *elem)
Definition: matroskaenc.c:624
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:442
MATROSKA_ID_FILEUID
#define MATROSKA_ID_FILEUID
Definition: matroska.h:258
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVCHROMA_LOC_TOP
@ AVCHROMA_LOC_TOP
Definition: pixfmt.h:741
MATROSKA_VIDEO_INTERLACE_FLAG_PROGRESSIVE
@ MATROSKA_VIDEO_INTERLACE_FLAG_PROGRESSIVE
Definition: matroska.h:300
EbmlElement::bin
const uint8_t * bin
Definition: matroskaenc.c:142
av_chroma_location_enum_to_pos
int av_chroma_location_enum_to_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
Converts AVChromaLocation to swscale x/y chroma position.
Definition: pixdesc.c:3588
NALUList::nalus
NALU * nalus
Definition: evc.c:74
AVCOL_PRI_NB
@ AVCOL_PRI_NB
Not part of ABI.
Definition: pixfmt.h:604
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:108
mkv_track::write_dts
int write_dts
Definition: matroskaenc.c:187
CodecTags::str
char str[22]
Definition: matroska.h:376
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:117
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:217
format
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
mkv_write_flush_packet
static int mkv_write_flush_packet(AVFormatContext *s, AVPacket *pkt)
Definition: matroskaenc.c:3144
ebml_writer_add_block
static void ebml_writer_add_block(EbmlWriter *writer, MatroskaMuxContext *mkv)
Definition: matroskaenc.c:552
MATROSKA_VIDEO_FIELDORDER_BT
@ MATROSKA_VIDEO_FIELDORDER_BT
Definition: matroska.h:309
MatroskaMuxContext::cluster_pos
int64_t cluster_pos
file offset of the current Cluster
Definition: matroskaenc.c:224
AVDictionaryEntry::key
char * key
Definition: dict.h:90
MATROSKA_ID_TAGNAME
#define MATROSKA_ID_TAGNAME
Definition: matroska.h:215
AVSphericalMapping::bound_top
uint32_t bound_top
Distance from the top edge.
Definition: spherical.h:180
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:222
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:134
ebml_writer_open_master
static void ebml_writer_open_master(EbmlWriter *writer, uint32_t id)
Definition: matroskaenc.c:460
MATROSKA_ID_TAG
#define MATROSKA_ID_TAG
Definition: matroska.h:213
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
ebml_writer_add_uid
static void ebml_writer_add_uid(EbmlWriter *writer, uint32_t id, uint64_t val)
Definition: matroskaenc.c:531
MATROSKA_ID_TIMECODESCALE
#define MATROSKA_ID_TIMECODESCALE
Definition: matroska.h:65
lfg.h
MatroskaMuxContext::tmp_bc
AVIOContext * tmp_bc
Definition: matroskaenc.c:241
get_mimetype
static const char * get_mimetype(const AVStream *st)
Definition: matroskaenc.c:2430
ebml_writer_add_sint
static void ebml_writer_add_sint(EbmlWriter *writer, uint32_t id, int64_t val)
Definition: matroskaenc.c:545
MatroskaMuxContext::write_crc
int write_crc
Definition: matroskaenc.c:254
matroska_webm_class
static const AVClass matroska_webm_class
Definition: matroskaenc.c:3563
AV_OPT_TYPE_INT64
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
Definition: opt.h:263
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
MATROSKA_ID_CUETRACKPOSITION
#define MATROSKA_ID_CUETRACKPOSITION
Definition: matroska.h:203
additional_audio_tags
static const AVCodecTag additional_audio_tags[]
Definition: matroskaenc.c:3520
MATROSKA_ID_SEEKENTRY
#define MATROSKA_ID_SEEKENTRY
Definition: matroska.h:228
ff_isom_put_dvcc_dvvc
void ff_isom_put_dvcc_dvvc(void *logctx, uint8_t out[ISOM_DVCC_DVVC_SIZE], const AVDOVIDecoderConfigurationRecord *dovi)
Definition: dovi_isom.c:89
mkv_track::track_num
unsigned track_num
Definition: matroskaenc.c:190
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
MATROSKA_ID_TRACKTYPE
#define MATROSKA_ID_TRACKTYPE
Definition: matroska.h:79
AVPacketSideData::data
uint8_t * data
Definition: packet.h:391
ebml_writer_close_master
static void ebml_writer_close_master(EbmlWriter *writer)
Definition: matroskaenc.c:471
AVDOVIDecoderConfigurationRecord::dv_profile
uint8_t dv_profile
Definition: dovi_meta.h:58
MATROSKA_ID_SEGMENTUID
#define MATROSKA_ID_SEGMENTUID
Definition: matroska.h:71
EbmlType
EbmlType
Definition: matroskadec.c:89
MATROSKA_ID_TRACKBLKADDMAPPING
#define MATROSKA_ID_TRACKBLKADDMAPPING
Definition: matroska.h:113
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:111
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:142
sint_size
static av_const int sint_size(int64_t val)
Definition: matroskaenc.c:583
MatroskaMuxContext::cluster_time_limit
int64_t cluster_time_limit
Definition: matroskaenc.c:253
EbmlElement::type
EbmlType type
Definition: matroskaenc.c:134
EbmlElement::f
double f
Definition: matroskaenc.c:140
MATROSKA_ID_INFO
#define MATROSKA_ID_INFO
Definition: matroska.h:55
MatroskaMuxContext::have_video
int have_video
Definition: matroskaenc.c:246
MATROSKA_ID_AUDIOCHANNELS
#define MATROSKA_ID_AUDIOCHANNELS
Definition: matroska.h:173
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:410
MATROSKA_ID_BLKADDIDVALUE
#define MATROSKA_ID_BLKADDIDVALUE
Definition: matroska.h:193
AV_CODEC_ID_SVQ3
@ AV_CODEC_ID_SVQ3
Definition: codec_id.h:75
EbmlType
EbmlType
Definition: matroskaenc.c:107
key
const char * key
Definition: hwcontext_opencl.c:189
AVCodecParameters::nb_coded_side_data
int nb_coded_side_data
Amount of entries in coded_side_data.
Definition: codec_par.h:86
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:589
ff_format_shift_data
int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size)
Make shift_size amount of space at read_start by shifting data in the output at read_start until the ...
Definition: mux_utils.c:72
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
MATROSKA_ID_VIDEOSTEREOMODE
#define MATROSKA_ID_VIDEOSTEREOMODE
Definition: matroska.h:128
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:870
ff_webm_codec_tags
const CodecTags ff_webm_codec_tags[]
Definition: matroska.c:109
mkv_track::uid
uint64_t uid
Definition: matroskaenc.c:189
HDIV2
#define HDIV2(STEREOMODETYPE, WDIV, HDIV, WEBM)
AV_CODEC_ID_ARIB_CAPTION
@ AV_CODEC_ID_ARIB_CAPTION
Definition: codec_id.h:583
AVStereo3D::flags
int flags
Additional information about the frame packing.
Definition: stereo3d.h:212
MATROSKA_ID_VIDEOCOLORSPACE
#define MATROSKA_ID_VIDEOCOLORSPACE
Definition: matroska.h:131
if
if(ret)
Definition: filter_design.txt:179
MATROSKA_ID_TRACKNAME
#define MATROSKA_ID_TRACKNAME
Definition: matroska.h:95
FFFormatContext
Definition: internal.h:64
BlockContext::track
struct mkv_track * track
Definition: matroskaenc.c:120
AV_CODEC_ID_WEBVTT
@ AV_CODEC_ID_WEBVTT
Definition: codec_id.h:576
EBML_ID_DOCTYPEREADVERSION
#define EBML_ID_DOCTYPEREADVERSION
Definition: matroska.h:41
mkv_cues::entries
mkv_cuepoint * entries
Definition: matroskaenc.c:180
AVFormatContext
Format I/O context.
Definition: avformat.h:1300
internal.h
MATROSKA_ID_TRACKFLAGHEARINGIMPAIRED
#define MATROSKA_ID_TRACKFLAGHEARINGIMPAIRED
Definition: matroska.h:100
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:771
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
MATROSKA_ID_BLOCKGROUP
#define MATROSKA_ID_BLOCKGROUP
Definition: matroska.h:238
MATROSKA_ID_VIDEOCOLOR_LUMINANCEMIN
#define MATROSKA_ID_VIDEOCOLOR_LUMINANCEMIN
Definition: matroska.h:159
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
EbmlWriter
Definition: matroskaenc.c:148
mkv_assemble_codecprivate
static int mkv_assemble_codecprivate(AVFormatContext *s, AVIOContext *dyn_cp, AVCodecParameters *par, const uint8_t *extradata, int extradata_size, int native_id, int qt_id, uint8_t **codecpriv, int *codecpriv_size, unsigned *max_payload_size)
Definition: matroskaenc.c:1197
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:787
NULL
#define NULL
Definition: coverity.c:32
MATROSKA_ID_ATTACHMENTS
#define MATROSKA_ID_ATTACHMENTS
Definition: matroska.h:60
STEREOMODE_STEREO3D_MAPPING
#define STEREOMODE_STEREO3D_MAPPING(MAP, MKV_ONLY)
Definition: matroska.h:401
ff_put_wav_header
int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int flags)
Write WAVEFORMAT header structure.
Definition: riffenc.c:54
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:262
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:284
MATROSKA_TRACK_TYPE_AUDIO
@ MATROSKA_TRACK_TYPE_AUDIO
Definition: matroska.h:281
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:327
STEREOMODE
#define STEREOMODE(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM)
isom.h
MATROSKA_ID_TRACKFLAGORIGINAL
#define MATROSKA_ID_TRACKFLAGORIGINAL
Definition: matroska.h:103
MATROSKA_VIDEO_DISPLAYUNIT_DAR
@ MATROSKA_VIDEO_DISPLAYUNIT_DAR
Definition: matroska.h:335
mkv_track::default_duration_high
uint64_t default_duration_high
Definition: matroskaenc.c:204
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
MATROSKA_ID_WRITINGAPP
#define MATROSKA_ID_WRITINGAPP
Definition: matroska.h:68
WV_HEADER_SIZE
#define WV_HEADER_SIZE
Definition: wavpack.h:33
ff_isom_write_hvcc
int ff_isom_write_hvcc(AVIOContext *pb, const uint8_t *data, int size, int ps_array_completeness, void *logctx)
Writes HEVC extradata (parameter sets and declarative SEI NAL units with nuh_layer_id == 0,...
Definition: hevc.c:1401
MatroskaMuxContext::info
ebml_stored_master info
Definition: matroskaenc.c:219
AV_DISPOSITION_COMMENT
#define AV_DISPOSITION_COMMENT
The stream is a commentary track.
Definition: avformat.h:639
MATROSKA_ID_VIDEOCOLOR_GY
#define MATROSKA_ID_VIDEOCOLOR_GY
Definition: matroska.h:153
AV_CODEC_ID_CINEPAK
@ AV_CODEC_ID_CINEPAK
Definition: codec_id.h:95
AV_CODEC_ID_DVD_SUBTITLE
@ AV_CODEC_ID_DVD_SUBTITLE
Definition: codec_id.h:558
MAX_VIDEO_PROJECTION_ELEMS
#define MAX_VIDEO_PROJECTION_ELEMS
Definition: matroskaenc.c:1421
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
avc.h
parseutils.h
MATROSKA_ID_SIMPLETAG
#define MATROSKA_ID_SIMPLETAG
Definition: matroska.h:214
MATROSKA_ID_VIDEOPROJECTION
#define MATROSKA_ID_VIDEOPROJECTION
Definition: matroska.h:161
mkv_assemble_native_codecprivate
static int mkv_assemble_native_codecprivate(AVFormatContext *s, AVIOContext *dyn_cp, const AVCodecParameters *par, const uint8_t *extradata, int extradata_size, unsigned *size_to_reserve)
Definition: matroskaenc.c:1117
options
Definition: swscale.c:42
MatroskaMuxContext::segment_uid
uint32_t segment_uid[4]
Definition: matroskaenc.c:264
MatroskaMuxContext::cur_block
BlockContext cur_block
Definition: matroskaenc.c:233
put_xiph_codecpriv
static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, const AVCodecParameters *par, const uint8_t *extradata, int extradata_size)
Definition: matroskaenc.c:1005
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:828
MATROSKA_ID_SEEKID
#define MATROSKA_ID_SEEKID
Definition: matroska.h:231
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:336
FFOutputFormat
Definition: mux.h:61
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:703
EBML_STR
@ EBML_STR
Definition: matroskaenc.c:112
double
double
Definition: af_crystalizer.c:132
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:592
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:179
MATROSKA_ID_CHAPTERTIMESTART
#define MATROSKA_ID_CHAPTERTIMESTART
Definition: matroska.h:263
ff_codec_movvideo_tags
const AVCodecTag ff_codec_movvideo_tags[]
Definition: isom_tags.c:29
ffio_fill
void ffio_fill(AVIOContext *s, int b, int64_t count)
Definition: aviobuf.c:187
mkv_add_seekhead_entry
static void mkv_add_seekhead_entry(MatroskaMuxContext *mkv, uint32_t elementid, uint64_t filepos)
Definition: matroskaenc.c:757
AV_DISPOSITION_ORIGINAL
#define AV_DISPOSITION_ORIGINAL
The stream is in original language.
Definition: avformat.h:635
mkv_track::sample_rate_offset
int64_t sample_rate_offset
Definition: matroskaenc.c:194
AV_CODEC_ID_QDM2
@ AV_CODEC_ID_QDM2
Definition: codec_id.h:467
mkv_get_uid
static uint64_t mkv_get_uid(const mkv_track *tracks, int i, AVLFG *c)
Definition: matroskaenc.c:3367
MATROSKA_TRACK_TYPE_VIDEO
@ MATROSKA_TRACK_TYPE_VIDEO
Definition: matroska.h:280
ebml_writer_add
static EbmlElement * ebml_writer_add(EbmlWriter *writer, uint32_t id, EbmlType type)
Definition: matroskaenc.c:452
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: packet.c:438
get_metadata_duration
static int64_t get_metadata_duration(AVFormatContext *s)
Definition: matroskaenc.c:2497
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:180
mkv_track::has_cue
int has_cue
Definition: matroskaenc.c:188
MATROSKA_ID_FILEMIMETYPE
#define MATROSKA_ID_FILEMIMETYPE
Definition: matroska.h:256
MATROSKA_ID_VIDEODISPLAYHEIGHT
#define MATROSKA_ID_VIDEODISPLAYHEIGHT
Definition: matroska.h:118
WDIV1
#define WDIV1(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM)
EbmlWriter::elements
EbmlElement * elements
Definition: matroskaenc.c:151
ff_matroska_audio_muxer
const FFOutputFormat ff_matroska_audio_muxer
DURATION_STRING_LENGTH
#define DURATION_STRING_LENGTH
DURATION_STRING_LENGTH must be <= 112 or the containing simpletag will need more than one byte for it...
Definition: matroskaenc.c:276
AV_PKT_DATA_CONTENT_LIGHT_LEVEL
@ AV_PKT_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: packet.h:232
MATROSKA_ID_TRACKAUDIO
#define MATROSKA_ID_TRACKAUDIO
Definition: matroska.h:81
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:683
EbmlElement::str
const char * str
Definition: matroskaenc.c:141
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:245
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:184
put_ebml_float
static void put_ebml_float(AVIOContext *pb, uint32_t elementid, double val)
Definition: matroskaenc.c:387
uint_size
static av_const int uint_size(uint64_t val)
Definition: matroskaenc.c:568
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
av_packet_side_data_get
const AVPacketSideData * av_packet_side_data_get(const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
Get side information from a side data array.
Definition: packet.c:657
MATROSKA_ID_VIDEOCOLORMAXCLL
#define MATROSKA_ID_VIDEOCOLORMAXCLL
Definition: matroska.h:146
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:225
MATROSKA_ID_TRACKENTRY
#define MATROSKA_ID_TRACKENTRY
Definition: matroska.h:74
ebml_stored_master
Definition: matroskaenc.c:102
WDIV2
#define WDIV2(STEREOMODETYPE, WDIV, HDIV, WEBM)
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:73
AV_WB32
#define AV_WB32(p, v)
Definition: intreadwrite.h:415
ff_wv_parse_header
int ff_wv_parse_header(WvHeader *wv, const uint8_t *data)
Parse a WavPack block header.
Definition: wv.c:30
mkv_put_codecprivate
static void mkv_put_codecprivate(AVIOContext *pb, unsigned max_payload_size, const uint8_t *codecpriv, unsigned codecpriv_size)
Definition: matroskaenc.c:1272
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: codec_id.h:450
mkv_write_header
static int mkv_write_header(AVFormatContext *s)
Definition: matroskaenc.c:2596
mkv_track::default_duration_low
uint64_t default_duration_low
Definition: matroskaenc.c:203
MatroskaMuxContext
Definition: matroskaenc.c:214
mkv_cuepoint::duration
int64_t duration
duration of the block according to time base
Definition: matroskaenc.c:176
EbmlMaster::nb_elements
int nb_elements
-1 if not finished
Definition: matroskaenc.c:128
ebml_writer_add_bin
static void ebml_writer_add_bin(EbmlWriter *writer, uint32_t id, const uint8_t *data, size_t size)
Definition: matroskaenc.c:511
AV_DISPOSITION_CAPTIONS
#define AV_DISPOSITION_CAPTIONS
The subtitle stream contains captions, providing a transcription and possibly a translation of audio.
Definition: avformat.h:692
mkv_track::blockadditionmapping_offset
int64_t blockadditionmapping_offset
Definition: matroskaenc.c:199
MATROSKA_ID_AUDIOBITDEPTH
#define MATROSKA_ID_AUDIOBITDEPTH
Definition: matroska.h:172
AV_CODEC_ID_FFV1
@ AV_CODEC_ID_FFV1
Definition: codec_id.h:85
AVLFG
Context structure for the Lagged Fibonacci PRNG.
Definition: lfg.h:33
mkv_track::offset
unsigned offset
Definition: matroskaenc.c:193
MATROSKA_ID_TRACKFLAGDEFAULT
#define MATROSKA_ID_TRACKFLAGDEFAULT
Definition: matroska.h:98
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
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:61
MATROSKA_ID_TRACKFLAGCOMMENTARY
#define MATROSKA_ID_TRACKFLAGCOMMENTARY
Definition: matroska.h:104
ffio_reset_dyn_buf
void ffio_reset_dyn_buf(AVIOContext *s)
Reset a dynamic buffer.
Definition: aviobuf.c:1396
AVMediaType
AVMediaType
Definition: avutil.h:199
mkv_write_stereo_mode
static int mkv_write_stereo_mode(AVFormatContext *s, EbmlWriter *writer, const AVCodecParameters *par, const AVStream *st, int is_webm, int *h_width, int *h_height)
Definition: matroskaenc.c:1601
MATROSKA_ID_TRACKFLAGLACING
#define MATROSKA_ID_TRACKFLAGLACING
Definition: matroska.h:105
AVPacket::size
int size
Definition: packet.h:540
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:94
MATROSKA_ID_VIDEOCOLOR_GX
#define MATROSKA_ID_VIDEOCOLOR_GX
Definition: matroska.h:152
ff_codec_get_id
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:133
master
const char * master
Definition: vf_curves.c:130
FF_OFMT_FLAG_ALLOW_FLUSH
#define FF_OFMT_FLAG_ALLOW_FLUSH
This flag indicates that the muxer stores data internally and supports flushing it.
Definition: mux.h:38
ff_isom_write_avcc
int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
Definition: avc.c:31
AVSphericalMapping::bound_right
uint32_t bound_right
Distance from the right edge.
Definition: spherical.h:181
mkv_write_field_order
static void mkv_write_field_order(EbmlWriter *writer, int is_webm, enum AVFieldOrder field_order)
Definition: matroskaenc.c:1561
AV_PKT_DATA_DYNAMIC_HDR10_PLUS
@ AV_PKT_DATA_DYNAMIC_HDR10_PLUS
HDR10+ dynamic metadata associated with a video frame.
Definition: packet.h:296
EBML_FLOAT
@ EBML_FLOAT
Definition: matroskaenc.c:110
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:741
MATROSKA_ID_FILEDATA
#define MATROSKA_ID_FILEDATA
Definition: matroska.h:257
ebml_master::sizebytes
int sizebytes
how many bytes were reserved for the size
Definition: matroskaenc.c:99
MATROSKA_ID_VIDEOPROJECTIONPOSEPITCH
#define MATROSKA_ID_VIDEOPROJECTIONPOSEPITCH
Definition: matroska.h:165
mkv_handle_spherical
static int mkv_handle_spherical(void *logctx, EbmlWriter *writer, const AVCodecParameters *par, uint8_t private[], double *yaw, double *pitch, double *roll)
Definition: matroskaenc.c:1477
size
int size
Definition: twinvq_data.h:10344
MATROSKA_ID_BLOCKMORE
#define MATROSKA_ID_BLOCKMORE
Definition: matroska.h:240
MAX_SEEKHEAD_ENTRIES
#define MAX_SEEKHEAD_ENTRIES
Definition: matroskaenc.c:75
MATROSKA_BLOCK_ADD_ID_TYPE_OPAQUE
@ MATROSKA_BLOCK_ADD_ID_TYPE_OPAQUE
Definition: matroska.h:362
mkv_cuepoint::pts
uint64_t pts
Definition: matroskaenc.c:172
ebml_stored_master::bc
AVIOContext * bc
Definition: matroskaenc.c:103
EbmlWriter::current_master_element
int current_master_element
Definition: matroskaenc.c:150
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AV_CODEC_ID_QDMC
@ AV_CODEC_ID_QDMC
Definition: codec_id.h:498
put_ebml_void
static void put_ebml_void(AVIOContext *pb, int size)
Write a void element of a given size.
Definition: matroskaenc.c:414
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:147
EbmlElement::size
uint64_t size
excluding id and length field
Definition: matroskaenc.c:136
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
av_get_audio_frame_duration2
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
This function is the same as av_get_audio_frame_duration(), except it works with AVCodecParameters in...
Definition: utils.c:805
AVCodecParameters::profile
int profile
Codec-specific bitstream restrictions that the stream conforms to.
Definition: codec_par.h:128
AV_CODEC_ID_OPUS
@ AV_CODEC_ID_OPUS
Definition: codec_id.h:508
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:737
AV_DISPOSITION_DUB
#define AV_DISPOSITION_DUB
The stream is not in original language.
Definition: avformat.h:629
MatroskaMuxContext::cur_audio_pkt
AVPacket * cur_audio_pkt
Definition: matroskaenc.c:243
EBML_UINT
@ EBML_UINT
Definition: matroskaenc.c:108
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:826
av1.h
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:121
mkv_track::codecpriv_size
unsigned codecpriv_size
size reserved for CodecPrivate excluding header+length field
Definition: matroskaenc.c:201
start_ebml_master_crc32
static int start_ebml_master_crc32(AVIOContext **dyn_cp, MatroskaMuxContext *mkv)
Definition: matroskaenc.c:768
MATROSKA_ID_POINTENTRY
#define MATROSKA_ID_POINTENTRY
Definition: matroska.h:199
dovi_isom.h
header
static const uint8_t header[24]
Definition: sdr2.c:68
AV_DISPOSITION_HEARING_IMPAIRED
#define AV_DISPOSITION_HEARING_IMPAIRED
The stream is intended for hearing impaired audiences.
Definition: avformat.h:658
MATROSKA_ID_BLKADDIDEXTRADATA
#define MATROSKA_ID_BLKADDIDEXTRADATA
Definition: matroska.h:196
CASE
#define CASE(type, variable)
ff_isom_write_av1c
int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size, int write_seq_header)
Writes AV1 extradata (Sequence Header and Metadata OBUs) to the provided AVIOContext.
Definition: av1.c:399
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:538
MAX_FIELD_ORDER_ELEMS
#define MAX_FIELD_ORDER_ELEMS
Definition: matroskaenc.c:1560
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:201
avio_wb32
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:365
FF_COMPLIANCE_NORMAL
#define FF_COMPLIANCE_NORMAL
Definition: defs.h:60
AVSphericalMapping::padding
uint32_t padding
Number of pixels to pad from the edge of each cube face.
Definition: spherical.h:194
additional_subtitle_tags
static const AVCodecTag additional_subtitle_tags[]
Definition: matroskaenc.c:3535
EbmlElement::mkv
struct MatroskaMuxContext * mkv
used by EBML_BLOCK
Definition: matroskaenc.c:143
avio_wl32
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:357
mkv_write_blockadditional
static void mkv_write_blockadditional(EbmlWriter *writer, const uint8_t *buf, size_t size, uint64_t additional_id)
Definition: matroskaenc.c:2789
AV_CODEC_ID_VVC
@ AV_CODEC_ID_VVC
Definition: codec_id.h:252
av_crc_get_table
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
mkv_write_video_projection
static void mkv_write_video_projection(void *logctx, EbmlWriter *wr, const AVCodecParameters *par, uint8_t private[])
Definition: matroskaenc.c:1537
AV_CODEC_ID_RV30
@ AV_CODEC_ID_RV30
Definition: codec_id.h:120
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
mkv_write_tag_targets
static void mkv_write_tag_targets(MatroskaMuxContext *mkv, AVIOContext *pb, uint32_t elementid, uint64_t uid)
Definition: matroskaenc.c:2217
BlockContext::flags
uint8_t flags
Definition: matroskaenc.c:123
AV_CHANNEL_ORDER_NATIVE
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
Definition: channel_layout.h:125
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:545
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:223
version
version
Definition: libkvazaar.c:321
mkv_write_trailer
static int mkv_write_trailer(AVFormatContext *s)
Definition: matroskaenc.c:3162
AV_STEREO3D_FLAG_INVERT
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
Definition: stereo3d.h:194
MATROSKA_ID_VIDEOPIXELHEIGHT
#define MATROSKA_ID_VIDEOPIXELHEIGHT
Definition: matroska.h:120
mkv_write_tags
static int mkv_write_tags(AVFormatContext *s)
Definition: matroskaenc.c:2282
AV_CODEC_ID_SVQ1
@ AV_CODEC_ID_SVQ1
Definition: codec_id.h:74
M_PI
#define M_PI
Definition: mathematics.h:67
mkv_cuepoint::stream_idx
int stream_idx
Definition: matroskaenc.c:173
EBML_MASTER
@ EBML_MASTER
Definition: matroskaenc.c:116
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:220
MATROSKA_ID_MUXINGAPP
#define MATROSKA_ID_MUXINGAPP
Definition: matroska.h:69
mkv_write_video_color
static void mkv_write_video_color(EbmlWriter *writer, const AVStream *st, const AVCodecParameters *par)
Definition: matroskaenc.c:1339
MatroskaMuxContext::duration
int64_t duration
Definition: matroskaenc.c:227
MATROSKA_ID_EDITIONFLAGDEFAULT
#define MATROSKA_ID_EDITIONFLAGDEFAULT
Definition: matroska.h:271
MATROSKA_ID_FILEDESC
#define MATROSKA_ID_FILEDESC
Definition: matroska.h:254
ff_nal_units_write_list
void ff_nal_units_write_list(const NALUList *list, AVIOContext *pb, const uint8_t *buf)
Definition: nal.c:121
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:409
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:269
MATROSKA_ID_VIDEOPROJECTIONTYPE
#define MATROSKA_ID_VIDEOPROJECTIONTYPE
Definition: matroska.h:162
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:97
MATROSKA_ID_FILENAME
#define MATROSKA_ID_FILENAME
Definition: matroska.h:255
AV_CODEC_ID_ATRAC1
@ AV_CODEC_ID_ATRAC1
Definition: codec_id.h:494
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:67
EbmlMaster
Definition: matroskaenc.c:127
AV_CODEC_ID_RA_288
@ AV_CODEC_ID_RA_288
Definition: codec_id.h:434
ebml_stored_master::pos
int64_t pos
Definition: matroskaenc.c:104
AVSphericalMapping::roll
int32_t roll
Rotation around the forward vector [-180, 180].
Definition: spherical.h:140
MATROSKA_ID_CODECID
#define MATROSKA_ID_CODECID
Definition: matroska.h:87
AVIOContext::direct
int direct
avio_read and avio_write should if possible be satisfied directly instead of going through a buffer,...
Definition: avio.h:268
AV_CODEC_ID_RV10
@ AV_CODEC_ID_RV10
Definition: codec_id.h:57
AVFMT_GLOBALHEADER
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:478
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:532
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:108
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:349
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: packet.c:253
AV_CODEC_ID_THEORA
@ AV_CODEC_ID_THEORA
Definition: codec_id.h:82
av_builtin_constant_p
#define av_builtin_constant_p
Definition: attributes.h:160
EbmlElement::uint
uint64_t uint
Definition: matroskaenc.c:138
AVCodecParameters::height
int height
Definition: codec_par.h:135
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:207
mkv_cuepoint::cluster_pos
int64_t cluster_pos
offset of the cluster containing the block relative to the segment
Definition: matroskaenc.c:174
mkv_write_default_duration
static void mkv_write_default_duration(mkv_track *track, AVIOContext *pb, AVRational duration)
Definition: matroskaenc.c:1869
mkv_seekhead
Definition: matroskaenc.c:164
MATROSKA_ID_CUETRACK
#define MATROSKA_ID_CUETRACK
Definition: matroska.h:206
mkv_seekhead::entries
mkv_seekhead_entry entries[MAX_SEEKHEAD_ENTRIES]
Definition: matroskaenc.c:166
AV_FIELD_BB
@ AV_FIELD_BB
Bottom coded first, bottom displayed first.
Definition: defs.h:204
MATROSKA_ID_SEEKPOSITION
#define MATROSKA_ID_SEEKPOSITION
Definition: matroska.h:232
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
MATROSKA_ID_CLUSTER
#define MATROSKA_ID_CLUSTER
Definition: matroska.h:61
EbmlElement::id
uint32_t id
Definition: matroskaenc.c:133
MATROSKA_ID_TRACKLANGUAGE
#define MATROSKA_ID_TRACKLANGUAGE
Definition: matroska.h:96
AV_CODEC_ID_RV20
@ AV_CODEC_ID_RV20
Definition: codec_id.h:58
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:228
ebml_master::pos
int64_t pos
absolute offset in the containing AVIOContext where the master's elements start
Definition: matroskaenc.c:98
else
else
Definition: snow.txt:125
AVMEDIA_TYPE_ATTACHMENT
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition: avutil.h:205
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
MATROSKA_ID_VIDEOFLAGINTERLACED
#define MATROSKA_ID_VIDEOFLAGINTERLACED
Definition: matroska.h:126
EBML_WRITER
#define EBML_WRITER(max_nb_elems)
Definition: matroskaenc.c:154
MATROSKA_BLOCK_ADD_ID_ITU_T_T35
#define MATROSKA_BLOCK_ADD_ID_ITU_T_T35
Definition: matroska.h:369
AV_CODEC_ID_PCM_S32BE
@ AV_CODEC_ID_PCM_S32BE
Definition: codec_id.h:344
EBML_ID_CRC32
#define EBML_ID_CRC32
Definition: matroska.h:45
ff_mkv_metadata_conv
const AVMetadataConv ff_mkv_metadata_conv[]
Definition: matroska.c:125
mkv_write_track_video
static int mkv_write_track_video(AVFormatContext *s, MatroskaMuxContext *mkv, const AVStream *st, const AVCodecParameters *par, AVIOContext *pb)
Definition: matroskaenc.c:1758
av_inv_q
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
AVCodecParameters::color_range
enum AVColorRange color_range
Video only.
Definition: codec_par.h:166
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:643
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:129
ff_webm_muxer
const FFOutputFormat ff_webm_muxer
mkv_check_tag_name
static int mkv_check_tag_name(const char *name, uint32_t elementid)
Definition: matroskaenc.c:2227
MPEG4AudioConfig::ext_sample_rate
int ext_sample_rate
Definition: mpeg4audio.h:37
AVCodecParameters::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
Definition: codec_par.h:81
nal.h
MATROSKA_ID_CHAPTERUID
#define MATROSKA_ID_CHAPTERUID
Definition: matroska.h:273
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
mkv_reformat_av1
static int mkv_reformat_av1(MatroskaMuxContext *mkv, AVIOContext *pb, const AVPacket *pkt, int *size)
Definition: matroskaenc.c:2752
FF_API_ALLOW_FLUSH
#define FF_API_ALLOW_FLUSH
Definition: version_major.h:46
ebml_writer_close_or_discard_master
static void ebml_writer_close_or_discard_master(EbmlWriter *writer)
Definition: matroskaenc.c:485
AVCodecParameters::field_order
enum AVFieldOrder field_order
Video only.
Definition: codec_par.h:161
mkv_write_tag
static int mkv_write_tag(MatroskaMuxContext *mkv, const AVDictionary *m, AVIOContext **pb, unsigned reserved_size, uint32_t elementid, uint64_t uid)
Definition: matroskaenc.c:2241
AVDynamicHDRPlus
This struct represents dynamic metadata for color volume transform - application 4 of SMPTE 2094-40:2...
Definition: hdr_dynamic_metadata.h:243
mkv_end_cluster
static int mkv_end_cluster(AVFormatContext *s)
Definition: matroskaenc.c:2904
MATROSKA_ID_VIDEOPROJECTIONPOSEYAW
#define MATROSKA_ID_VIDEOPROJECTIONPOSEYAW
Definition: matroska.h:164
AVFMT_TS_NONSTRICT
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:491
ebml_write_header
static void ebml_write_header(AVIOContext *pb, const char *doctype, int version)
Definition: matroskaenc.c:2521
version.h
OFFSET
#define OFFSET(x)
Definition: matroskaenc.c:3543
mkv_assemble_cues
static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp, AVIOContext *cuepoint, const mkv_cues *cues, mkv_track *tracks, int num_tracks, uint64_t offset)
Definition: matroskaenc.c:963
BlockContext::h2645_nalu_list
NALUList h2645_nalu_list
Definition: matroskaenc.c:124
AVStream::disposition
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition: avformat.h:817
AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL
@ AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL
Data found in BlockAdditional element of matroska container.
Definition: packet.h:188
AV_DISPOSITION_VISUAL_IMPAIRED
#define AV_DISPOSITION_VISUAL_IMPAIRED
The stream is intended for visually impaired audiences.
Definition: avformat.h:662
tag
uint32_t tag
Definition: movenc.c:1879
ffio_free_dyn_buf
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
Definition: aviobuf.c:1435
AVFMT_FLAG_BITEXACT
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1468
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:748
mkv_track::sample_rate
int sample_rate
Definition: matroskaenc.c:192
mkv_write_block
static int mkv_write_block(void *logctx, MatroskaMuxContext *mkv, AVIOContext *pb, const AVCodecParameters *par, mkv_track *track, const AVPacket *pkt, int keyframe, int64_t ts, uint64_t duration, int force_blockgroup, int64_t relative_packet_pos)
Definition: matroskaenc.c:2798
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:231
mkv_seekhead_entry::elementid
uint32_t elementid
Definition: matroskaenc.c:160
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:80
AVSphericalMapping::pitch
int32_t pitch
Rotation around the right vector [-90, 90].
Definition: spherical.h:139
ff_av1_filter_obus
int ff_av1_filter_obus(AVIOContext *pb, const uint8_t *buf, int size)
Filter out AV1 OBUs not meant to be present in ISOBMFF sample data and write the resulting bitstream ...
Definition: av1.c:83
AVStereo3D::type
enum AVStereo3DType type
How views are packed within the video.
Definition: stereo3d.h:207
mkv_track::last_timestamp
int64_t last_timestamp
Definition: matroskaenc.c:195
MATROSKA_ID_VIDEOCOLOR_BX
#define MATROSKA_ID_VIDEOCOLOR_BX
Definition: matroska.h:154
MatroskaMuxContext::wrote_tags
int wrote_tags
Definition: matroskaenc.c:249
MATROSKA_ID_TAGSTRING
#define MATROSKA_ID_TAGSTRING
Definition: matroska.h:216
mkv_seekhead_entry::segmentpos
uint64_t segmentpos
Definition: matroskaenc.c:161
put_ebml_string
static void put_ebml_string(AVIOContext *pb, uint32_t elementid, const char *str)
Definition: matroskaenc.c:402
MATROSKA_ID_VIDEOCOLORMATRIXCOEFF
#define MATROSKA_ID_VIDEOCOLORMATRIXCOEFF
Definition: matroska.h:134
pos
unsigned int pos
Definition: spdifenc.c:414
WEBM1
#define WEBM1(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM)
avformat.h
dict.h
AV_CODEC_ID_TEXT
@ AV_CODEC_ID_TEXT
raw UTF-8 text
Definition: codec_id.h:560
MATROSKA_ID_SIMPLEBLOCK
#define MATROSKA_ID_SIMPLEBLOCK
Definition: matroska.h:243
AV_DISPOSITION_DESCRIPTIONS
#define AV_DISPOSITION_DESCRIPTIONS
The subtitle stream contains a textual description of the video content.
Definition: avformat.h:698
ebml_writer_str_len
static int ebml_writer_str_len(EbmlElement *elem)
Definition: matroskaenc.c:558
id
enum AVCodecID id
Definition: dts2pts.c:367
MATROSKA_ID_VIDEOPIXELCROPL
#define MATROSKA_ID_VIDEOPIXELCROPL
Definition: matroska.h:123
EBML_SINT
@ EBML_SINT
Definition: matroskaenc.c:109
MATROSKA_BLOCK_ADD_ID_TYPE_DVVC
@ MATROSKA_BLOCK_ADD_ID_TYPE_DVVC
Definition: matroska.h:365
left
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
Definition: snow.txt:386
FLAGS
#define FLAGS
Definition: matroskaenc.c:3544
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
U
#define U(x)
Definition: vpx_arith.h:37
EbmlElement::priv
union EbmlElement::@403 priv
AVCodecParameters::chroma_location
enum AVChromaLocation chroma_location
Definition: codec_par.h:170
mkv_deinit
static void mkv_deinit(AVFormatContext *s)
Free the members allocated in the mux context.
Definition: matroskaenc.c:850
WEBM2
#define WEBM2(STEREOMODETYPE, WDIV, HDIV, WEBM)
NALUList
Definition: evc.c:73
ebml_writer_uint_len
static int ebml_writer_uint_len(EbmlElement *elem)
Definition: matroskaenc.c:577
AV_PKT_DATA_WEBVTT_IDENTIFIER
@ AV_PKT_DATA_WEBVTT_IDENTIFIER
The optional first identifier line of a WebVTT cue.
Definition: packet.h:193
MAX_STEREO_MODE_ELEMS
#define MAX_STEREO_MODE_ELEMS
Definition: matroskaenc.c:1600
webm_reformat_vtt
static int webm_reformat_vtt(MatroskaMuxContext *mkv, AVIOContext *pb, const AVPacket *pkt, int *size)
Definition: matroskaenc.c:2762
MATROSKA_ID_EDITIONENTRY
#define MATROSKA_ID_EDITIONENTRY
Definition: matroska.h:261
mkv_track::reformat
int(* reformat)(struct MatroskaMuxContext *, AVIOContext *, const AVPacket *, int *size)
Definition: matroskaenc.c:210
ff_codec_bmp_tags
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:36
MATROSKA_ID_TRACKMAXBLKADDID
#define MATROSKA_ID_TRACKMAXBLKADDID
Definition: matroska.h:112
itut35.h
random_seed.h
EBML_ID_HEADER
#define EBML_ID_HEADER
Definition: matroska.h:32
AV_HDR_PLUS_MAX_PAYLOAD_SIZE
#define AV_HDR_PLUS_MAX_PAYLOAD_SIZE
Definition: hdr_dynamic_metadata.h:356
channel_layout.h
EBML_ID_EBMLVERSION
#define EBML_ID_EBMLVERSION
Definition: matroska.h:35
mkv_track
Definition: matroskaenc.c:186
MatroskaMuxContext::seekhead
mkv_seekhead seekhead
Definition: matroskaenc.c:229
wv.h
DURATION_SIMPLETAG_SIZE
#define DURATION_SIMPLETAG_SIZE
2 + 1 Simpletag header, 2 + 1 + 8 Name "DURATION", rest for TagString
Definition: matroskaenc.c:279
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:41
ebml_writer_elem_len
static int ebml_writer_elem_len(EbmlWriter *writer, EbmlElement *elem, int remaining_elems)
Definition: matroskaenc.c:670
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:217
AVRational::den
int den
Denominator.
Definition: rational.h:60
EbmlElement::master
EbmlMaster master
Definition: matroskaenc.c:144
EbmlWriter::nb_elements
unsigned nb_elements
Definition: matroskaenc.c:149
MATROSKA_ID_VIDEOCOLOR
#define MATROSKA_ID_VIDEOCOLOR
Definition: matroska.h:132
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
MatroskaMuxContext::cues
mkv_cues cues
Definition: matroskaenc.c:230
mkv_check_bitstream
static int mkv_check_bitstream(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
Definition: matroskaenc.c:3502
defs.h
ff_codec_get_tag
unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id)
Definition: utils.c:123
MATROSKA_ID_VIDEOCOLORTRANSFERCHARACTERISTICS
#define MATROSKA_ID_VIDEOCOLORTRANSFERCHARACTERISTICS
Definition: matroska.h:143
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:261
MATROSKA_ID_VIDEOCOLOR_RX
#define MATROSKA_ID_VIDEOCOLOR_RX
Definition: matroska.h:150
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:818
MATROSKA_TRACK_TYPE_SUBTITLE
@ MATROSKA_TRACK_TYPE_SUBTITLE
Definition: matroska.h:284
MatroskaMuxContext::duration_offset
int64_t duration_offset
Definition: matroskaenc.c:226
hdr_dynamic_metadata.h
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:931
AVStream::r_frame_rate
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:914
AV_PKT_DATA_SKIP_SAMPLES
@ AV_PKT_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
Definition: packet.h:153
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:165
MATROSKA_VIDEO_PROJECTION_TYPE_EQUIRECTANGULAR
@ MATROSKA_VIDEO_PROJECTION_TYPE_EQUIRECTANGULAR
Definition: matroska.h:355
mkv_check_new_extra_data
static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt)
Definition: matroskaenc.c:2923
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:541
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:26
mkv_seekhead::reserved_size
int reserved_size
Definition: matroskaenc.c:168
avio_wb64
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:431
MATROSKA_ID_VIDEOCOLORCHROMASITINGHORZ
#define MATROSKA_ID_VIDEOCOLORCHROMASITINGHORZ
Definition: matroska.h:140
MatroskaMuxContext::is_live
int is_live
Definition: matroskaenc.c:255
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:191
EbmlElement::length_size
unsigned length_size
Definition: matroskaenc.c:135
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
MATROSKA_ID_BLOCKREFERENCE
#define MATROSKA_ID_BLOCKREFERENCE
Definition: matroska.h:248
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:1879
AVCodecParameters::bits_per_coded_sample
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: codec_par.h:110
mem.h
CodecTags::id
enum AVCodecID id
Definition: matroska.h:377
MATROSKA_ID_VIDEOCOLOR_RY
#define MATROSKA_ID_VIDEOCOLOR_RY
Definition: matroska.h:151
MATROSKA_VIDEO_FIELDORDER_TB
@ MATROSKA_VIDEO_FIELDORDER_TB
Definition: matroska.h:308
mastering_display_metadata.h
ITU_T_T35_COUNTRY_CODE_US
#define ITU_T_T35_COUNTRY_CODE_US
Definition: itut35.h:24
AVSphericalMapping::bound_left
uint32_t bound_left
Distance from the left edge.
Definition: spherical.h:179
mkv_cues::num_entries
int num_entries
Definition: matroskaenc.c:181
FFFormatContext::pkt
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
Definition: internal.h:111
ebml_writer_write_block
static void ebml_writer_write_block(const EbmlElement *elem, AVIOContext *pb)
Definition: matroskaenc.c:649
AVCodecParameters::format
int format
Definition: codec_par.h:92
MatroskaMuxContext::track
ebml_stored_master track
Definition: matroskaenc.c:220
MATROSKA_ID_TRACKVIDEO
#define MATROSKA_ID_TRACKVIDEO
Definition: matroska.h:80
avio_wb24
void avio_wb24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:455
ff_mkv_codec_tags
const CodecTags ff_mkv_codec_tags[]
Definition: matroska.c:27
MATROSKA_ID_TRACKFLAGFORCED
#define MATROSKA_ID_TRACKFLAGFORCED
Definition: matroska.h:99
MATROSKA_VIDEO_STEREOMODE_TYPE_NB
@ MATROSKA_VIDEO_STEREOMODE_TYPE_NB
Definition: matroska.h:328
AVDictionaryEntry
Definition: dict.h:89
codec_par.h
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
EBML_ID_EBMLREADVERSION
#define EBML_ID_EBMLREADVERSION
Definition: matroska.h:36
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
ITU_T_T35_PROVIDER_CODE_SMTPE
#define ITU_T_T35_PROVIDER_CODE_SMTPE
Definition: itut35.h:30
AVContentLightMetadata::MaxFALL
unsigned MaxFALL
Max average light level per frame (cd/m^2).
Definition: mastering_display_metadata.h:116
AVPacket
This structure stores compressed data.
Definition: packet.h:516
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
mkv_write_chapters
static int mkv_write_chapters(AVFormatContext *s)
Definition: matroskaenc.c:2345
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
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:88
riff.h
MATROSKA_ID_ATTACHEDFILE
#define MATROSKA_ID_ATTACHEDFILE
Definition: matroska.h:253
MATROSKA_ID_CODECDELAY
#define MATROSKA_ID_CODECDELAY
Definition: matroska.h:93
EBML_UTF8
@ EBML_UTF8
Definition: matroskaenc.c:113
DEFAULT_MODE_PASSTHROUGH
@ DEFAULT_MODE_PASSTHROUGH
Definition: matroskaenc.c:94
ff_matroska_muxer
const FFOutputFormat ff_matroska_muxer
int32_t
int32_t
Definition: audioconvert.c:56
bytestream.h
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:890
MAX_CUETRACKPOS_SIZE
#define MAX_CUETRACKPOS_SIZE
4 * (1-byte EBML ID, 1-byte EBML size, 8-byte uint max)
Definition: matroskaenc.c:272
avio_wb16
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:443
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:192
MATROSKA_ID_TAGTARGETS_TRACKUID
#define MATROSKA_ID_TAGTARGETS_TRACKUID
Definition: matroska.h:223
mkv_handle_rotation
static void mkv_handle_rotation(void *logctx, const AVCodecParameters *par, double *yaw, double *roll)
Definition: matroskaenc.c:1422
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
BlockContext::rel_ts
int16_t rel_ts
Definition: matroskaenc.c:122
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AV_CODEC_ID_WAVPACK
@ AV_CODEC_ID_WAVPACK
Definition: codec_id.h:473
AV_CODEC_ID_COOK
@ AV_CODEC_ID_COOK
Definition: codec_id.h:468
MATROSKA_ID_CHAPTERTIMEEND
#define MATROSKA_ID_CHAPTERTIMEEND
Definition: matroska.h:264
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
EBML_BLOCK
@ EBML_BLOCK
pseudo-type for writing (Simple)Blocks
Definition: matroskaenc.c:115
MATROSKA_ID_TRACKS
#define MATROSKA_ID_TRACKS
Definition: matroska.h:56
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3774
AV_CODEC_ID_VORBIS
@ AV_CODEC_ID_VORBIS
Definition: codec_id.h:453
AVStereo3D
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
Definition: stereo3d.h:203
AVDictionaryEntry::value
char * value
Definition: dict.h:91
avstring.h
MATROSKA_ID_SEEKPREROLL
#define MATROSKA_ID_SEEKPREROLL
Definition: matroska.h:94
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:248
codec_desc.h
MATROSKA_ID_SEEKHEAD
#define MATROSKA_ID_SEEKHEAD
Definition: matroska.h:59
mkv_write_simpletag
static int mkv_write_simpletag(AVIOContext *pb, const AVDictionaryEntry *t)
Definition: matroskaenc.c:2182
MATROSKA_BLOCK_ADD_ID_TYPE_DVCC
@ MATROSKA_BLOCK_ADD_ID_TYPE_DVCC
Definition: matroska.h:364
ff_nal_units_create_list
int ff_nal_units_create_list(NALUList *list, const uint8_t *buf, int size)
Definition: nal.c:115
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
snprintf
#define snprintf
Definition: snprintf.h:34
mkv_cuepoint
Definition: matroskaenc.c:171
AVCodecParameters::initial_padding
int initial_padding
Audio only.
Definition: codec_par.h:203
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: mux.c:1354
MATROSKA_ID_VIDEOPROJECTIONPOSEROLL
#define MATROSKA_ID_VIDEOPROJECTIONPOSEROLL
Definition: matroska.h:166
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
mkv_seekhead::num_entries
int num_entries
Definition: matroskaenc.c:167
AV_CODEC_ID_PCM_S24BE
@ AV_CODEC_ID_PCM_S24BE
Definition: codec_id.h:348
MATROSKA_ID_BLOCKADDID
#define MATROSKA_ID_BLOCKADDID
Definition: matroska.h:241
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:367
mkv_write_blockadditionmapping
static void mkv_write_blockadditionmapping(AVFormatContext *s, const MatroskaMuxContext *mkv, const AVCodecParameters *par, AVIOContext *pb, mkv_track *track, const AVStream *st)
Definition: matroskaenc.c:1701
AVSphericalMapping
This structure describes how to handle spherical videos, outlining information about projection,...
Definition: spherical.h:94
FFStream::lowest_ts_allowed
int64_t lowest_ts_allowed
This is the lowest ts allowed in this track; it may be set by the muxer during init or write_header a...
Definition: internal.h:254
av_dict_iterate
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition: dict.c:44
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:375
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:84
AVSphericalMapping::yaw
int32_t yaw
Rotation around the up vector [-180, 180].
Definition: spherical.h:138
src
#define src
Definition: vp8dsp.c:248
MATROSKA_ID_TAGTARGETS_CHAPTERUID
#define MATROSKA_ID_TAGTARGETS_CHAPTERUID
Definition: matroska.h:224
MATROSKA_VIDEO_PROJECTION_TYPE_CUBEMAP
@ MATROSKA_VIDEO_PROJECTION_TYPE_CUBEMAP
Definition: matroska.h:356
AV_CODEC_ID_MLP
@ AV_CODEC_ID_MLP
Definition: codec_id.h:477
mkv_write_info
static int mkv_write_info(AVFormatContext *s)
Definition: matroskaenc.c:2537
AV_CODEC_ID_PRORES
@ AV_CODEC_ID_PRORES
Definition: codec_id.h:200
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_metadata_conv_ctx
void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:59
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:227
MPEG4AudioConfig::sample_rate
int sample_rate
Definition: mpeg4audio.h:32
AVDOVIDecoderConfigurationRecord
Definition: dovi_meta.h:55
MATROSKA_ID_BLOCKADDITIONS
#define MATROSKA_ID_BLOCKADDITIONS
Definition: matroska.h:239
DEFAULT_MODE_INFER_NO_SUBS
@ DEFAULT_MODE_INFER_NO_SUBS
Definition: matroskaenc.c:93
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:145
mux.h
FFFormatContext::avoid_negative_ts_use_pts
int avoid_negative_ts_use_pts
Definition: internal.h:117