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 "av1.h"
25 #include "avc.h"
26 #include "hevc.h"
27 #include "avformat.h"
28 #include "avio_internal.h"
29 #include "avlanguage.h"
30 #include "flacenc.h"
31 #include "internal.h"
32 #include "isom.h"
33 #include "matroska.h"
34 #include "riff.h"
35 #include "subtitles.h"
36 #include "vorbiscomment.h"
37 #include "wv.h"
38 
39 #include "libavutil/avstring.h"
41 #include "libavutil/crc.h"
42 #include "libavutil/dict.h"
43 #include "libavutil/intfloat.h"
44 #include "libavutil/intreadwrite.h"
45 #include "libavutil/lfg.h"
47 #include "libavutil/mathematics.h"
48 #include "libavutil/opt.h"
49 #include "libavutil/parseutils.h"
50 #include "libavutil/random_seed.h"
51 #include "libavutil/rational.h"
52 #include "libavutil/samplefmt.h"
53 #include "libavutil/sha.h"
54 #include "libavutil/stereo3d.h"
55 
56 #include "libavcodec/xiph.h"
57 #include "libavcodec/mpeg4audio.h"
58 #include "libavcodec/internal.h"
59 
60 /* Level 1 elements we create a SeekHead entry for:
61  * Info, Tracks, Chapters, Attachments, Tags and Cues */
62 #define MAX_SEEKHEAD_ENTRIES 6
63 
64 typedef struct ebml_master {
65  int64_t pos; ///< absolute offset in the containing AVIOContext where the master's elements start
66  int sizebytes; ///< how many bytes were reserved for the size
67 } ebml_master;
68 
69 typedef struct mkv_seekhead_entry {
70  uint32_t elementid;
71  uint64_t segmentpos;
73 
74 typedef struct mkv_seekhead {
75  int64_t filepos;
79 } mkv_seekhead;
80 
81 typedef struct mkv_cuepoint {
82  uint64_t pts;
84  int tracknum;
85  int64_t cluster_pos; ///< offset of the cluster containing the block relative to the segment
86  int64_t relative_pos; ///< relative offset from the position of the cluster containing the block
87  int64_t duration; ///< duration of the block according to time base
88 } mkv_cuepoint;
89 
90 typedef struct mkv_cues {
91  int64_t segment_offset;
94 } mkv_cues;
95 
96 typedef struct mkv_track {
97  int write_dts;
98  int has_cue;
101  int64_t last_timestamp;
102  int64_t duration;
105  int64_t ts_offset;
106 } mkv_track;
107 
108 typedef struct mkv_attachment {
110  uint32_t fileuid;
112 
113 typedef struct mkv_attachments {
117 
118 #define MODE_MATROSKAv2 0x01
119 #define MODE_WEBM 0x02
120 
121 /** Maximum number of tracks allowed in a Matroska file (with track numbers in
122  * range 1 to 126 (inclusive) */
123 #define MAX_TRACKS 126
124 
125 typedef struct MatroskaMuxContext {
126  const AVClass *class;
127  int mode;
129  int64_t tags_pos;
131  int64_t info_pos;
133  int64_t tracks_pos;
135  int64_t segment_offset;
137  int64_t cluster_pos; ///< file offset of the current cluster
138  int64_t cluster_pts;
140  int64_t duration;
145 
147 
150 
153  int64_t cues_pos;
155  int is_dash;
157  int is_live;
159 
162 
165 
166 /** 2 bytes * 7 for EBML IDs, 7 1-byte EBML lengths, 6 1-byte uint,
167  * 8 byte for "matroska" doctype string */
168 #define MAX_EBML_HEADER_SIZE 35
169 
170 /** 2 bytes * 3 for EBML IDs, 3 1-byte EBML lengths, 8 bytes for 64 bit
171  * offset, 4 bytes for target EBML ID */
172 #define MAX_SEEKENTRY_SIZE 21
173 
174 /** per-cuepoint-track - 5 1-byte EBML IDs, 5 1-byte EBML sizes, 3 8-byte uint max
175  * and one 1-byte uint for the track number (this assumes MAX_TRACKS to be <= 255) */
176 #define MAX_CUETRACKPOS_SIZE 35
177 
178 /** per-cuepoint - 1 1-byte EBML ID, 1 1-byte EBML size, 8-byte uint max */
179 #define MAX_CUEPOINT_CONTENT_SIZE(num_tracks) 10 + MAX_CUETRACKPOS_SIZE * num_tracks
180 
181 /** Seek preroll value for opus */
182 #define OPUS_SEEK_PREROLL 80000000
183 
184 static int ebml_id_size(uint32_t id)
185 {
186  return (av_log2(id + 1) - 1) / 7 + 1;
187 }
188 
189 static void put_ebml_id(AVIOContext *pb, uint32_t id)
190 {
191  int i = ebml_id_size(id);
192  while (i--)
193  avio_w8(pb, (uint8_t)(id >> (i * 8)));
194 }
195 
196 /**
197  * Write an EBML size meaning "unknown size".
198  *
199  * @param bytes The number of bytes the size should occupy (maximum: 8).
200  */
201 static void put_ebml_size_unknown(AVIOContext *pb, int bytes)
202 {
203  av_assert0(bytes <= 8);
204  avio_w8(pb, 0x1ff >> bytes);
205  ffio_fill(pb, 0xff, bytes - 1);
206 }
207 
208 /**
209  * Calculate how many bytes are needed to represent a given number in EBML.
210  */
211 static int ebml_num_size(uint64_t num)
212 {
213  int bytes = 1;
214  while ((num + 1) >> bytes * 7)
215  bytes++;
216  return bytes;
217 }
218 
219 /**
220  * Write a number in EBML variable length format.
221  *
222  * @param bytes The number of bytes that need to be used to write the number.
223  * If zero, the minimal number of bytes will be used.
224  */
225 static void put_ebml_num(AVIOContext *pb, uint64_t num, int bytes)
226 {
227  int i, needed_bytes = ebml_num_size(num);
228 
229  // sizes larger than this are currently undefined in EBML
230  av_assert0(num < (1ULL << 56) - 1);
231 
232  if (bytes == 0)
233  bytes = needed_bytes;
234  // The bytes needed to write the given size must not exceed
235  // the bytes that we ought to use.
236  av_assert0(bytes >= needed_bytes);
237 
238  num |= 1ULL << bytes * 7;
239  for (i = bytes - 1; i >= 0; i--)
240  avio_w8(pb, (uint8_t)(num >> i * 8));
241 }
242 
243 static void put_ebml_uint(AVIOContext *pb, uint32_t elementid, uint64_t val)
244 {
245  int i, bytes = 1;
246  uint64_t tmp = val;
247  while (tmp >>= 8)
248  bytes++;
249 
250  put_ebml_id(pb, elementid);
251  put_ebml_num(pb, bytes, 0);
252  for (i = bytes - 1; i >= 0; i--)
253  avio_w8(pb, (uint8_t)(val >> i * 8));
254 }
255 
256 static void put_ebml_sint(AVIOContext *pb, uint32_t elementid, int64_t val)
257 {
258  int i, bytes = 1;
259  uint64_t tmp = 2*(val < 0 ? val^-1 : val);
260 
261  while (tmp>>=8) bytes++;
262 
263  put_ebml_id(pb, elementid);
264  put_ebml_num(pb, bytes, 0);
265  for (i = bytes - 1; i >= 0; i--)
266  avio_w8(pb, (uint8_t)(val >> i * 8));
267 }
268 
269 static void put_ebml_float(AVIOContext *pb, uint32_t elementid, double val)
270 {
271  put_ebml_id(pb, elementid);
272  put_ebml_num(pb, 8, 0);
273  avio_wb64(pb, av_double2int(val));
274 }
275 
276 static void put_ebml_binary(AVIOContext *pb, uint32_t elementid,
277  const void *buf, int size)
278 {
279  put_ebml_id(pb, elementid);
280  put_ebml_num(pb, size, 0);
281  avio_write(pb, buf, size);
282 }
283 
284 static void put_ebml_string(AVIOContext *pb, uint32_t elementid,
285  const char *str)
286 {
287  put_ebml_binary(pb, elementid, str, strlen(str));
288 }
289 
290 /**
291  * Write a void element of a given size. Useful for reserving space in
292  * the file to be written to later.
293  *
294  * @param size The number of bytes to reserve, which must be at least 2.
295  */
296 static void put_ebml_void(AVIOContext *pb, uint64_t size)
297 {
298  int64_t currentpos = avio_tell(pb);
299 
300  av_assert0(size >= 2);
301 
303  // we need to subtract the length needed to store the size from the
304  // size we need to reserve so 2 cases, we use 8 bytes to store the
305  // size if possible, 1 byte otherwise
306  if (size < 10)
307  put_ebml_num(pb, size - 2, 0);
308  else
309  put_ebml_num(pb, size - 9, 8);
310  ffio_fill(pb, 0, currentpos + size - avio_tell(pb));
311 }
312 
313 static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid,
314  uint64_t expectedsize)
315 {
316  int bytes = expectedsize ? ebml_num_size(expectedsize) : 8;
317 
318  put_ebml_id(pb, elementid);
319  put_ebml_size_unknown(pb, bytes);
320  return (ebml_master) { avio_tell(pb), bytes };
321 }
322 
324 {
325  int64_t pos = avio_tell(pb);
326 
327  if (avio_seek(pb, master.pos - master.sizebytes, SEEK_SET) < 0)
328  return;
329  put_ebml_num(pb, pos - master.pos, master.sizebytes);
330  avio_seek(pb, pos, SEEK_SET);
331 }
332 
334  uint32_t elementid)
335 {
336  int ret;
337 
338  if ((ret = avio_open_dyn_buf(dyn_cp)) < 0)
339  return ret;
340 
341  put_ebml_id(pb, elementid);
342  if (mkv->write_crc)
343  put_ebml_void(*dyn_cp, 6); /* Reserve space for CRC32 so position/size calculations using avio_tell() take it into account */
344 
345  return 0;
346 }
347 
349 {
350  uint8_t *buf, crc[4];
351  int size, skip = 0;
352 
353  size = avio_close_dyn_buf(*dyn_cp, &buf);
354  put_ebml_num(pb, size, 0);
355  if (mkv->write_crc) {
356  skip = 6; /* Skip reserved 6-byte long void element from the dynamic buffer. */
357  AV_WL32(crc, av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), UINT32_MAX, buf + skip, size - skip) ^ UINT32_MAX);
358  put_ebml_binary(pb, EBML_ID_CRC32, crc, sizeof(crc));
359  }
360  avio_write(pb, buf + skip, size - skip);
361 
362  av_free(buf);
363  *dyn_cp = NULL;
364 }
365 
366 /**
367 * Complete ebml master without destroying the buffer, allowing for later updates
368 */
370  int64_t *pos)
371 {
372  uint8_t *buf;
373  int size = avio_get_dyn_buf(*dyn_cp, &buf);
374 
375  *pos = avio_tell(pb);
376 
377  put_ebml_num(pb, size, 0);
378  avio_write(pb, buf, size);
379 }
380 
381 static void put_xiph_size(AVIOContext *pb, int size)
382 {
383  ffio_fill(pb, 255, size / 255);
384  avio_w8(pb, size % 255);
385 }
386 
387 /**
388  * Free the members allocated in the mux context.
389  */
391 {
392  MatroskaMuxContext *mkv = s->priv_data;
393 
395 
397  ffio_free_dyn_buf(&mkv->info_bc);
399  ffio_free_dyn_buf(&mkv->tags_bc);
400 
401  if (mkv->cues) {
402  av_freep(&mkv->cues->entries);
403  av_freep(&mkv->cues);
404  }
405  if (mkv->attachments) {
406  av_freep(&mkv->attachments->entries);
407  av_freep(&mkv->attachments);
408  }
409  av_freep(&mkv->tracks);
410 }
411 
412 /**
413  * Initialize the SeekHead element to be ready to index level 1 Matroska
414  * elements. Enough space to write MAX_SEEKHEAD_ENTRIES SeekHead entries
415  * will be reserved at the current file location.
416  */
418 {
419  mkv->seekhead.filepos = avio_tell(pb);
420  // 21 bytes max for a Seek entry, 6 bytes max for the SeekHead ID
421  // and size, 6 bytes for a CRC32 element, and 2 bytes to guarantee
422  // that an EBML void element will fit afterwards
425 }
426 
427 static void mkv_add_seekhead_entry(MatroskaMuxContext *mkv, uint32_t elementid,
428  uint64_t filepos)
429 {
430  mkv_seekhead *seekhead = &mkv->seekhead;
431 
433 
434  seekhead->entries[seekhead->num_entries].elementid = elementid;
435  seekhead->entries[seekhead->num_entries++].segmentpos = filepos - mkv->segment_offset;
436 }
437 
438 /**
439  * Write the SeekHead to the file at the location reserved for it.
440  *
441  * @return The file offset where the seekhead was written,
442  * -1 if an error occurred.
443  */
445 {
446  AVIOContext *dyn_cp;
447  mkv_seekhead *seekhead = &mkv->seekhead;
448  ebml_master seekentry;
449  int64_t currentpos, remaining;
450  int i;
451 
452  currentpos = avio_tell(pb);
453 
454  if (avio_seek(pb, seekhead->filepos, SEEK_SET) < 0) {
455  currentpos = -1;
456  goto fail;
457  }
458 
459  if (start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_SEEKHEAD) < 0) {
460  currentpos = -1;
461  goto fail;
462  }
463 
464  for (i = 0; i < seekhead->num_entries; i++) {
465  mkv_seekhead_entry *entry = &seekhead->entries[i];
466 
468 
470  put_ebml_num(dyn_cp, ebml_id_size(entry->elementid), 0);
471  put_ebml_id(dyn_cp, entry->elementid);
472 
474  end_ebml_master(dyn_cp, seekentry);
475  }
476  end_ebml_master_crc32(pb, &dyn_cp, mkv);
477 
478  remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb);
479  put_ebml_void(pb, remaining);
480  avio_seek(pb, currentpos, SEEK_SET);
481 
482  currentpos = seekhead->filepos;
483 
484 fail:
485 
486  return currentpos;
487 }
488 
489 static mkv_cues *mkv_start_cues(int64_t segment_offset)
490 {
491  mkv_cues *cues = av_mallocz(sizeof(mkv_cues));
492  if (!cues)
493  return NULL;
494 
495  cues->segment_offset = segment_offset;
496  return cues;
497 }
498 
499 static int mkv_add_cuepoint(mkv_cues *cues, int stream, int tracknum, int64_t ts,
500  int64_t cluster_pos, int64_t relative_pos, int64_t duration)
501 {
502  mkv_cuepoint *entries = cues->entries;
503 
504  if (ts < 0)
505  return 0;
506 
507  entries = av_realloc_array(entries, cues->num_entries + 1, sizeof(mkv_cuepoint));
508  if (!entries)
509  return AVERROR(ENOMEM);
510  cues->entries = entries;
511 
512  cues->entries[cues->num_entries].pts = ts;
513  cues->entries[cues->num_entries].stream_idx = stream;
514  cues->entries[cues->num_entries].tracknum = tracknum;
515  cues->entries[cues->num_entries].cluster_pos = cluster_pos - cues->segment_offset;
516  cues->entries[cues->num_entries].relative_pos = relative_pos;
517  cues->entries[cues->num_entries++].duration = duration;
518 
519  return 0;
520 }
521 
522 static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tracks, int num_tracks)
523 {
524  MatroskaMuxContext *mkv = s->priv_data;
525  AVIOContext *dyn_cp, *pb = s->pb;
526  int64_t currentpos;
527  int i, j, ret;
528 
529  currentpos = avio_tell(pb);
530  ret = start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CUES);
531  if (ret < 0)
532  return ret;
533 
534  for (i = 0; i < cues->num_entries; i++) {
535  ebml_master cuepoint, track_positions;
536  mkv_cuepoint *entry = &cues->entries[i];
537  uint64_t pts = entry->pts;
538  int ctp_nb = 0;
539 
540  // Calculate the number of entries, so we know the element size
541  for (j = 0; j < num_tracks; j++)
542  tracks[j].has_cue = 0;
543  for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) {
544  int idx = entry[j].stream_idx;
545 
546  av_assert0(idx >= 0 && idx < num_tracks);
547  if (tracks[idx].has_cue && s->streams[idx]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE)
548  continue;
549  tracks[idx].has_cue = 1;
550  ctp_nb ++;
551  }
552 
554  put_ebml_uint(dyn_cp, MATROSKA_ID_CUETIME, pts);
555 
556  // put all the entries from different tracks that have the exact same
557  // timestamp into the same CuePoint
558  for (j = 0; j < num_tracks; j++)
559  tracks[j].has_cue = 0;
560  for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) {
561  int idx = entry[j].stream_idx;
562 
563  if (tracks[idx].has_cue && s->streams[idx]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE)
564  continue;
565  tracks[idx].has_cue = 1;
567  put_ebml_uint(dyn_cp, MATROSKA_ID_CUETRACK , entry[j].tracknum );
568  put_ebml_uint(dyn_cp, MATROSKA_ID_CUECLUSTERPOSITION , entry[j].cluster_pos);
569  put_ebml_uint(dyn_cp, MATROSKA_ID_CUERELATIVEPOSITION, entry[j].relative_pos);
570  if (entry[j].duration != -1)
571  put_ebml_uint(dyn_cp, MATROSKA_ID_CUEDURATION , entry[j].duration);
572  end_ebml_master(dyn_cp, track_positions);
573  }
574  i += j - 1;
575  end_ebml_master(dyn_cp, cuepoint);
576  }
577  end_ebml_master_crc32(pb, &dyn_cp, mkv);
578 
579  return currentpos;
580 }
581 
583 {
584  const uint8_t *header_start[3];
585  int header_len[3];
586  int first_header_size;
587  int j;
588 
589  if (par->codec_id == AV_CODEC_ID_VORBIS)
590  first_header_size = 30;
591  else
592  first_header_size = 42;
593 
595  first_header_size, header_start, header_len) < 0) {
596  av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n");
597  return -1;
598  }
599 
600  avio_w8(pb, 2); // number packets - 1
601  for (j = 0; j < 2; j++) {
602  put_xiph_size(pb, header_len[j]);
603  }
604  for (j = 0; j < 3; j++)
605  avio_write(pb, header_start[j], header_len[j]);
606 
607  return 0;
608 }
609 
611 {
612  if (par->extradata && par->extradata_size == 2)
613  avio_write(pb, par->extradata, 2);
614  else
615  avio_wl16(pb, 0x403); // fallback to the version mentioned in matroska specs
616  return 0;
617 }
618 
620  AVIOContext *pb, AVCodecParameters *par)
621 {
622  int write_comment = (par->channel_layout &&
623  !(par->channel_layout & ~0x3ffffULL) &&
625  int ret = ff_flac_write_header(pb, par->extradata, par->extradata_size,
626  !write_comment);
627 
628  if (ret < 0)
629  return ret;
630 
631  if (write_comment) {
632  const char *vendor = (s->flags & AVFMT_FLAG_BITEXACT) ?
633  "Lavf" : LIBAVFORMAT_IDENT;
634  AVDictionary *dict = NULL;
635  uint8_t buf[32], *data, *p;
636  int64_t len;
637 
638  snprintf(buf, sizeof(buf), "0x%"PRIx64, par->channel_layout);
639  av_dict_set(&dict, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0);
640 
641  len = ff_vorbiscomment_length(dict, vendor, NULL, 0);
642  if (len >= ((1<<24) - 4)) {
643  av_dict_free(&dict);
644  return AVERROR(EINVAL);
645  }
646 
647  data = av_malloc(len + 4);
648  if (!data) {
649  av_dict_free(&dict);
650  return AVERROR(ENOMEM);
651  }
652 
653  data[0] = 0x84;
654  AV_WB24(data + 1, len);
655 
656  p = data + 4;
657  ff_vorbiscomment_write(&p, &dict, vendor, NULL, 0);
658 
659  avio_write(pb, data, len + 4);
660 
661  av_freep(&data);
662  av_dict_free(&dict);
663  }
664 
665  return 0;
666 }
667 
668 static int get_aac_sample_rates(AVFormatContext *s, uint8_t *extradata, int extradata_size,
669  int *sample_rate, int *output_sample_rate)
670 {
671  MPEG4AudioConfig mp4ac;
672  int ret;
673 
674  ret = avpriv_mpeg4audio_get_config2(&mp4ac, extradata, extradata_size, 1, s);
675  /* Don't abort if the failure is because of missing extradata. Assume in that
676  * case a bitstream filter will provide the muxer with the extradata in the
677  * first packet.
678  * Abort however if s->pb is not seekable, as we would not be able to seek back
679  * to write the sample rate elements once the extradata shows up, anyway. */
680  if (ret < 0 && (extradata_size || !(s->pb->seekable & AVIO_SEEKABLE_NORMAL))) {
681  av_log(s, AV_LOG_ERROR,
682  "Error parsing AAC extradata, unable to determine samplerate.\n");
683  return AVERROR(EINVAL);
684  }
685 
686  if (ret < 0) {
687  /* This will only happen when this function is called while writing the
688  * header and no extradata is available. The space for this element has
689  * to be reserved for when this function is called again after the
690  * extradata shows up in the first packet, as there's no way to know if
691  * output_sample_rate will be different than sample_rate or not. */
692  *output_sample_rate = *sample_rate;
693  } else {
694  *sample_rate = mp4ac.sample_rate;
695  *output_sample_rate = mp4ac.ext_sample_rate;
696  }
697  return 0;
698 }
699 
701  AVCodecParameters *par,
702  AVIOContext *dyn_cp)
703 {
704  switch (par->codec_id) {
705  case AV_CODEC_ID_VORBIS:
706  case AV_CODEC_ID_THEORA:
707  return put_xiph_codecpriv(s, dyn_cp, par);
708  case AV_CODEC_ID_FLAC:
709  return put_flac_codecpriv(s, dyn_cp, par);
710  case AV_CODEC_ID_WAVPACK:
711  return put_wv_codecpriv(dyn_cp, par);
712  case AV_CODEC_ID_H264:
713  return ff_isom_write_avcc(dyn_cp, par->extradata,
714  par->extradata_size);
715  case AV_CODEC_ID_HEVC:
716  return ff_isom_write_hvcc(dyn_cp, par->extradata,
717  par->extradata_size, 0);
718  case AV_CODEC_ID_AV1:
719  if (par->extradata_size)
720  return ff_isom_write_av1c(dyn_cp, par->extradata,
721  par->extradata_size);
722  else
723  put_ebml_void(pb, 4 + 3);
724  break;
725  case AV_CODEC_ID_ALAC:
726  if (par->extradata_size < 36) {
727  av_log(s, AV_LOG_ERROR,
728  "Invalid extradata found, ALAC expects a 36-byte "
729  "QuickTime atom.");
730  return AVERROR_INVALIDDATA;
731  } else
732  avio_write(dyn_cp, par->extradata + 12,
733  par->extradata_size - 12);
734  break;
735  case AV_CODEC_ID_AAC:
736  if (par->extradata_size)
737  avio_write(dyn_cp, par->extradata, par->extradata_size);
738  else
739  put_ebml_void(pb, MAX_PCE_SIZE + 2 + 4);
740  break;
741  default:
742  if (par->codec_id == AV_CODEC_ID_PRORES &&
744  avio_wl32(dyn_cp, par->codec_tag);
745  } else if (par->extradata_size && par->codec_id != AV_CODEC_ID_TTA)
746  avio_write(dyn_cp, par->extradata, par->extradata_size);
747  }
748 
749  return 0;
750 }
751 
753  AVCodecParameters *par,
754  int native_id, int qt_id)
755 {
756  AVIOContext *dyn_cp;
757  uint8_t *codecpriv;
758  int ret, codecpriv_size;
759 
760  ret = avio_open_dyn_buf(&dyn_cp);
761  if (ret < 0)
762  return ret;
763 
764  if (native_id) {
765  ret = mkv_write_native_codecprivate(s, pb, par, dyn_cp);
766  } else if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
767  if (qt_id) {
768  if (!par->codec_tag)
770  par->codec_id);
773  ) {
774  int i;
775  avio_wb32(dyn_cp, 0x5a + par->extradata_size);
776  avio_wl32(dyn_cp, par->codec_tag);
777  for(i = 0; i < 0x5a - 8; i++)
778  avio_w8(dyn_cp, 0);
779  }
780  avio_write(dyn_cp, par->extradata, par->extradata_size);
781  } else {
783  av_log(s, AV_LOG_WARNING, "codec %s is not supported by this format\n",
784  avcodec_get_name(par->codec_id));
785 
786  if (!par->codec_tag)
788  par->codec_id);
789  if (!par->codec_tag && par->codec_id != AV_CODEC_ID_RAWVIDEO) {
790  av_log(s, AV_LOG_ERROR, "No bmp codec tag found for codec %s\n",
791  avcodec_get_name(par->codec_id));
792  ret = AVERROR(EINVAL);
793  }
794 
795  ff_put_bmp_header(dyn_cp, par, 0, 0);
796  }
797  } else if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
798  unsigned int tag;
800  if (!tag) {
801  av_log(s, AV_LOG_ERROR, "No wav codec tag found for codec %s\n",
802  avcodec_get_name(par->codec_id));
803  ret = AVERROR(EINVAL);
804  }
805  if (!par->codec_tag)
806  par->codec_tag = tag;
807 
809  }
810 
811  codecpriv_size = avio_get_dyn_buf(dyn_cp, &codecpriv);
812  if (codecpriv_size)
814  codecpriv_size);
815  ffio_free_dyn_buf(&dyn_cp);
816  return ret;
817 }
818 
820  AVIOContext *dyn_cp;
821  uint8_t *colorinfo_ptr;
822  int side_data_size = 0;
823  int ret, colorinfo_size;
824  const uint8_t *side_data;
825 
826  ret = avio_open_dyn_buf(&dyn_cp);
827  if (ret < 0)
828  return ret;
829 
830  if (par->color_trc != AVCOL_TRC_UNSPECIFIED &&
831  par->color_trc < AVCOL_TRC_NB) {
833  par->color_trc);
834  }
835  if (par->color_space != AVCOL_SPC_UNSPECIFIED &&
836  par->color_space < AVCOL_SPC_NB) {
838  }
840  par->color_primaries < AVCOL_PRI_NB) {
842  }
843  if (par->color_range != AVCOL_RANGE_UNSPECIFIED &&
844  par->color_range < AVCOL_RANGE_NB) {
846  }
849  int xpos, ypos;
850 
851  avcodec_enum_to_chroma_pos(&xpos, &ypos, par->chroma_location);
852  put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORCHROMASITINGHORZ, (xpos >> 7) + 1);
853  put_ebml_uint(dyn_cp, MATROSKA_ID_VIDEOCOLORCHROMASITINGVERT, (ypos >> 7) + 1);
854  }
855 
857  &side_data_size);
858  if (side_data_size) {
859  const AVContentLightMetadata *metadata =
860  (const AVContentLightMetadata*)side_data;
863  }
864 
866  &side_data_size);
867  if (side_data_size == sizeof(AVMasteringDisplayMetadata)) {
868  ebml_master meta_element = start_ebml_master(
870  const AVMasteringDisplayMetadata *metadata =
871  (const AVMasteringDisplayMetadata*)side_data;
872  if (metadata->has_primaries) {
874  av_q2d(metadata->display_primaries[0][0]));
876  av_q2d(metadata->display_primaries[0][1]));
878  av_q2d(metadata->display_primaries[1][0]));
880  av_q2d(metadata->display_primaries[1][1]));
882  av_q2d(metadata->display_primaries[2][0]));
884  av_q2d(metadata->display_primaries[2][1]));
886  av_q2d(metadata->white_point[0]));
888  av_q2d(metadata->white_point[1]));
889  }
890  if (metadata->has_luminance) {
892  av_q2d(metadata->max_luminance));
894  av_q2d(metadata->min_luminance));
895  }
896  end_ebml_master(dyn_cp, meta_element);
897  }
898 
899  colorinfo_size = avio_get_dyn_buf(dyn_cp, &colorinfo_ptr);
900  if (colorinfo_size) {
901  ebml_master colorinfo = start_ebml_master(pb, MATROSKA_ID_VIDEOCOLOR, colorinfo_size);
902  avio_write(pb, colorinfo_ptr, colorinfo_size);
903  end_ebml_master(pb, colorinfo);
904  }
905  ffio_free_dyn_buf(&dyn_cp);
906  return 0;
907 }
908 
910  AVStream *st)
911 {
912  ebml_master projection;
913  int side_data_size = 0;
914  uint8_t private[20];
915 
916  const AVSphericalMapping *spherical =
918  &side_data_size);
919 
920  if (!side_data_size)
921  return 0;
922 
923  if (spherical->projection != AV_SPHERICAL_EQUIRECTANGULAR &&
925  spherical->projection != AV_SPHERICAL_CUBEMAP) {
926  av_log(s, AV_LOG_WARNING, "Unknown projection type\n");
927  return 0;
928  }
929 
930  // Maximally 4 8-byte elements with id-length 2 + 1 byte length field
931  // and the private data of the AV_SPHERICAL_EQUIRECTANGULAR_TILE case
933  4 * (2 + 1 + 8) + (2 + 1 + 20));
934 
935  switch (spherical->projection) {
939  break;
943  AV_WB32(private, 0); // version + flags
944  AV_WB32(private + 4, spherical->bound_top);
945  AV_WB32(private + 8, spherical->bound_bottom);
946  AV_WB32(private + 12, spherical->bound_left);
947  AV_WB32(private + 16, spherical->bound_right);
949  private, 20);
950  break;
954  AV_WB32(private, 0); // version + flags
955  AV_WB32(private + 4, 0); // layout
956  AV_WB32(private + 8, spherical->padding);
958  private, 12);
959  break;
960  default:
961  av_assert0(0);
962  }
963 
964  if (spherical->yaw)
966  (double) spherical->yaw / (1 << 16));
967  if (spherical->pitch)
969  (double) spherical->pitch / (1 << 16));
970  if (spherical->roll)
972  (double) spherical->roll / (1 << 16));
973 
974  end_ebml_master(pb, projection);
975 
976  return 0;
977 }
978 
980  enum AVFieldOrder field_order)
981 {
982  switch (field_order) {
983  case AV_FIELD_UNKNOWN:
984  break;
988  break;
989  case AV_FIELD_TT:
990  case AV_FIELD_BB:
991  case AV_FIELD_TB:
992  case AV_FIELD_BT:
995  if (mode != MODE_WEBM) {
996  switch (field_order) {
997  case AV_FIELD_TT:
1000  break;
1001  case AV_FIELD_BB:
1004  break;
1005  case AV_FIELD_TB:
1008  break;
1009  case AV_FIELD_BT:
1012  break;
1013  }
1014  }
1015  }
1016 }
1017 
1019  AVStream *st, int mode, int *h_width, int *h_height)
1020 {
1021  int i;
1022  int ret = 0;
1025 
1026  *h_width = 1;
1027  *h_height = 1;
1028  // convert metadata into proper side data and add it to the stream
1029  if ((tag = av_dict_get(st->metadata, "stereo_mode", NULL, 0)) ||
1030  (tag = av_dict_get( s->metadata, "stereo_mode", NULL, 0))) {
1031  int stereo_mode = atoi(tag->value);
1032 
1033  for (i=0; i<MATROSKA_VIDEO_STEREOMODE_TYPE_NB; i++)
1034  if (!strcmp(tag->value, ff_matroska_video_stereo_mode[i])){
1035  stereo_mode = i;
1036  break;
1037  }
1038 
1039  if (stereo_mode < MATROSKA_VIDEO_STEREOMODE_TYPE_NB &&
1040  stereo_mode != 10 && stereo_mode != 12) {
1041  int ret = ff_mkv_stereo3d_conv(st, stereo_mode);
1042  if (ret < 0)
1043  return ret;
1044  }
1045  }
1046 
1047  // iterate to find the stereo3d side data
1048  for (i = 0; i < st->nb_side_data; i++) {
1049  AVPacketSideData sd = st->side_data[i];
1050  if (sd.type == AV_PKT_DATA_STEREO3D) {
1051  AVStereo3D *stereo = (AVStereo3D *)sd.data;
1052 
1053  switch (stereo->type) {
1054  case AV_STEREO3D_2D:
1056  break;
1058  format = (stereo->flags & AV_STEREO3D_FLAG_INVERT)
1061  *h_width = 2;
1062  break;
1063  case AV_STEREO3D_TOPBOTTOM:
1065  if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
1066  format--;
1067  *h_height = 2;
1068  break;
1071  if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
1072  format--;
1073  break;
1074  case AV_STEREO3D_LINES:
1076  if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
1077  format--;
1078  *h_height = 2;
1079  break;
1080  case AV_STEREO3D_COLUMNS:
1082  if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
1083  format--;
1084  *h_width = 2;
1085  break;
1088  if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
1089  format++;
1090  break;
1091  }
1092  break;
1093  }
1094  }
1095 
1096  if (format == MATROSKA_VIDEO_STEREOMODE_TYPE_NB)
1097  return ret;
1098 
1099  // if webm, do not write unsupported modes
1100  if ((mode == MODE_WEBM &&
1103  || format >= MATROSKA_VIDEO_STEREOMODE_TYPE_NB) {
1104  av_log(s, AV_LOG_ERROR,
1105  "The specified stereo mode is not valid.\n");
1107  return AVERROR(EINVAL);
1108  }
1109 
1110  // write StereoMode if format is valid
1112 
1113  return ret;
1114 }
1115 
1117  int i, AVIOContext *pb, int default_stream_exists)
1118 {
1119  AVStream *st = s->streams[i];
1120  AVCodecParameters *par = st->codecpar;
1121  ebml_master subinfo, track;
1122  int native_id = 0;
1123  int qt_id = 0;
1125  int sample_rate = par->sample_rate;
1126  int output_sample_rate = 0;
1127  int display_width_div = 1;
1128  int display_height_div = 1;
1129  int j, ret;
1131 
1132  if (par->codec_type == AVMEDIA_TYPE_ATTACHMENT) {
1133  mkv->have_attachments = 1;
1134  return 0;
1135  }
1136 
1137  if (par->codec_type == AVMEDIA_TYPE_AUDIO) {
1138  if (!bit_depth && par->codec_id != AV_CODEC_ID_ADPCM_G726) {
1139  if (par->bits_per_raw_sample)
1140  bit_depth = par->bits_per_raw_sample;
1141  else
1142  bit_depth = av_get_bytes_per_sample(par->format) << 3;
1143  }
1144  if (!bit_depth)
1145  bit_depth = par->bits_per_coded_sample;
1146  }
1147 
1148  if (par->codec_id == AV_CODEC_ID_AAC) {
1149  ret = get_aac_sample_rates(s, par->extradata, par->extradata_size, &sample_rate,
1150  &output_sample_rate);
1151  if (ret < 0)
1152  return ret;
1153  }
1154 
1155  track = start_ebml_master(pb, MATROSKA_ID_TRACKENTRY, 0);
1157  mkv->is_dash ? mkv->dash_track_number : i + 1);
1159  mkv->is_dash ? mkv->dash_track_number : i + 1);
1160  put_ebml_uint (pb, MATROSKA_ID_TRACKFLAGLACING , 0); // no lacing (yet)
1161 
1162  if ((tag = av_dict_get(st->metadata, "title", NULL, 0)))
1164  tag = av_dict_get(st->metadata, "language", NULL, 0);
1165  if (mkv->mode != MODE_WEBM || par->codec_id != AV_CODEC_ID_WEBVTT) {
1166  put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, tag && tag->value ? tag->value:"und");
1167  } else if (tag && tag->value) {
1169  }
1170 
1171  // The default value for TRACKFLAGDEFAULT is 1, so add element
1172  // if we need to clear it.
1173  if (default_stream_exists && !(st->disposition & AV_DISPOSITION_DEFAULT))
1175 
1178 
1179  if (mkv->mode == MODE_WEBM) {
1180  const char *codec_id;
1181  if (par->codec_type != AVMEDIA_TYPE_SUBTITLE) {
1182  for (j = 0; ff_webm_codec_tags[j].id != AV_CODEC_ID_NONE; j++) {
1183  if (ff_webm_codec_tags[j].id == par->codec_id) {
1184  codec_id = ff_webm_codec_tags[j].str;
1185  native_id = 1;
1186  break;
1187  }
1188  }
1189  } else if (par->codec_id == AV_CODEC_ID_WEBVTT) {
1191  codec_id = "D_WEBVTT/CAPTIONS";
1192  native_id = MATROSKA_TRACK_TYPE_SUBTITLE;
1193  } else if (st->disposition & AV_DISPOSITION_DESCRIPTIONS) {
1194  codec_id = "D_WEBVTT/DESCRIPTIONS";
1195  native_id = MATROSKA_TRACK_TYPE_METADATA;
1196  } else if (st->disposition & AV_DISPOSITION_METADATA) {
1197  codec_id = "D_WEBVTT/METADATA";
1198  native_id = MATROSKA_TRACK_TYPE_METADATA;
1199  } else {
1200  codec_id = "D_WEBVTT/SUBTITLES";
1201  native_id = MATROSKA_TRACK_TYPE_SUBTITLE;
1202  }
1203  }
1204 
1205  if (!native_id) {
1206  av_log(s, AV_LOG_ERROR,
1207  "Only VP8 or VP9 or AV1 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM.\n");
1208  return AVERROR(EINVAL);
1209  }
1210 
1211  put_ebml_string(pb, MATROSKA_ID_CODECID, codec_id);
1212  } else {
1213  // look for a codec ID string specific to mkv to use,
1214  // if none are found, use AVI codes
1215  if (par->codec_id != AV_CODEC_ID_RAWVIDEO || par->codec_tag) {
1216  for (j = 0; ff_mkv_codec_tags[j].id != AV_CODEC_ID_NONE; j++) {
1217  if (ff_mkv_codec_tags[j].id == par->codec_id && par->codec_id != AV_CODEC_ID_FFV1) {
1219  native_id = 1;
1220  break;
1221  }
1222  }
1223  } else {
1224  if (mkv->allow_raw_vfw) {
1225  native_id = 0;
1226  } else {
1227  av_log(s, AV_LOG_ERROR, "Raw RGB is not supported Natively in Matroska, you can use AVI or NUT or\n"
1228  "If you would like to store it anyway using VFW mode, enable allow_raw_vfw (-allow_raw_vfw 1)\n");
1229  return AVERROR(EINVAL);
1230  }
1231  }
1232  }
1233 
1234  if (par->codec_type == AVMEDIA_TYPE_AUDIO && par->initial_padding && par->codec_id == AV_CODEC_ID_OPUS) {
1235  int64_t codecdelay = av_rescale_q(par->initial_padding,
1236  (AVRational){ 1, 48000 },
1237  (AVRational){ 1, 1000000000 });
1238  if (codecdelay < 0) {
1239  av_log(s, AV_LOG_ERROR, "Initial padding is invalid\n");
1240  return AVERROR(EINVAL);
1241  }
1242 // mkv->tracks[i].ts_offset = av_rescale_q(par->initial_padding,
1243 // (AVRational){ 1, par->sample_rate },
1244 // st->time_base);
1245 
1246  put_ebml_uint(pb, MATROSKA_ID_CODECDELAY, codecdelay);
1247  }
1248  if (par->codec_id == AV_CODEC_ID_OPUS) {
1250  }
1251 
1252  switch (par->codec_type) {
1253  case AVMEDIA_TYPE_VIDEO:
1254  mkv->have_video = 1;
1256 
1257  if( st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0
1258  && av_cmp_q(av_inv_q(st->avg_frame_rate), st->time_base) > 0)
1260  else if( st->r_frame_rate.num > 0 && st->r_frame_rate.den > 0
1261  && av_cmp_q(av_inv_q(st->r_frame_rate), st->time_base) > 0)
1263 
1264  if (!native_id &&
1267  par->codec_id == AV_CODEC_ID_SVQ1 ||
1268  par->codec_id == AV_CODEC_ID_SVQ3 ||
1269  par->codec_id == AV_CODEC_ID_CINEPAK))
1270  qt_id = 1;
1271 
1272  if (qt_id)
1273  put_ebml_string(pb, MATROSKA_ID_CODECID, "V_QUICKTIME");
1274  else if (!native_id) {
1275  // if there is no mkv-specific codec ID, use VFW mode
1276  put_ebml_string(pb, MATROSKA_ID_CODECID, "V_MS/VFW/FOURCC");
1277  mkv->tracks[i].write_dts = 1;
1279  }
1280 
1281  subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKVIDEO, 0);
1282 
1285 
1286  mkv_write_field_order(pb, mkv->mode, par->field_order);
1287 
1288  // check both side data and metadata for stereo information,
1289  // write the result to the bitstream if any is found
1290  ret = mkv_write_stereo_mode(s, pb, st, mkv->mode,
1291  &display_width_div,
1292  &display_height_div);
1293  if (ret < 0)
1294  return ret;
1295 
1296  if (((tag = av_dict_get(st->metadata, "alpha_mode", NULL, 0)) && atoi(tag->value)) ||
1297  ((tag = av_dict_get( s->metadata, "alpha_mode", NULL, 0)) && atoi(tag->value)) ||
1298  (par->format == AV_PIX_FMT_YUVA420P)) {
1300  }
1301 
1302  // write DisplayWidth and DisplayHeight, they contain the size of
1303  // a single source view and/or the display aspect ratio
1304  if (st->sample_aspect_ratio.num) {
1305  int64_t d_width = av_rescale(par->width, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den);
1306  if (d_width > INT_MAX) {
1307  av_log(s, AV_LOG_ERROR, "Overflow in display width\n");
1308  return AVERROR(EINVAL);
1309  }
1310  if (d_width != par->width || display_width_div != 1 || display_height_div != 1) {
1311  if (mkv->mode == MODE_WEBM || display_width_div != 1 || display_height_div != 1) {
1312  put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , d_width / display_width_div);
1313  put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, par->height / display_height_div);
1314  } else {
1315  AVRational display_aspect_ratio;
1316  av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
1317  par->width * (int64_t)st->sample_aspect_ratio.num,
1318  par->height * (int64_t)st->sample_aspect_ratio.den,
1319  1024 * 1024);
1320  put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH, display_aspect_ratio.num);
1321  put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, display_aspect_ratio.den);
1323  }
1324  }
1325  } else if (display_width_div != 1 || display_height_div != 1) {
1326  put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , par->width / display_width_div);
1327  put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, par->height / display_height_div);
1328  } else if (mkv->mode != MODE_WEBM)
1330 
1331  if (par->codec_id == AV_CODEC_ID_RAWVIDEO) {
1332  uint32_t color_space = av_le2ne32(par->codec_tag);
1333  put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLORSPACE, &color_space, sizeof(color_space));
1334  }
1335  ret = mkv_write_video_color(pb, par, st);
1336  if (ret < 0)
1337  return ret;
1338  ret = mkv_write_video_projection(s, pb, st);
1339  if (ret < 0)
1340  return ret;
1341  end_ebml_master(pb, subinfo);
1342  break;
1343 
1344  case AVMEDIA_TYPE_AUDIO:
1346 
1347  if (!native_id)
1348  // no mkv-specific ID, use ACM mode
1349  put_ebml_string(pb, MATROSKA_ID_CODECID, "A_MS/ACM");
1350 
1351  subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKAUDIO, 0);
1353 
1354  mkv->tracks[i].sample_rate_offset = avio_tell(pb);
1355  put_ebml_float (pb, MATROSKA_ID_AUDIOSAMPLINGFREQ, sample_rate);
1356  if (output_sample_rate)
1357  put_ebml_float(pb, MATROSKA_ID_AUDIOOUTSAMPLINGFREQ, output_sample_rate);
1358  if (bit_depth)
1359  put_ebml_uint(pb, MATROSKA_ID_AUDIOBITDEPTH, bit_depth);
1360  end_ebml_master(pb, subinfo);
1361  break;
1362 
1363  case AVMEDIA_TYPE_SUBTITLE:
1364  if (!native_id) {
1365  av_log(s, AV_LOG_ERROR, "Subtitle codec %d is not supported.\n", par->codec_id);
1366  return AVERROR(ENOSYS);
1367  }
1368 
1369  if (mkv->mode != MODE_WEBM || par->codec_id != AV_CODEC_ID_WEBVTT)
1370  native_id = MATROSKA_TRACK_TYPE_SUBTITLE;
1371 
1372  put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, native_id);
1373  break;
1374  default:
1375  av_log(s, AV_LOG_ERROR, "Only audio, video, and subtitles are supported for Matroska.\n");
1376  return AVERROR(EINVAL);
1377  }
1378 
1379  if (mkv->mode != MODE_WEBM || par->codec_id != AV_CODEC_ID_WEBVTT) {
1380  mkv->tracks[i].codecpriv_offset = avio_tell(pb);
1381  ret = mkv_write_codecprivate(s, pb, par, native_id, qt_id);
1382  if (ret < 0)
1383  return ret;
1384  }
1385 
1386  end_ebml_master(pb, track);
1387 
1388  return 0;
1389 }
1390 
1392 {
1393  MatroskaMuxContext *mkv = s->priv_data;
1394  AVIOContext *pb = s->pb;
1395  int i, ret, default_stream_exists = 0;
1396 
1398 
1399  ret = start_ebml_master_crc32(pb, &mkv->tracks_bc, mkv, MATROSKA_ID_TRACKS);
1400  if (ret < 0)
1401  return ret;
1402 
1403  for (i = 0; i < s->nb_streams; i++) {
1404  AVStream *st = s->streams[i];
1405  default_stream_exists |= st->disposition & AV_DISPOSITION_DEFAULT;
1406  }
1407  for (i = 0; i < s->nb_streams; i++) {
1408  ret = mkv_write_track(s, mkv, i, mkv->tracks_bc, default_stream_exists);
1409  if (ret < 0)
1410  return ret;
1411  }
1412 
1413  if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live)
1415  else
1416  end_ebml_master_crc32(pb, &mkv->tracks_bc, mkv);
1417 
1418  return 0;
1419 }
1420 
1422 {
1423  MatroskaMuxContext *mkv = s->priv_data;
1424  AVIOContext *dyn_cp, *pb = s->pb;
1425  ebml_master editionentry;
1426  AVRational scale = {1, 1E9};
1427  int i, ret;
1428 
1429  if (!s->nb_chapters || mkv->wrote_chapters)
1430  return 0;
1431 
1433 
1434  ret = start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_CHAPTERS);
1435  if (ret < 0) return ret;
1436 
1437  editionentry = start_ebml_master(dyn_cp, MATROSKA_ID_EDITIONENTRY, 0);
1438  if (mkv->mode != MODE_WEBM) {
1441  }
1442  for (i = 0; i < s->nb_chapters; i++) {
1443  ebml_master chapteratom, chapterdisplay;
1444  AVChapter *c = s->chapters[i];
1445  int64_t chapterstart = av_rescale_q(c->start, c->time_base, scale);
1446  int64_t chapterend = av_rescale_q(c->end, c->time_base, scale);
1447  AVDictionaryEntry *t = NULL;
1448  if (chapterstart < 0 || chapterstart > chapterend || chapterend < 0) {
1449  av_log(s, AV_LOG_ERROR,
1450  "Invalid chapter start (%"PRId64") or end (%"PRId64").\n",
1451  chapterstart, chapterend);
1452  return AVERROR_INVALIDDATA;
1453  }
1454 
1455  chapteratom = start_ebml_master(dyn_cp, MATROSKA_ID_CHAPTERATOM, 0);
1457  put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERTIMESTART, chapterstart);
1458  put_ebml_uint(dyn_cp, MATROSKA_ID_CHAPTERTIMEEND, chapterend);
1459  if (mkv->mode != MODE_WEBM) {
1462  }
1463  if ((t = av_dict_get(c->metadata, "title", NULL, 0))) {
1464  chapterdisplay = start_ebml_master(dyn_cp, MATROSKA_ID_CHAPTERDISPLAY, 0);
1466  put_ebml_string(dyn_cp, MATROSKA_ID_CHAPLANG , "und");
1467  end_ebml_master(dyn_cp, chapterdisplay);
1468  }
1469  end_ebml_master(dyn_cp, chapteratom);
1470  }
1471  end_ebml_master(dyn_cp, editionentry);
1472  end_ebml_master_crc32(pb, &dyn_cp, mkv);
1473 
1474  mkv->wrote_chapters = 1;
1475  return 0;
1476 }
1477 
1479 {
1480  uint8_t *key = av_strdup(t->key);
1481  uint8_t *p = key;
1482  const uint8_t *lang = NULL;
1483  ebml_master tag;
1484 
1485  if (!key)
1486  return AVERROR(ENOMEM);
1487 
1488  if ((p = strrchr(p, '-')) &&
1489  (lang = ff_convert_lang_to(p + 1, AV_LANG_ISO639_2_BIBL)))
1490  *p = 0;
1491 
1492  p = key;
1493  while (*p) {
1494  if (*p == ' ')
1495  *p = '_';
1496  else if (*p >= 'a' && *p <= 'z')
1497  *p -= 'a' - 'A';
1498  p++;
1499  }
1500 
1503  if (lang)
1506  end_ebml_master(pb, tag);
1507 
1508  av_freep(&key);
1509  return 0;
1510 }
1511 
1512 static int mkv_write_tag_targets(AVFormatContext *s, uint32_t elementid,
1513  unsigned int uid, ebml_master *tag)
1514 {
1515  AVIOContext *pb;
1516  MatroskaMuxContext *mkv = s->priv_data;
1518  int ret;
1519 
1520  if (!mkv->tags_bc) {
1522 
1523  ret = start_ebml_master_crc32(s->pb, &mkv->tags_bc, mkv, MATROSKA_ID_TAGS);
1524  if (ret < 0)
1525  return ret;
1526  }
1527  pb = mkv->tags_bc;
1528 
1529  *tag = start_ebml_master(pb, MATROSKA_ID_TAG, 0);
1530  targets = start_ebml_master(pb, MATROSKA_ID_TAGTARGETS, 0);
1531  if (elementid)
1532  put_ebml_uint(pb, elementid, uid);
1533  end_ebml_master(pb, targets);
1534  return 0;
1535 }
1536 
1537 static int mkv_check_tag_name(const char *name, uint32_t elementid)
1538 {
1539  return av_strcasecmp(name, "title") &&
1540  av_strcasecmp(name, "stereo_mode") &&
1541  av_strcasecmp(name, "creation_time") &&
1542  av_strcasecmp(name, "encoding_tool") &&
1543  av_strcasecmp(name, "duration") &&
1544  (elementid != MATROSKA_ID_TAGTARGETS_TRACKUID ||
1545  av_strcasecmp(name, "language")) &&
1546  (elementid != MATROSKA_ID_TAGTARGETS_ATTACHUID ||
1547  (av_strcasecmp(name, "filename") &&
1548  av_strcasecmp(name, "mimetype")));
1549 }
1550 
1551 static int mkv_write_tag(AVFormatContext *s, AVDictionary *m, uint32_t elementid,
1552  unsigned int uid)
1553 {
1554  MatroskaMuxContext *mkv = s->priv_data;
1555  ebml_master tag;
1556  int ret;
1557  AVDictionaryEntry *t = NULL;
1558 
1559  ret = mkv_write_tag_targets(s, elementid, uid, &tag);
1560  if (ret < 0)
1561  return ret;
1562 
1563  while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX))) {
1564  if (mkv_check_tag_name(t->key, elementid)) {
1565  ret = mkv_write_simpletag(mkv->tags_bc, t);
1566  if (ret < 0)
1567  return ret;
1568  }
1569  }
1570 
1571  end_ebml_master(mkv->tags_bc, tag);
1572  return 0;
1573 }
1574 
1575 static int mkv_check_tag(AVDictionary *m, uint32_t elementid)
1576 {
1577  AVDictionaryEntry *t = NULL;
1578 
1579  while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX)))
1580  if (mkv_check_tag_name(t->key, elementid))
1581  return 1;
1582 
1583  return 0;
1584 }
1585 
1587 {
1588  MatroskaMuxContext *mkv = s->priv_data;
1589  int i, ret;
1590 
1592 
1593  if (mkv_check_tag(s->metadata, 0)) {
1594  ret = mkv_write_tag(s, s->metadata, 0, 0);
1595  if (ret < 0) return ret;
1596  }
1597 
1598  for (i = 0; i < s->nb_streams; i++) {
1599  AVStream *st = s->streams[i];
1600 
1602  continue;
1603 
1605  continue;
1606 
1608  if (ret < 0) return ret;
1609  }
1610 
1611  if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) {
1612  for (i = 0; i < s->nb_streams; i++) {
1613  AVIOContext *pb;
1614  AVStream *st = s->streams[i];
1615  ebml_master tag_target;
1616  ebml_master tag;
1617 
1619  continue;
1620 
1622  i + 1, &tag_target);
1623  if (ret < 0)
1624  return ret;
1625  pb = mkv->tags_bc;
1626 
1628  put_ebml_string(pb, MATROSKA_ID_TAGNAME, "DURATION");
1629  mkv->tracks[i].duration_offset = avio_tell(pb);
1630 
1631  // Reserve space to write duration as a 20-byte string.
1632  // 2 (ebml id) + 1 (data size) + 20 (data)
1633  put_ebml_void(pb, 23);
1634  end_ebml_master(pb, tag);
1635  end_ebml_master(pb, tag_target);
1636  }
1637  }
1638 
1639  if (mkv->mode != MODE_WEBM) {
1640  for (i = 0; i < s->nb_chapters; i++) {
1641  AVChapter *ch = s->chapters[i];
1642 
1644  continue;
1645 
1647  if (ret < 0)
1648  return ret;
1649  }
1650  }
1651 
1652  if (mkv->have_attachments && mkv->mode != MODE_WEBM) {
1653  for (i = 0; i < mkv->attachments->num_entries; i++) {
1654  mkv_attachment *attachment = &mkv->attachments->entries[i];
1655  AVStream *st = s->streams[attachment->stream_idx];
1656 
1658  continue;
1659 
1660  ret = mkv_write_tag(s, st->metadata, MATROSKA_ID_TAGTARGETS_ATTACHUID, attachment->fileuid);
1661  if (ret < 0)
1662  return ret;
1663  }
1664  }
1665 
1666  if (mkv->tags_bc) {
1667  if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live)
1668  end_ebml_master_crc32_preliminary(s->pb, &mkv->tags_bc, mkv, &mkv->tags_pos);
1669  else
1670  end_ebml_master_crc32(s->pb, &mkv->tags_bc, mkv);
1671  }
1672  return 0;
1673 }
1674 
1676 {
1677  MatroskaMuxContext *mkv = s->priv_data;
1678  AVIOContext *dyn_cp, *pb = s->pb;
1679  AVLFG c;
1680  int i, ret;
1681 
1682  if (!mkv->have_attachments)
1683  return 0;
1684 
1685  mkv->attachments = av_mallocz(sizeof(*mkv->attachments));
1686  if (!mkv->attachments)
1687  return AVERROR(ENOMEM);
1688 
1690 
1692 
1693  ret = start_ebml_master_crc32(pb, &dyn_cp, mkv, MATROSKA_ID_ATTACHMENTS);
1694  if (ret < 0) return ret;
1695 
1696  for (i = 0; i < s->nb_streams; i++) {
1697  AVStream *st = s->streams[i];
1698  ebml_master attached_file;
1699  mkv_attachment *attachment = mkv->attachments->entries;
1700  AVDictionaryEntry *t;
1701  const char *mimetype = NULL;
1702  uint32_t fileuid;
1703 
1705  continue;
1706 
1707  attachment = av_realloc_array(attachment, mkv->attachments->num_entries + 1, sizeof(mkv_attachment));
1708  if (!attachment)
1709  return AVERROR(ENOMEM);
1710  mkv->attachments->entries = attachment;
1711 
1712  attached_file = start_ebml_master(dyn_cp, MATROSKA_ID_ATTACHEDFILE, 0);
1713 
1714  if (t = av_dict_get(st->metadata, "title", NULL, 0))
1716  if (!(t = av_dict_get(st->metadata, "filename", NULL, 0))) {
1717  av_log(s, AV_LOG_ERROR, "Attachment stream %d has no filename tag.\n", i);
1718  return AVERROR(EINVAL);
1719  }
1721  if (t = av_dict_get(st->metadata, "mimetype", NULL, 0))
1722  mimetype = t->value;
1723  else if (st->codecpar->codec_id != AV_CODEC_ID_NONE ) {
1724  int i;
1725  for (i = 0; ff_mkv_mime_tags[i].id != AV_CODEC_ID_NONE; i++)
1726  if (ff_mkv_mime_tags[i].id == st->codecpar->codec_id) {
1727  mimetype = ff_mkv_mime_tags[i].str;
1728  break;
1729  }
1730  for (i = 0; ff_mkv_image_mime_tags[i].id != AV_CODEC_ID_NONE; i++)
1731  if (ff_mkv_image_mime_tags[i].id == st->codecpar->codec_id) {
1732  mimetype = ff_mkv_image_mime_tags[i].str;
1733  break;
1734  }
1735  }
1736  if (!mimetype) {
1737  av_log(s, AV_LOG_ERROR, "Attachment stream %d has no mimetype tag and "
1738  "it cannot be deduced from the codec id.\n", i);
1739  return AVERROR(EINVAL);
1740  }
1741 
1742  if (s->flags & AVFMT_FLAG_BITEXACT) {
1743  struct AVSHA *sha = av_sha_alloc();
1744  uint8_t digest[20];
1745  if (!sha)
1746  return AVERROR(ENOMEM);
1747  av_sha_init(sha, 160);
1749  av_sha_final(sha, digest);
1750  av_free(sha);
1751  fileuid = AV_RL32(digest);
1752  } else {
1753  fileuid = av_lfg_get(&c);
1754  }
1755  av_log(s, AV_LOG_VERBOSE, "Using %.8"PRIx32" for attachment %d\n",
1756  fileuid, mkv->attachments->num_entries);
1757 
1758  put_ebml_string(dyn_cp, MATROSKA_ID_FILEMIMETYPE, mimetype);
1760  put_ebml_uint(dyn_cp, MATROSKA_ID_FILEUID, fileuid);
1761  end_ebml_master(dyn_cp, attached_file);
1762 
1764  mkv->attachments->entries[mkv->attachments->num_entries++].fileuid = fileuid;
1765  }
1766  end_ebml_master_crc32(pb, &dyn_cp, mkv);
1767 
1768  return 0;
1769 }
1770 
1772 {
1773  int i = 0;
1774  int64_t max = 0;
1775  int64_t us;
1776 
1777  AVDictionaryEntry *explicitDuration = av_dict_get(s->metadata, "DURATION", NULL, 0);
1778  if (explicitDuration && (av_parse_time(&us, explicitDuration->value, 1) == 0) && us > 0) {
1779  av_log(s, AV_LOG_DEBUG, "get_metadata_duration found duration in context metadata: %" PRId64 "\n", us);
1780  return us;
1781  }
1782 
1783  for (i = 0; i < s->nb_streams; i++) {
1784  int64_t us;
1785  AVDictionaryEntry *duration = av_dict_get(s->streams[i]->metadata, "DURATION", NULL, 0);
1786 
1787  if (duration && (av_parse_time(&us, duration->value, 1) == 0))
1788  max = FFMAX(max, us);
1789  }
1790 
1791  av_log(s, AV_LOG_DEBUG, "get_metadata_duration returned: %" PRId64 "\n", max);
1792  return max;
1793 }
1794 
1796 {
1797  MatroskaMuxContext *mkv = s->priv_data;
1798  AVIOContext *pb = s->pb;
1801  int ret, i, version = 2;
1802  int64_t creation_time;
1803 
1804  if (!strcmp(s->oformat->name, "webm")) {
1805  mkv->mode = MODE_WEBM;
1806  mkv->write_crc = 0;
1807  } else
1808  mkv->mode = MODE_MATROSKAv2;
1809 
1810  if (mkv->mode != MODE_WEBM ||
1811  av_dict_get(s->metadata, "stereo_mode", NULL, 0) ||
1812  av_dict_get(s->metadata, "alpha_mode", NULL, 0))
1813  version = 4;
1814 
1815  for (i = 0; i < s->nb_streams; i++) {
1816  if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_OPUS ||
1817  av_dict_get(s->streams[i]->metadata, "stereo_mode", NULL, 0) ||
1818  av_dict_get(s->streams[i]->metadata, "alpha_mode", NULL, 0))
1819  version = 4;
1820  }
1821 
1822  mkv->tracks = av_mallocz_array(s->nb_streams, sizeof(*mkv->tracks));
1823  if (!mkv->tracks) {
1824  return AVERROR(ENOMEM);
1825  }
1832  put_ebml_uint (pb, EBML_ID_DOCTYPEVERSION , version);
1834  end_ebml_master(pb, ebml_header);
1835 
1837  mkv->segment_offset = avio_tell(pb);
1838 
1839  // we write a seek head at the beginning to point to all other level
1840  // one elements (except Clusters).
1841  mkv_start_seekhead(mkv, pb);
1842 
1844 
1845  ret = start_ebml_master_crc32(pb, &mkv->info_bc, mkv, MATROSKA_ID_INFO);
1846  if (ret < 0)
1847  return ret;
1848  pb = mkv->info_bc;
1849 
1851  if ((tag = av_dict_get(s->metadata, "title", NULL, 0)))
1853  if (!(s->flags & AVFMT_FLAG_BITEXACT)) {
1855  if ((tag = av_dict_get(s->metadata, "encoding_tool", NULL, 0)))
1857  else
1859 
1860  if (mkv->mode != MODE_WEBM) {
1861  uint32_t segment_uid[4];
1862  AVLFG lfg;
1863 
1865 
1866  for (i = 0; i < 4; i++)
1867  segment_uid[i] = av_lfg_get(&lfg);
1868 
1869  put_ebml_binary(pb, MATROSKA_ID_SEGMENTUID, segment_uid, 16);
1870  }
1871  } else {
1872  const char *ident = "Lavf";
1875  }
1876 
1877  if (ff_parse_creation_time_metadata(s, &creation_time, 0) > 0) {
1878  // Adjust time so it's relative to 2001-01-01 and convert to nanoseconds.
1879  int64_t date_utc = (creation_time - 978307200000000LL) * 1000;
1880  uint8_t date_utc_buf[8];
1881  AV_WB64(date_utc_buf, date_utc);
1882  put_ebml_binary(pb, MATROSKA_ID_DATEUTC, date_utc_buf, 8);
1883  }
1884 
1885  // reserve space for the duration
1886  mkv->duration = 0;
1887  mkv->duration_offset = avio_tell(pb);
1888  if (!mkv->is_live) {
1889  int64_t metadata_duration = get_metadata_duration(s);
1890 
1891  if (s->duration > 0) {
1892  int64_t scaledDuration = av_rescale(s->duration, 1000, AV_TIME_BASE);
1893  put_ebml_float(pb, MATROSKA_ID_DURATION, scaledDuration);
1894  av_log(s, AV_LOG_DEBUG, "Write early duration from recording time = %" PRIu64 "\n", scaledDuration);
1895  } else if (metadata_duration > 0) {
1896  int64_t scaledDuration = av_rescale(metadata_duration, 1000, AV_TIME_BASE);
1897  put_ebml_float(pb, MATROSKA_ID_DURATION, scaledDuration);
1898  av_log(s, AV_LOG_DEBUG, "Write early duration from metadata = %" PRIu64 "\n", scaledDuration);
1899  } else {
1900  put_ebml_void(pb, 11); // assumes double-precision float to be written
1901  }
1902  }
1903  if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live)
1904  end_ebml_master_crc32_preliminary(s->pb, &mkv->info_bc, mkv, &mkv->info_pos);
1905  else
1906  end_ebml_master_crc32(s->pb, &mkv->info_bc, mkv);
1907  pb = s->pb;
1908 
1909  ret = mkv_write_tracks(s);
1910  if (ret < 0)
1911  return ret;
1912 
1913  for (i = 0; i < s->nb_chapters; i++)
1914  mkv->chapter_id_offset = FFMAX(mkv->chapter_id_offset, 1LL - s->chapters[i]->id);
1915 
1916  ret = mkv_write_chapters(s);
1917  if (ret < 0)
1918  return ret;
1919 
1920  if (mkv->mode != MODE_WEBM) {
1921  ret = mkv_write_attachments(s);
1922  if (ret < 0)
1923  return ret;
1924  }
1925 
1926  ret = mkv_write_tags(s);
1927  if (ret < 0)
1928  return ret;
1929 
1930  if (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live)
1931  mkv_write_seekhead(pb, mkv);
1932 
1933  mkv->cues = mkv_start_cues(mkv->segment_offset);
1934  if (!mkv->cues) {
1935  return AVERROR(ENOMEM);
1936  }
1937 
1938  if (s->metadata_header_padding > 0) {
1939  if (s->metadata_header_padding == 1)
1942  }
1943 
1944  if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && mkv->reserve_cues_space) {
1945  mkv->cues_pos = avio_tell(pb);
1946  if (mkv->reserve_cues_space == 1)
1947  mkv->reserve_cues_space++;
1949  }
1950 
1952  mkv->cur_audio_pkt.size = 0;
1953  mkv->cluster_pos = -1;
1954 
1955  // start a new cluster every 5 MB or 5 sec, or 32k / 1 sec for streaming or
1956  // after 4k and on a keyframe
1957  if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
1958  if (mkv->cluster_time_limit < 0)
1959  mkv->cluster_time_limit = 5000;
1960  if (mkv->cluster_size_limit < 0)
1961  mkv->cluster_size_limit = 5 * 1024 * 1024;
1962  } else {
1963  if (mkv->cluster_time_limit < 0)
1964  mkv->cluster_time_limit = 1000;
1965  if (mkv->cluster_size_limit < 0)
1966  mkv->cluster_size_limit = 32 * 1024;
1967  }
1968 
1969  return 0;
1970 }
1971 
1972 static int mkv_blockgroup_size(int pkt_size)
1973 {
1974  int size = pkt_size + 4;
1975  size += ebml_num_size(size);
1976  size += 2; // EBML ID for block and block duration
1977  size += 9; // max size of block duration incl. length field
1978  return size;
1979 }
1980 
1981 static int mkv_strip_wavpack(const uint8_t *src, uint8_t **pdst, int *size)
1982 {
1983  uint8_t *dst;
1984  int srclen = *size;
1985  int offset = 0;
1986  int ret;
1987 
1988  dst = av_malloc(srclen);
1989  if (!dst)
1990  return AVERROR(ENOMEM);
1991 
1992  while (srclen >= WV_HEADER_SIZE) {
1993  WvHeader header;
1994 
1995  ret = ff_wv_parse_header(&header, src);
1996  if (ret < 0)
1997  goto fail;
1998  src += WV_HEADER_SIZE;
1999  srclen -= WV_HEADER_SIZE;
2000 
2001  if (srclen < header.blocksize) {
2002  ret = AVERROR_INVALIDDATA;
2003  goto fail;
2004  }
2005 
2006  if (header.initial) {
2007  AV_WL32(dst + offset, header.samples);
2008  offset += 4;
2009  }
2010  AV_WL32(dst + offset, header.flags);
2011  AV_WL32(dst + offset + 4, header.crc);
2012  offset += 8;
2013 
2014  if (!(header.initial && header.final)) {
2015  AV_WL32(dst + offset, header.blocksize);
2016  offset += 4;
2017  }
2018 
2019  memcpy(dst + offset, src, header.blocksize);
2020  src += header.blocksize;
2021  srclen -= header.blocksize;
2022  offset += header.blocksize;
2023  }
2024 
2025  *pdst = dst;
2026  *size = offset;
2027 
2028  return 0;
2029 fail:
2030  av_freep(&dst);
2031  return ret;
2032 }
2033 
2035  uint32_t blockid, AVPacket *pkt, int keyframe)
2036 {
2037  MatroskaMuxContext *mkv = s->priv_data;
2039  mkv_track *track = &mkv->tracks[pkt->stream_index];
2040  uint8_t *data = NULL, *side_data = NULL;
2041  int err = 0, offset = 0, size = pkt->size, side_data_size = 0;
2042  int64_t ts = track->write_dts ? pkt->dts : pkt->pts;
2043  uint64_t additional_id = 0;
2044  int64_t discard_padding = 0;
2045  uint8_t track_number = (mkv->is_dash ? mkv->dash_track_number : (pkt->stream_index + 1));
2046  ebml_master block_group, block_additions, block_more;
2047 
2048  ts += track->ts_offset;
2049 
2050  /* The following string is identical to the one in mkv_write_vtt_blocks
2051  * so that only one copy needs to exist in binaries. */
2052  av_log(s, AV_LOG_DEBUG,
2053  "Writing block of size %d with pts %" PRId64 ", dts %" PRId64 ", "
2054  "duration %" PRId64 " at relative offset %" PRId64 " in cluster "
2055  "at offset %" PRId64 ". TrackNumber %d, keyframe %d\n",
2056  pkt->size, pkt->pts, pkt->dts, pkt->duration, avio_tell(pb),
2057  mkv->cluster_pos, track_number, keyframe != 0);
2058 
2059  if (par->codec_id == AV_CODEC_ID_H264 && par->extradata_size > 0 &&
2060  (AV_RB24(par->extradata) == 1 || AV_RB32(par->extradata) == 1)) {
2061  err = ff_avc_parse_nal_units_buf(pkt->data, &data, &size);
2062  } else if (par->codec_id == AV_CODEC_ID_HEVC && par->extradata_size > 6 &&
2063  (AV_RB24(par->extradata) == 1 || AV_RB32(par->extradata) == 1)) {
2064  /* extradata is Annex B, assume the bitstream is too and convert it */
2065  err = ff_hevc_annexb2mp4_buf(pkt->data, &data, &size, 0, NULL);
2066  } else if (par->codec_id == AV_CODEC_ID_AV1) {
2067  err = ff_av1_filter_obus_buf(pkt->data, &data, &size, &offset);
2068  } else if (par->codec_id == AV_CODEC_ID_WAVPACK) {
2069  err = mkv_strip_wavpack(pkt->data, &data, &size);
2070  } else
2071  data = pkt->data;
2072 
2073  if (err < 0) {
2074  av_log(s, AV_LOG_ERROR, "Error when reformatting data of "
2075  "a packet from stream %d.\n", pkt->stream_index);
2076  return err;
2077  }
2078 
2079  if (par->codec_id == AV_CODEC_ID_PRORES && size >= 8) {
2080  /* Matroska specification requires to remove the first QuickTime atom
2081  */
2082  size -= 8;
2083  offset = 8;
2084  }
2085 
2086  side_data = av_packet_get_side_data(pkt,
2088  &side_data_size);
2089  if (side_data && side_data_size >= 10) {
2090  discard_padding = av_rescale_q(AV_RL32(side_data + 4),
2091  (AVRational){1, par->sample_rate},
2092  (AVRational){1, 1000000000});
2093  }
2094 
2095  side_data = av_packet_get_side_data(pkt,
2097  &side_data_size);
2098  if (side_data) {
2099  if (side_data_size < 8) {
2100  side_data_size = 0;
2101  } else {
2102  additional_id = AV_RB64(side_data);
2103  side_data += 8;
2104  side_data_size -= 8;
2105  }
2106  }
2107 
2108  if ((side_data_size && additional_id == 1) || discard_padding) {
2109  block_group = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP, 0);
2110  blockid = MATROSKA_ID_BLOCK;
2111  }
2112 
2113  put_ebml_id(pb, blockid);
2114  put_ebml_num(pb, size + 4, 0);
2115  // this assumes stream_index is less than 126
2116  avio_w8(pb, 0x80 | track_number);
2117  avio_wb16(pb, ts - mkv->cluster_pts);
2118  avio_w8(pb, (blockid == MATROSKA_ID_SIMPLEBLOCK && keyframe) ? (1 << 7) : 0);
2119  avio_write(pb, data + offset, size);
2120  if (data != pkt->data)
2121  av_free(data);
2122 
2123  if (blockid == MATROSKA_ID_BLOCK && !keyframe) {
2125  }
2126  track->last_timestamp = ts;
2127 
2128  if (discard_padding) {
2129  put_ebml_sint(pb, MATROSKA_ID_DISCARDPADDING, discard_padding);
2130  }
2131 
2132  if (side_data_size && additional_id == 1) {
2133  block_additions = start_ebml_master(pb, MATROSKA_ID_BLOCKADDITIONS, 0);
2134  block_more = start_ebml_master(pb, MATROSKA_ID_BLOCKMORE, 0);
2137  put_ebml_num(pb, side_data_size, 0);
2138  avio_write(pb, side_data, side_data_size);
2139  end_ebml_master(pb, block_more);
2140  end_ebml_master(pb, block_additions);
2141  }
2142  if ((side_data_size && additional_id == 1) || discard_padding) {
2143  end_ebml_master(pb, block_group);
2144  }
2145 
2146  return 0;
2147 }
2148 
2150 {
2151  MatroskaMuxContext *mkv = s->priv_data;
2152  ebml_master blockgroup;
2153  int id_size, settings_size, size;
2154  uint8_t *id, *settings;
2155  int64_t ts = mkv->tracks[pkt->stream_index].write_dts ? pkt->dts : pkt->pts;
2156  const int flags = 0;
2157 
2158  id_size = 0;
2160  &id_size);
2161 
2162  settings_size = 0;
2164  &settings_size);
2165 
2166  size = id_size + 1 + settings_size + 1 + pkt->size;
2167 
2168  /* The following string is identical to the one in mkv_write_block so that
2169  * only one copy needs to exist in binaries. */
2170  av_log(s, AV_LOG_DEBUG,
2171  "Writing block of size %d with pts %" PRId64 ", dts %" PRId64 ", "
2172  "duration %" PRId64 " at relative offset %" PRId64 " in cluster "
2173  "at offset %" PRId64 ". TrackNumber %d, keyframe %d\n",
2174  size, pkt->pts, pkt->dts, pkt->duration, avio_tell(pb),
2175  mkv->cluster_pos, pkt->stream_index + 1, 1);
2176 
2178 
2180  put_ebml_num(pb, size + 4, 0);
2181  avio_w8(pb, 0x80 | (pkt->stream_index + 1)); // this assumes stream_index is less than 126
2182  avio_wb16(pb, ts - mkv->cluster_pts);
2183  avio_w8(pb, flags);
2184  avio_printf(pb, "%.*s\n%.*s\n%.*s", id_size, id, settings_size, settings, pkt->size, pkt->data);
2185 
2187  end_ebml_master(pb, blockgroup);
2188 
2189  return pkt->duration;
2190 }
2191 
2193 {
2194  MatroskaMuxContext *mkv = s->priv_data;
2195 
2196  end_ebml_master_crc32(s->pb, &mkv->cluster_bc, mkv);
2197  mkv->cluster_pos = -1;
2199 }
2200 
2202 {
2203  MatroskaMuxContext *mkv = s->priv_data;
2204  mkv_track *track = &mkv->tracks[pkt->stream_index];
2206  uint8_t *side_data;
2207  int side_data_size = 0, ret;
2208 
2210  &side_data_size);
2211 
2212  switch (par->codec_id) {
2213  case AV_CODEC_ID_AAC:
2214  if (side_data_size && (s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) {
2215  int filler, output_sample_rate = 0;
2216  int64_t curpos;
2217  ret = get_aac_sample_rates(s, side_data, side_data_size, &track->sample_rate,
2218  &output_sample_rate);
2219  if (ret < 0)
2220  return ret;
2221  if (!output_sample_rate)
2222  output_sample_rate = track->sample_rate; // Space is already reserved, so it's this or a void element.
2223  ret = ff_alloc_extradata(par, side_data_size);
2224  if (ret < 0)
2225  return ret;
2226  memcpy(par->extradata, side_data, side_data_size);
2227  curpos = avio_tell(mkv->tracks_bc);
2228  avio_seek(mkv->tracks_bc, track->codecpriv_offset, SEEK_SET);
2229  mkv_write_codecprivate(s, mkv->tracks_bc, par, 1, 0);
2230  filler = MAX_PCE_SIZE + 2 + 4 - (avio_tell(mkv->tracks_bc) - track->codecpriv_offset);
2231  if (filler)
2232  put_ebml_void(mkv->tracks_bc, filler);
2233  avio_seek(mkv->tracks_bc, track->sample_rate_offset, SEEK_SET);
2235  put_ebml_float(mkv->tracks_bc, MATROSKA_ID_AUDIOOUTSAMPLINGFREQ, output_sample_rate);
2236  avio_seek(mkv->tracks_bc, curpos, SEEK_SET);
2237  } else if (!par->extradata_size && !track->sample_rate) {
2238  // No extradata (codecpar or packet side data).
2239  av_log(s, AV_LOG_ERROR, "Error parsing AAC extradata, unable to determine samplerate.\n");
2240  return AVERROR(EINVAL);
2241  }
2242  break;
2243  case AV_CODEC_ID_FLAC:
2244  if (side_data_size && (s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) {
2245  AVCodecParameters *codecpriv_par;
2246  int64_t curpos;
2247  if (side_data_size != par->extradata_size) {
2248  av_log(s, AV_LOG_ERROR, "Invalid FLAC STREAMINFO metadata for output stream %d\n",
2249  pkt->stream_index);
2250  return AVERROR(EINVAL);
2251  }
2252  codecpriv_par = avcodec_parameters_alloc();
2253  if (!codecpriv_par)
2254  return AVERROR(ENOMEM);
2255  ret = avcodec_parameters_copy(codecpriv_par, par);
2256  if (ret < 0) {
2257  avcodec_parameters_free(&codecpriv_par);
2258  return ret;
2259  }
2260  memcpy(codecpriv_par->extradata, side_data, side_data_size);
2261  curpos = avio_tell(mkv->tracks_bc);
2262  avio_seek(mkv->tracks_bc, track->codecpriv_offset, SEEK_SET);
2263  mkv_write_codecprivate(s, mkv->tracks_bc, codecpriv_par, 1, 0);
2264  avio_seek(mkv->tracks_bc, curpos, SEEK_SET);
2265  avcodec_parameters_free(&codecpriv_par);
2266  }
2267  break;
2268  // FIXME: Remove the following once libaom starts propagating extradata during init()
2269  // See https://bugs.chromium.org/p/aomedia/issues/detail?id=2012
2270  case AV_CODEC_ID_AV1:
2271  if (side_data_size && (s->pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live &&
2272  !par->extradata_size) {
2273  AVIOContext *dyn_cp;
2274  uint8_t *codecpriv;
2275  int codecpriv_size;
2276  int64_t curpos;
2277  ret = avio_open_dyn_buf(&dyn_cp);
2278  if (ret < 0)
2279  return ret;
2280  ff_isom_write_av1c(dyn_cp, side_data, side_data_size);
2281  codecpriv_size = avio_close_dyn_buf(dyn_cp, &codecpriv);
2282  if (!codecpriv_size) {
2283  av_free(codecpriv);
2284  return AVERROR_INVALIDDATA;
2285  }
2286  curpos = avio_tell(mkv->tracks_bc);
2287  avio_seek(mkv->tracks_bc, track->codecpriv_offset, SEEK_SET);
2288  // Do not write the OBUs as we don't have space saved for them
2289  put_ebml_binary(mkv->tracks_bc, MATROSKA_ID_CODECPRIVATE, codecpriv, 4);
2290  av_free(codecpriv);
2291  avio_seek(mkv->tracks_bc, curpos, SEEK_SET);
2292  ret = ff_alloc_extradata(par, side_data_size);
2293  if (ret < 0)
2294  return ret;
2295  memcpy(par->extradata, side_data, side_data_size);
2296  } else if (!par->extradata_size)
2297  return AVERROR_INVALIDDATA;
2298  break;
2299  default:
2300  if (side_data_size)
2301  av_log(s, AV_LOG_DEBUG, "Ignoring new extradata in a packet for stream %d.\n", pkt->stream_index);
2302  break;
2303  }
2304 
2305  return 0;
2306 }
2307 
2309 {
2310  MatroskaMuxContext *mkv = s->priv_data;
2311  AVIOContext *pb;
2313  mkv_track *track = &mkv->tracks[pkt->stream_index];
2314  int keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY);
2315  int duration = pkt->duration;
2316  int ret;
2317  int64_t ts = track->write_dts ? pkt->dts : pkt->pts;
2318  int64_t relative_packet_pos;
2319  int tracknum = mkv->is_dash ? mkv->dash_track_number : pkt->stream_index + 1;
2320 
2321  if (ts == AV_NOPTS_VALUE) {
2322  av_log(s, AV_LOG_ERROR, "Can't write packet with unknown timestamp\n");
2323  return AVERROR(EINVAL);
2324  }
2325  ts += track->ts_offset;
2326 
2327  if (mkv->cluster_pos != -1) {
2328  int64_t cluster_time = ts - mkv->cluster_pts;
2329  if ((int16_t)cluster_time != cluster_time) {
2330  mkv_end_cluster(s);
2331  av_log(s, AV_LOG_WARNING, "Starting new cluster due to timestamp\n");
2332  }
2333  }
2334 
2335  if (mkv->cluster_pos == -1) {
2336  mkv->cluster_pos = avio_tell(s->pb);
2338  if (ret < 0)
2339  return ret;
2341  mkv->cluster_pts = FFMAX(0, ts);
2342  av_log(s, AV_LOG_DEBUG,
2343  "Starting new cluster with timestamp "
2344  "%" PRId64 " at offset %" PRId64 " bytes\n",
2345  mkv->cluster_pts, mkv->cluster_pos);
2346  }
2347  pb = mkv->cluster_bc;
2348 
2349  relative_packet_pos = avio_tell(pb);
2350 
2351  if (par->codec_type != AVMEDIA_TYPE_SUBTITLE) {
2352  ret = mkv_write_block(s, pb, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe);
2353  if (ret < 0)
2354  return ret;
2355  if ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && (par->codec_type == AVMEDIA_TYPE_VIDEO && keyframe || add_cue)) {
2356  ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, tracknum, ts, mkv->cluster_pos, relative_packet_pos, -1);
2357  if (ret < 0) return ret;
2358  }
2359  } else {
2360  if (par->codec_id == AV_CODEC_ID_WEBVTT) {
2361  duration = mkv_write_vtt_blocks(s, pb, pkt);
2362  } else {
2364  mkv_blockgroup_size(pkt->size));
2365 
2366 #if FF_API_CONVERGENCE_DURATION
2368  /* For backward compatibility, prefer convergence_duration. */
2369  if (pkt->convergence_duration > 0) {
2370  duration = pkt->convergence_duration;
2371  }
2373 #endif
2374  /* All subtitle blocks are considered to be keyframes. */
2375  mkv_write_block(s, pb, MATROSKA_ID_BLOCK, pkt, 1);
2377  end_ebml_master(pb, blockgroup);
2378  }
2379 
2380  if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
2381  ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, tracknum, ts,
2382  mkv->cluster_pos, relative_packet_pos, duration);
2383  if (ret < 0)
2384  return ret;
2385  }
2386  }
2387 
2388  mkv->duration = FFMAX(mkv->duration, ts + duration);
2389  track->duration = FFMAX(track->duration, ts + duration);
2390 
2391  return 0;
2392 }
2393 
2395 {
2396  MatroskaMuxContext *mkv = s->priv_data;
2398  int keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY);
2399  int cluster_size;
2400  int64_t cluster_time;
2401  int ret;
2402  int start_new_cluster;
2403 
2404  ret = mkv_check_new_extra_data(s, pkt);
2405  if (ret < 0)
2406  return ret;
2407 
2408  if (mkv->tracks[pkt->stream_index].write_dts)
2409  cluster_time = pkt->dts - mkv->cluster_pts;
2410  else
2411  cluster_time = pkt->pts - mkv->cluster_pts;
2412  cluster_time += mkv->tracks[pkt->stream_index].ts_offset;
2413 
2414  cluster_size = avio_tell(mkv->cluster_bc);
2415 
2416  if (mkv->is_dash && codec_type == AVMEDIA_TYPE_VIDEO) {
2417  // WebM DASH specification states that the first block of every cluster
2418  // has to be a key frame. So for DASH video, we only create a cluster
2419  // on seeing key frames.
2420  start_new_cluster = keyframe;
2421  } else if (mkv->is_dash && codec_type == AVMEDIA_TYPE_AUDIO &&
2422  (mkv->cluster_pos == -1 ||
2423  cluster_time > mkv->cluster_time_limit)) {
2424  // For DASH audio, we create a Cluster based on cluster_time_limit
2425  start_new_cluster = 1;
2426  } else if (!mkv->is_dash &&
2427  (cluster_size > mkv->cluster_size_limit ||
2428  cluster_time > mkv->cluster_time_limit ||
2429  (codec_type == AVMEDIA_TYPE_VIDEO && keyframe &&
2430  cluster_size > 4 * 1024))) {
2431  start_new_cluster = 1;
2432  } else {
2433  start_new_cluster = 0;
2434  }
2435 
2436  if (mkv->cluster_pos != -1 && start_new_cluster) {
2437  mkv_end_cluster(s);
2438  }
2439 
2440  if (!mkv->cluster_pos)
2441  avio_write_marker(s->pb,
2444 
2445  // check if we have an audio packet cached
2446  if (mkv->cur_audio_pkt.size > 0) {
2447  // for DASH audio, a CuePoint has to be added when there is a new cluster.
2449  mkv->is_dash ? start_new_cluster : 0);
2451  if (ret < 0) {
2452  av_log(s, AV_LOG_ERROR,
2453  "Could not write cached audio packet ret:%d\n", ret);
2454  return ret;
2455  }
2456  }
2457 
2458  // buffer an audio packet to ensure the packet containing the video
2459  // keyframe's timecode is contained in the same cluster for WebM
2460  if (codec_type == AVMEDIA_TYPE_AUDIO) {
2461  if (pkt->size > 0)
2462  ret = av_packet_ref(&mkv->cur_audio_pkt, pkt);
2463  } else
2464  ret = mkv_write_packet_internal(s, pkt, 0);
2465  return ret;
2466 }
2467 
2469 {
2470  MatroskaMuxContext *mkv = s->priv_data;
2471 
2472  if (!pkt) {
2473  if (mkv->cluster_pos != -1) {
2474  mkv_end_cluster(s);
2475  av_log(s, AV_LOG_DEBUG,
2476  "Flushing cluster at offset %" PRIu64 " bytes\n",
2477  avio_tell(s->pb));
2478  }
2479  return 1;
2480  }
2481  return mkv_write_packet(s, pkt);
2482 }
2483 
2485 {
2486  MatroskaMuxContext *mkv = s->priv_data;
2487  AVIOContext *pb = s->pb;
2488  int64_t currentpos, cuespos;
2489  int ret;
2490 
2491  // check if we have an audio packet cached
2492  if (mkv->cur_audio_pkt.size > 0) {
2493  ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt, 0);
2494  if (ret < 0) {
2495  av_log(s, AV_LOG_ERROR,
2496  "Could not write cached audio packet ret:%d\n", ret);
2497  return ret;
2498  }
2499  }
2500 
2501  if (mkv->cluster_bc) {
2502  end_ebml_master_crc32(pb, &mkv->cluster_bc, mkv);
2503  }
2504 
2505  ret = mkv_write_chapters(s);
2506  if (ret < 0)
2507  return ret;
2508 
2509 
2510  if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && !mkv->is_live) {
2511  if (mkv->cues->num_entries) {
2512  if (mkv->reserve_cues_space) {
2513  int64_t cues_end;
2514 
2515  currentpos = avio_tell(pb);
2516  avio_seek(pb, mkv->cues_pos, SEEK_SET);
2517 
2518  cuespos = mkv_write_cues(s, mkv->cues, mkv->tracks, s->nb_streams);
2519  cues_end = avio_tell(pb);
2520  if (cues_end > cuespos + mkv->reserve_cues_space) {
2521  av_log(s, AV_LOG_ERROR,
2522  "Insufficient space reserved for cues: %d "
2523  "(needed: %" PRId64 ").\n",
2524  mkv->reserve_cues_space, cues_end - cuespos);
2525  return AVERROR(EINVAL);
2526  }
2527 
2528  if (cues_end < cuespos + mkv->reserve_cues_space)
2530  (cues_end - cuespos));
2531 
2532  avio_seek(pb, currentpos, SEEK_SET);
2533  } else {
2534  cuespos = mkv_write_cues(s, mkv->cues, mkv->tracks, s->nb_streams);
2535  }
2536 
2538  }
2539 
2540  mkv_write_seekhead(pb, mkv);
2541 
2542  // update the duration
2543  av_log(s, AV_LOG_DEBUG, "end duration = %" PRIu64 "\n", mkv->duration);
2544  currentpos = avio_tell(pb);
2545  avio_seek(mkv->info_bc, mkv->duration_offset, SEEK_SET);
2547  avio_seek(pb, mkv->info_pos, SEEK_SET);
2548  end_ebml_master_crc32(pb, &mkv->info_bc, mkv);
2549 
2550  // write tracks master
2551  avio_seek(pb, mkv->tracks_pos, SEEK_SET);
2552  end_ebml_master_crc32(pb, &mkv->tracks_bc, mkv);
2553 
2554  // update stream durations
2555  if (!mkv->is_live) {
2556  int i;
2557  int64_t curr = avio_tell(mkv->tags_bc);
2558  for (i = 0; i < s->nb_streams; ++i) {
2559  AVStream *st = s->streams[i];
2560  mkv_track *track = &mkv->tracks[i];
2561 
2562  if (track->duration_offset > 0) {
2563  double duration_sec = track->duration * av_q2d(st->time_base);
2564  char duration_string[20] = "";
2565 
2566  av_log(s, AV_LOG_DEBUG, "stream %d end duration = %" PRIu64 "\n", i,
2567  track->duration);
2568 
2569  avio_seek(mkv->tags_bc, track->duration_offset, SEEK_SET);
2570 
2571  snprintf(duration_string, 20, "%02d:%02d:%012.9f",
2572  (int) duration_sec / 3600, ((int) duration_sec / 60) % 60,
2573  fmod(duration_sec, 60));
2574 
2575  put_ebml_binary(mkv->tags_bc, MATROSKA_ID_TAGSTRING, duration_string, 20);
2576  }
2577  }
2578  avio_seek(mkv->tags_bc, curr, SEEK_SET);
2579  }
2580  if (mkv->tags_bc && !mkv->is_live) {
2581  avio_seek(pb, mkv->tags_pos, SEEK_SET);
2582  end_ebml_master_crc32(pb, &mkv->tags_bc, mkv);
2583  }
2584 
2585  avio_seek(pb, currentpos, SEEK_SET);
2586  }
2587 
2588  if (!mkv->is_live) {
2589  end_ebml_master(pb, mkv->segment);
2590  }
2591 
2592  return 0;
2593 }
2594 
2595 static int mkv_query_codec(enum AVCodecID codec_id, int std_compliance)
2596 {
2597  int i;
2598  for (i = 0; ff_mkv_codec_tags[i].id != AV_CODEC_ID_NONE; i++)
2599  if (ff_mkv_codec_tags[i].id == codec_id)
2600  return 1;
2601 
2602  if (std_compliance < FF_COMPLIANCE_NORMAL) {
2603  enum AVMediaType type = avcodec_get_type(codec_id);
2604  // mkv theoretically supports any video/audio through VFW/ACM
2605  if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)
2606  return 1;
2607  }
2608 
2609  return 0;
2610 }
2611 
2612 static int webm_query_codec(enum AVCodecID codec_id, int std_compliance)
2613 {
2614  int i;
2615  for (i = 0; ff_webm_codec_tags[i].id != AV_CODEC_ID_NONE; i++)
2616  if (ff_webm_codec_tags[i].id == codec_id)
2617  return 1;
2618 
2619  return 0;
2620 }
2621 
2622 static int mkv_init(struct AVFormatContext *s)
2623 {
2624  int i;
2625 
2626  if (s->nb_streams > MAX_TRACKS) {
2627  av_log(s, AV_LOG_ERROR,
2628  "At most %d streams are supported for muxing in Matroska\n",
2629  MAX_TRACKS);
2630  return AVERROR(EINVAL);
2631  }
2632 
2633  for (i = 0; i < s->nb_streams; i++) {
2634  if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_ATRAC3 ||
2640  av_log(s, AV_LOG_ERROR,
2641  "The Matroska muxer does not yet support muxing %s\n",
2643  return AVERROR_PATCHWELCOME;
2644  }
2645  }
2646 
2647  if (s->avoid_negative_ts < 0) {
2648  s->avoid_negative_ts = 1;
2650  }
2651 
2652  for (i = 0; i < s->nb_streams; i++) {
2653  // ms precision is the de-facto standard timescale for mkv files
2654  avpriv_set_pts_info(s->streams[i], 64, 1, 1000);
2655  }
2656 
2657  return 0;
2658 }
2659 
2660 static int mkv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
2661 {
2662  int ret = 1;
2663  AVStream *st = s->streams[pkt->stream_index];
2664 
2665  if (st->codecpar->codec_id == AV_CODEC_ID_AAC) {
2666  if (pkt->size > 2 && (AV_RB16(pkt->data) & 0xfff0) == 0xfff0)
2667  ret = ff_stream_add_bitstream_filter(st, "aac_adtstoasc", NULL);
2668  } else if (st->codecpar->codec_id == AV_CODEC_ID_VP9) {
2669  ret = ff_stream_add_bitstream_filter(st, "vp9_superframe", NULL);
2670  }
2671 
2672  return ret;
2673 }
2674 
2676  { AV_CODEC_ID_ALAC, 0XFFFFFFFF },
2677  { AV_CODEC_ID_MLP, 0xFFFFFFFF },
2678  { AV_CODEC_ID_OPUS, 0xFFFFFFFF },
2679  { AV_CODEC_ID_PCM_S16BE, 0xFFFFFFFF },
2680  { AV_CODEC_ID_PCM_S24BE, 0xFFFFFFFF },
2681  { AV_CODEC_ID_PCM_S32BE, 0xFFFFFFFF },
2682  { AV_CODEC_ID_QDMC, 0xFFFFFFFF },
2683  { AV_CODEC_ID_QDM2, 0xFFFFFFFF },
2684  { AV_CODEC_ID_RA_144, 0xFFFFFFFF },
2685  { AV_CODEC_ID_RA_288, 0xFFFFFFFF },
2686  { AV_CODEC_ID_COOK, 0xFFFFFFFF },
2687  { AV_CODEC_ID_TRUEHD, 0xFFFFFFFF },
2688  { AV_CODEC_ID_NONE, 0xFFFFFFFF }
2689 };
2690 
2692  { AV_CODEC_ID_RV10, 0xFFFFFFFF },
2693  { AV_CODEC_ID_RV20, 0xFFFFFFFF },
2694  { AV_CODEC_ID_RV30, 0xFFFFFFFF },
2695  { AV_CODEC_ID_NONE, 0xFFFFFFFF }
2696 };
2697 
2699  { AV_CODEC_ID_DVB_SUBTITLE, 0xFFFFFFFF },
2700  { AV_CODEC_ID_DVD_SUBTITLE, 0xFFFFFFFF },
2701  { AV_CODEC_ID_HDMV_PGS_SUBTITLE, 0xFFFFFFFF },
2702  { AV_CODEC_ID_NONE, 0xFFFFFFFF }
2703 };
2704 
2705 #define OFFSET(x) offsetof(MatroskaMuxContext, x)
2706 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM
2707 static const AVOption options[] = {
2708  { "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 },
2709  { "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 },
2710  { "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 },
2711  { "dash", "Create a WebM file conforming to WebM DASH specification", OFFSET(is_dash), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
2712  { "dash_track_number", "Track number for the DASH stream", OFFSET(dash_track_number), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 127, FLAGS },
2713  { "live", "Write files assuming it is a live stream.", OFFSET(is_live), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
2714  { "allow_raw_vfw", "allow RAW VFW mode", OFFSET(allow_raw_vfw), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
2715  { "write_crc32", "write a CRC32 element inside every Level 1 element", OFFSET(write_crc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
2716  { NULL },
2717 };
2718 
2719 #if CONFIG_MATROSKA_MUXER
2720 static const AVClass matroska_class = {
2721  .class_name = "matroska muxer",
2722  .item_name = av_default_item_name,
2723  .option = options,
2724  .version = LIBAVUTIL_VERSION_INT,
2725 };
2726 
2728  .name = "matroska",
2729  .long_name = NULL_IF_CONFIG_SMALL("Matroska"),
2730  .mime_type = "video/x-matroska",
2731  .extensions = "mkv",
2732  .priv_data_size = sizeof(MatroskaMuxContext),
2733  .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
2735  .video_codec = CONFIG_LIBX264_ENCODER ?
2737  .init = mkv_init,
2738  .deinit = mkv_deinit,
2744  .codec_tag = (const AVCodecTag* const []){
2747  },
2748  .subtitle_codec = AV_CODEC_ID_ASS,
2749  .query_codec = mkv_query_codec,
2750  .check_bitstream = mkv_check_bitstream,
2751  .priv_class = &matroska_class,
2752 };
2753 #endif
2754 
2755 #if CONFIG_WEBM_MUXER
2756 static const AVClass webm_class = {
2757  .class_name = "webm muxer",
2758  .item_name = av_default_item_name,
2759  .option = options,
2760  .version = LIBAVUTIL_VERSION_INT,
2761 };
2762 
2764  .name = "webm",
2765  .long_name = NULL_IF_CONFIG_SMALL("WebM"),
2766  .mime_type = "video/webm",
2767  .extensions = "webm",
2768  .priv_data_size = sizeof(MatroskaMuxContext),
2769  .audio_codec = CONFIG_LIBOPUS_ENCODER ? AV_CODEC_ID_OPUS : AV_CODEC_ID_VORBIS,
2770  .video_codec = CONFIG_LIBVPX_VP9_ENCODER? AV_CODEC_ID_VP9 : AV_CODEC_ID_VP8,
2771  .subtitle_codec = AV_CODEC_ID_WEBVTT,
2772  .init = mkv_init,
2773  .deinit = mkv_deinit,
2778  .check_bitstream = mkv_check_bitstream,
2781  .priv_class = &webm_class,
2782 };
2783 #endif
2784 
2785 #if CONFIG_MATROSKA_AUDIO_MUXER
2786 static const AVClass mka_class = {
2787  .class_name = "matroska audio muxer",
2788  .item_name = av_default_item_name,
2789  .option = options,
2790  .version = LIBAVUTIL_VERSION_INT,
2791 };
2793  .name = "matroska",
2794  .long_name = NULL_IF_CONFIG_SMALL("Matroska Audio"),
2795  .mime_type = "audio/x-matroska",
2796  .extensions = "mka",
2797  .priv_data_size = sizeof(MatroskaMuxContext),
2798  .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
2800  .video_codec = AV_CODEC_ID_NONE,
2801  .init = mkv_init,
2802  .deinit = mkv_deinit,
2806  .check_bitstream = mkv_check_bitstream,
2809  .codec_tag = (const AVCodecTag* const []){
2811  },
2812  .priv_class = &mka_class,
2813 };
2814 #endif
unsigned int nb_chapters
Number of chapters in AVChapter array.
Definition: avformat.h:1581
static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int add_cue)
Definition: matroskaenc.c:2308
int32_t pitch
Rotation around the right vector [-90, 90].
Definition: spherical.h:127
Context structure for the Lagged Fibonacci PRNG.
Definition: lfg.h:33
#define MATROSKA_ID_SEEKPREROLL
Definition: matroska.h:95
void av_sha_final(AVSHA *ctx, uint8_t *digest)
Finish hashing and output digest value.
Definition: sha.c:345
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
Definition: stereo3d.h:167
#define MATROSKA_ID_VIDEOPROJECTIONPOSEYAW
Definition: matroska.h:159
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:698
enum AVChromaLocation chroma_location
Definition: avcodec.h:4126
internal header for HEVC (de)muxer utilities
#define AV_DISPOSITION_METADATA
Definition: avformat.h:857
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:461
#define NULL
Definition: coverity.c:32
static int mkv_write_vtt_blocks(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt)
Definition: matroskaenc.c:2149
#define MAX_CUEPOINT_CONTENT_SIZE(num_tracks)
per-cuepoint - 1 1-byte EBML ID, 1 1-byte EBML size, 8-byte uint max
Definition: matroskaenc.c:179
const char const char void * val
Definition: avisynth_c.h:863
#define MATROSKA_ID_BLOCKADDID
Definition: matroska.h:230
#define MATROSKA_ID_TRACKDEFAULTDURATION
Definition: matroska.h:104
enum AVFieldOrder field_order
Video only.
Definition: avcodec.h:4117
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:467
static void put_ebml_size_unknown(AVIOContext *pb, int bytes)
Write an EBML size meaning "unknown size".
Definition: matroskaenc.c:201
Bytestream IO Context.
Definition: avio.h:161
enum AVColorTransferCharacteristic color_trc
Definition: avcodec.h:4124
#define MATROSKA_ID_VIDEOFLAGINTERLACED
Definition: matroska.h:121
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define MATROSKA_ID_VIDEOCOLOR_GX
Definition: matroska.h:147
void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:59
#define MATROSKA_ID_DATEUTC
Definition: matroska.h:71
int sizebytes
how many bytes were reserved for the size
Definition: matroskaenc.c:66
#define MAX_TRACKS
Maximum number of tracks allowed in a Matroska file (with track numbers in range 1 to 126 (inclusive)...
Definition: matroskaenc.c:123
The optional first identifier line of a WebVTT cue.
Definition: avcodec.h:1383
uint32_t samples
Definition: wv.h:39
int initial
Definition: wv.h:43
#define MATROSKA_ID_TRACKFLAGLACING
Definition: matroska.h:101
unsigned MaxCLL
Max content light level (cd/m^2).
#define MATROSKA_ID_TRACKENTRY
Definition: matroska.h:75
#define MATROSKA_ID_VIDEODISPLAYHEIGHT
Definition: matroska.h:113
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1410
AVOption.
Definition: opt.h:246
hash context
Definition: sha.c:34
int64_t cluster_pos
offset of the cluster containing the block relative to the segment
Definition: matroskaenc.c:85
void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par, int for_asf, int ignore_extradata)
Definition: riffenc.c:209
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:100
int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int flags)
Write WAVEFORMAT header structure.
Definition: riffenc.c:54
static int mkv_init(struct AVFormatContext *s)
Definition: matroskaenc.c:2622
#define MAX_SEEKHEAD_ENTRIES
Definition: matroskaenc.c:62
#define MATROSKA_ID_VIDEOPROJECTIONPOSEROLL
Definition: matroska.h:161
#define MATROSKA_ID_CUETRACKPOSITION
Definition: matroska.h:192
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:3160
#define MATROSKA_ID_CODECPRIVATE
Definition: matroska.h:89
AVIOContext * cluster_bc
Definition: matroskaenc.c:136
av_cold int av_sha_init(AVSHA *ctx, int bits)
Initialize SHA-1 or SHA-2 hashing.
Definition: sha.c:273
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4943
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:587
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:1
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define MATROSKA_ID_AUDIOBITDEPTH
Definition: matroska.h:167
#define MATROSKA_ID_TRACKFLAGDEFAULT
Definition: matroska.h:99
static const AVCodecTag additional_subtitle_tags[]
Definition: matroskaenc.c:2698
This side data should be associated with a video stream and contains Stereoscopic 3D information in f...
Definition: avcodec.h:1301
static int mkv_write_attachments(AVFormatContext *s)
Definition: matroskaenc.c:1675
uint64_t pts
Definition: matroskaenc.c:82
Video represents a portion of a sphere mapped on a flat surface using equirectangular projection...
Definition: spherical.h:72
static int mkv_write_video_color(AVIOContext *pb, AVCodecParameters *par, AVStream *st)
Definition: matroskaenc.c:819
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:4036
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:937
#define MATROSKA_ID_TAGTARGETS_ATTACHUID
Definition: matroska.h:214
int num
Numerator.
Definition: rational.h:59
int size
Definition: avcodec.h:1534
int ff_hevc_annexb2mp4_buf(const uint8_t *buf_in, uint8_t **buf_out, int *size, int filter_ps, int *ps_count)
Writes Annex B formatted HEVC NAL units to a data buffer.
Definition: hevc.c:1047
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:241
#define MATROSKA_ID_FILEDATA
Definition: matroska.h:246
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1805
#define EBML_ID_DOCTYPEREADVERSION
Definition: matroska.h:42
#define us(width, name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:266
#define MATROSKA_ID_BLOCKREFERENCE
Definition: matroska.h:237
int av_log2(unsigned v)
Definition: intmath.c:26
static int mkv_write_header(AVFormatContext *s)
Definition: matroskaenc.c:1795
#define MATROSKA_ID_TRACKTYPE
Definition: matroska.h:80
enum AVMediaType codec_type
Definition: rtp.c:37
#define MATROSKA_ID_TAGTARGETS_CHAPTERUID
Definition: matroska.h:213
int ff_flac_is_native_layout(uint64_t channel_layout)
int64_t duration
duration of the block according to time base
Definition: matroskaenc.c:87
static av_always_inline uint64_t av_double2int(double f)
Reinterpret a double as a 64-bit integer.
Definition: intfloat.h:70
GLint GLenum type
Definition: opengl_enc.c:104
#define MATROSKA_ID_VIDEOCOLOR_RX
Definition: matroska.h:145
Video represents a sphere mapped on a flat surface using equirectangular projection.
Definition: spherical.h:56
#define MATROSKA_ID_MUXINGAPP
Definition: matroska.h:70
int64_t cluster_time_limit
Definition: matroskaenc.c:154
#define MATROSKA_ID_AUDIOCHANNELS
Definition: matroska.h:168
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id)
Definition: utils.c:3150
int64_t segment_offset
Definition: matroskaenc.c:91
const char * key
int version
Definition: avisynth_c.h:858
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
int avoid_negative_ts_use_pts
Definition: internal.h:119
const char * master
Definition: vf_curves.c:117
#define MATROSKA_ID_VIDEOPROJECTIONTYPE
Definition: matroska.h:157
AVPacketSideData * side_data
An array of side data that applies to the whole stream (i.e.
Definition: avformat.h:977
Views are next to each other.
Definition: stereo3d.h:67
static AVPacket pkt
#define av_le2ne32(x)
Definition: bswap.h:96
#define MATROSKA_ID_CUECLUSTERPOSITION
Definition: matroska.h:196
#define MATROSKA_ID_VIDEOCOLOR_LUMINANCEMAX
Definition: matroska.h:153
#define MAX_EBML_HEADER_SIZE
2 bytes * 7 for EBML IDs, 7 1-byte EBML lengths, 6 1-byte uint, 8 byte for "matroska" doctype string ...
Definition: matroskaenc.c:168
Definition: matroskaenc.c:69
int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
Converts AVChromaLocation to swscale x/y chroma position.
Definition: utils.c:353
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:87
AVDictionary * metadata
Definition: avformat.h:1313
#define MATROSKA_ID_VIDEOCOLORCHROMASITINGHORZ
Definition: matroska.h:135
mkv_track * tracks
Definition: matroskaenc.c:143
#define src
Definition: vp8dsp.c:254
#define AVFMT_ALLOW_FLUSH
Format allows flushing.
Definition: avformat.h:471
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
#define MATROSKA_ID_EDITIONFLAGDEFAULT
Definition: matroska.h:260
static int start_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, uint32_t elementid)
Definition: matroskaenc.c:333
#define MATROSKA_ID_CLUSTERTIMECODE
Definition: matroska.h:224
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1376
#define EBML_ID_DOCTYPE
Definition: matroska.h:40
int64_t duration_offset
Definition: matroskaenc.c:103
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:472
This struct describes the properties of an encoded stream.
Definition: avcodec.h:4028
#define MATROSKA_ID_CHAPTERTIMEEND
Definition: matroska.h:253
enum AVColorSpace color_space
Definition: avcodec.h:4125
int64_t pos
absolute offset in the containing AVIOContext where the master&#39;s elements start
Definition: matroskaenc.c:65
MatroskaVideoStereoModeType
Definition: matroska.h:301
Mastering display metadata (based on SMPTE-2086:2014).
Definition: avcodec.h:1409
#define FLAGS
Definition: matroskaenc.c:2706
#define MATROSKA_ID_FILEDESC
Definition: matroska.h:243
Format I/O context.
Definition: avformat.h:1352
#define EBML_ID_CRC32
Definition: matroska.h:46
UID uid
Definition: mxfenc.c:2139
char str[32]
Definition: internal.h:48
static int query_codec(enum AVCodecID id, int std_compliance)
Definition: img2enc.c:229
int64_t cluster_pos
file offset of the current cluster
Definition: matroskaenc.c:137
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
#define AV_WB64(p, v)
Definition: intreadwrite.h:433
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static const AVCodecTag additional_audio_tags[]
Definition: matroskaenc.c:2675
Public dictionary API.
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:367
uint8_t
#define MATROSKA_ID_VIDEOCOLOR_BX
Definition: matroska.h:149
#define MATROSKA_ID_CHAPLANG
Definition: matroska.h:256
#define av_malloc(s)
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:177
int width
Video only.
Definition: avcodec.h:4102
static void mkv_end_cluster(AVFormatContext *s)
Definition: matroskaenc.c:2192
AVOptions.
#define MATROSKA_ID_TRACKLANGUAGE
Definition: matroska.h:97
int64_t duration
Definition: matroskaenc.c:102
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
Definition: utils.c:2030
A point in the output bytestream where the underlying AVIOContext might flush the buffer depending on...
Definition: avio.h:146
Stereo 3D type: this structure describes how two videos are packed within a single video surface...
Definition: stereo3d.h:176
const AVCodecTag ff_codec_movvideo_tags[]
Definition: isom.c:75
#define OPUS_SEEK_PREROLL
Seek preroll value for opus.
Definition: matroskaenc.c:182
uint32_t flags
Definition: wv.h:40
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
int ff_mkv_stereo3d_conv(AVStream *st, MatroskaVideoStereoModeType stereo_mode)
Definition: matroska.c:171
uint64_t segmentpos
Definition: matroskaenc.c:71
int id
unique ID to identify the chapter
Definition: avformat.h:1310
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1551
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
#define MATROSKA_ID_TIMECODESCALE
Definition: matroska.h:66
static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int native_id, int qt_id)
Definition: matroskaenc.c:752
#define MATROSKA_ID_SIMPLEBLOCK
Definition: matroska.h:232
#define MATROSKA_ID_EDITIONFLAGHIDDEN
Definition: matroska.h:259
int nb_side_data
The number of elements in the AVStream.side_data array.
Definition: avformat.h:981
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
Definition: aviobuf.c:491
uint8_t * av_stream_get_side_data(const AVStream *stream, enum AVPacketSideDataType type, int *size)
Get side information from stream.
Definition: utils.c:5503
#define MATROSKA_ID_BLOCKMORE
Definition: matroska.h:229
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:87
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1420
int64_t duration
Definition: movenc.c:63
#define MATROSKA_ID_CUERELATIVEPOSITION
Definition: matroska.h:197
A point in the output bytestream where a demuxer can start parsing (for non self synchronizing bytest...
Definition: avio.h:128
#define MATROSKA_ID_AUDIOOUTSAMPLINGFREQ
Definition: matroska.h:165
#define MATROSKA_ID_VIDEOCOLOR
Definition: matroska.h:127
Public header for CRC hash function implementation.
int initial_padding
Audio only.
Definition: avcodec.h:4165
static int webm_query_codec(enum AVCodecID codec_id, int std_compliance)
Definition: matroskaenc.c:2612
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1483
uint8_t * data
Definition: avcodec.h:1533
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tracks, int num_tracks)
Definition: matroskaenc.c:522
#define MATROSKA_ID_VIDEODISPLAYWIDTH
Definition: matroska.h:112
int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size)
Writes AV1 extradata (Sequence Header and Metadata OBUs) to the provided AVIOContext.
Definition: av1.c:364
#define MATROSKA_ID_BLOCKADDITIONS
Definition: matroska.h:228
uint32_t tag
Definition: movenc.c:1533
static EbmlSyntax ebml_header[]
Definition: matroskadec.c:404
Not part of ABI.
Definition: pixfmt.h:536
#define WV_HEADER_SIZE
Definition: wavpack.h:30
enum AVCodecID id
Definition: internal.h:49
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
uint8_t * data
Definition: avcodec.h:1477
#define MATROSKA_ID_CUES
Definition: matroska.h:58
int64_t ts_offset
Definition: matroskaenc.c:105
#define max(a, b)
Definition: cuda_runtime.h:33
Video is not stereoscopic (and metadata has to be there).
Definition: stereo3d.h:55
ptrdiff_t size
Definition: opengl_enc.c:100
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:557
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
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
static const uint8_t header[24]
Definition: sdr2.c:67
#define MATROSKA_ID_TRACKNUMBER
Definition: matroska.h:78
#define MATROSKA_ID_VIDEOCOLOR_WHITEY
Definition: matroska.h:152
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:213
Definition: wv.h:34
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1500
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:198
#define MATROSKA_ID_SEGMENTUID
Definition: matroska.h:72
AVOutputFormat ff_webm_muxer
static int mkv_write_block(AVFormatContext *s, AVIOContext *pb, uint32_t blockid, AVPacket *pkt, int keyframe)
Definition: matroskaenc.c:2034
uint64_t channel_layout
Audio only.
Definition: avcodec.h:4138
static void put_ebml_num(AVIOContext *pb, uint64_t num, int bytes)
Write a number in EBML variable length format.
Definition: matroskaenc.c:225
#define av_log(a,...)
int has_cue
Definition: matroskaenc.c:98
#define AV_DISPOSITION_CAPTIONS
To specify text track kind (different from subtitles default).
Definition: avformat.h:855
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:609
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1565
static void mkv_add_seekhead_entry(MatroskaMuxContext *mkv, uint32_t elementid, uint64_t filepos)
Definition: matroskaenc.c:427
#define MATROSKA_ID_TRACKUID
Definition: matroska.h:79
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
ebml_master segment
Definition: matroskaenc.c:134
static int mkv_write_simpletag(AVIOContext *pb, AVDictionaryEntry *t)
Definition: matroskaenc.c:1478
#define MATROSKA_ID_VIDEOSTEREOMODE
Definition: matroska.h:123
uint32_t chapter_id_offset
Definition: matroskaenc.c:160
static void put_ebml_id(AVIOContext *pb, uint32_t id)
Definition: matroskaenc.c:189
int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds)
Parse creation_time in AVFormatContext metadata if exists and warn if the parsing fails...
Definition: utils.c:5709
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
AVPacket cur_audio_pkt
Definition: matroskaenc.c:146
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:217
static int mkv_write_tags(AVFormatContext *s)
Definition: matroskaenc.c:1586
#define MATROSKA_ID_VIDEOCOLOR_BY
Definition: matroska.h:150
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Copy the contents of src to dst.
Definition: utils.c:2051
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static void put_ebml_float(AVIOContext *pb, uint32_t elementid, double val)
Definition: matroskaenc.c:269
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:1539
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1592
int flags
Additional information about the frame packing.
Definition: stereo3d.h:185
#define MATROSKA_ID_BLOCKDURATION
Definition: matroska.h:236
#define EBML_ID_EBMLREADVERSION
Definition: matroska.h:37
#define MATROSKA_ID_VIDEOCOLORMAXCLL
Definition: matroska.h:141
#define MAX_CUETRACKPOS_SIZE
per-cuepoint-track - 5 1-byte EBML IDs, 5 1-byte EBML sizes, 3 8-byte uint max and one 1-byte uint fo...
Definition: matroskaenc.c:176
#define MATROSKA_ID_VIDEOCOLOR_WHITEX
Definition: matroska.h:151
static int get_aac_sample_rates(AVFormatContext *s, uint8_t *extradata, int extradata_size, int *sample_rate, int *output_sample_rate)
Definition: matroskaenc.c:668
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
Definition: avpacket.c:350
int reserved_size
Definition: matroskaenc.c:78
#define MATROSKA_ID_CLUSTER
Definition: matroska.h:62
const char * ff_convert_lang_to(const char *lang, enum AVLangCodespace target_codespace)
Convert a language code to a target codespace.
Definition: avlanguage.c:736
#define MATROSKA_ID_VIDEOCOLORCHROMASITINGVERT
Definition: matroska.h:136
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
int ff_av1_filter_obus_buf(const uint8_t *in, uint8_t **out, int *size, int *offset)
Filter out AV1 OBUs not meant to be present in ISOBMFF sample data and return the result in a data bu...
Definition: av1.c:86
Views are packed per line, as if interlaced.
Definition: stereo3d.h:129
enum AVColorPrimaries color_primaries
Definition: avcodec.h:4123
#define MATROSKA_ID_FILEMIMETYPE
Definition: matroska.h:245
#define MATROSKA_ID_WRITINGAPP
Definition: matroska.h:69
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
int ff_isom_write_hvcc(AVIOContext *pb, const uint8_t *data, int size, int ps_array_completeness)
Writes HEVC extradata (parameter sets, declarative SEI NAL units) to the provided AVIOContext...
Definition: hevc.c:1068
Not part of ABI.
Definition: pixfmt.h:473
AVIOContext * tracks_bc
Definition: matroskaenc.c:132
const char *const ff_matroska_video_stereo_mode[MATROSKA_VIDEO_STEREOMODE_TYPE_NB]
Definition: matroska.c:147
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:203
static int mkv_blockgroup_size(int pkt_size)
Definition: matroskaenc.c:1972
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:4032
static int ebml_num_size(uint64_t num)
Calculate how many bytes are needed to represent a given number in EBML.
Definition: matroskaenc.c:211
int write_dts
Definition: matroskaenc.c:97
int final
Definition: wv.h:43
AVChapter ** chapters
Definition: avformat.h:1582
int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m, const char *vendor_string, AVChapter **chapters, unsigned int nb_chapters)
Write a VorbisComment into a buffer.
Definition: vorbiscomment.c:65
enum AVCodecID id
Definition: matroska.h:355
enum AVPacketSideDataType type
Definition: avcodec.h:1479
enum AVMediaType avcodec_get_type(enum AVCodecID codec_id)
Get the type of the given codec.
Definition: codec_desc.c:3389
static int mkv_write_chapters(AVFormatContext *s)
Definition: matroskaenc.c:1421
#define EBML_ID_EBMLMAXIDLENGTH
Definition: matroska.h:38
#define MATROSKA_ID_CHAPTERFLAGHIDDEN
Definition: matroska.h:263
uint32_t crc
Definition: wv.h:41
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:948
const AVCodecTag ff_codec_wav_tags[]
Definition: riff.c:504
#define FFMAX(a, b)
Definition: common.h:94
int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size)
Definition: avc.c:95
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
void avcodec_parameters_free(AVCodecParameters **par)
Free an AVCodecParameters instance and everything associated with it and write NULL to the supplied p...
Definition: utils.c:2040
int64_t filepos
Definition: matroskaenc.c:75
#define fail()
Definition: checkasm.h:122
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1539
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:4054
const CodecMime ff_mkv_mime_tags[]
Definition: matroska.c:131
#define MATROSKA_ID_TAG
Definition: matroska.h:202
const CodecTags ff_webm_codec_tags[]
Definition: matroska.c:106
Views are alternated temporally.
Definition: stereo3d.h:92
#define AV_DISPOSITION_FORCED
Track should be used during playback by default.
Definition: avformat.h:832
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1408
uint32_t bound_bottom
Distance from the bottom edge.
Definition: spherical.h:170
AVOutputFormat ff_matroska_audio_muxer
#define LIBAVFORMAT_IDENT
Definition: version.h:46
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:260
Video frame is split into 6 faces of a cube, and arranged on a 3x2 layout.
Definition: spherical.h:65
#define MATROSKA_ID_VIDEOCOLOR_LUMINANCEMIN
Definition: matroska.h:154
audio channel layout utility functions
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:3323
#define EBML_ID_EBMLVERSION
Definition: matroska.h:36
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
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
mkv_cuepoint * entries
Definition: matroskaenc.c:92
void ffio_fill(AVIOContext *s, int b, int count)
Definition: aviobuf.c:199
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
#define MATROSKA_ID_TAGTARGETS
Definition: matroska.h:209
const AVCodecTag ff_codec_bmp_tags[]
Definition: riff.c:32
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:213
#define MATROSKA_ID_TAGNAME
Definition: matroska.h:204
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
static int put_wv_codecpriv(AVIOContext *pb, AVCodecParameters *par)
Definition: matroskaenc.c:610
static void end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv)
Definition: matroskaenc.c:348
#define MATROSKA_ID_CHAPTERFLAGENABLED
Definition: matroska.h:264
static int64_t mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv)
Write the SeekHead to the file at the location reserved for it.
Definition: matroskaenc.c:444
static int mkv_write_native_codecprivate(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, AVIOContext *dyn_cp)
Definition: matroskaenc.c:700
void av_sha_update(struct AVSHA *ctx, const uint8_t *data, unsigned int len)
Update hash value.
Definition: sha.c:315
static int64_t get_metadata_duration(AVFormatContext *s)
Definition: matroskaenc.c:1771
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:94
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
Definition: af_astats.c:226
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:461
This side data should be associated with a video stream and corresponds to the AVSphericalMapping str...
Definition: avcodec.h:1415
int64_t ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string, AVChapter **chapters, unsigned int nb_chapters)
Calculate the length in bytes of a VorbisComment.
Definition: vorbiscomment.c:41
uint32_t bound_right
Distance from the right edge.
Definition: spherical.h:169
int ff_wv_parse_header(WvHeader *wv, const uint8_t *data)
Parse a WavPack block header.
Definition: wv.c:29
#define MATROSKA_ID_SIMPLETAG
Definition: matroska.h:203
const char * name
Definition: avformat.h:500
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
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
#define AV_WB24(p, d)
Definition: intreadwrite.h:450
static int mkv_check_new_extra_data(AVFormatContext *s, AVPacket *pkt)
Definition: matroskaenc.c:2201
#define s(width, name)
Definition: cbs_vp9.c:257
int avoid_negative_ts
Avoid negative timestamps during muxing.
Definition: avformat.h:1683
#define MATROSKA_ID_CHAPTERATOM
Definition: matroska.h:251
int avpriv_split_xiph_headers(const uint8_t *extradata, int extradata_size, int first_header_size, const uint8_t *header_start[3], int header_len[3])
Split a single extradata buffer into the three headers that most Xiph codecs use. ...
Definition: xiph.c:24
int32_t yaw
Rotation around the up vector [-180, 180].
Definition: spherical.h:126
AVDictionary * metadata
Definition: avformat.h:939
enum AVCodecID codec_id
Definition: vaapi_decode.c:369
enum AVColorRange color_range
Video only.
Definition: avcodec.h:4122
AVIOContext * info_bc
Definition: matroskaenc.c:130
Opaque data information usually sparse.
Definition: avutil.h:205
#define MATROSKA_ID_VIDEOCOLORSPACE
Definition: matroska.h:126
#define MATROSKA_ID_CHAPTERS
Definition: matroska.h:63
#define EBML_ID_VOID
Definition: matroska.h:45
#define OFFSET(x)
Definition: matroskaenc.c:2705
#define MATROSKA_ID_AUDIOSAMPLINGFREQ
Definition: matroska.h:164
static int mkv_check_tag(AVDictionary *m, uint32_t elementid)
Definition: matroskaenc.c:1575
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:1172
ff_const59 struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1371
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
Definition: aviobuf.c:1440
uint32_t padding
Number of pixels to pad from the edge of each cube face.
Definition: spherical.h:182
static int mkv_add_cuepoint(mkv_cues *cues, int stream, int tracknum, int64_t ts, int64_t cluster_pos, int64_t relative_pos, int64_t duration)
Definition: matroskaenc.c:499
int metadata_header_padding
Number of bytes to be written as padding in a metadata header.
Definition: avformat.h:1852
Stream structure.
Definition: avformat.h:875
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
int64_t end
chapter start/end time in time_base units
Definition: avformat.h:1312
Content light level (based on CTA-861.3).
Definition: avcodec.h:1422
static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, int i, AVIOContext *pb, int default_stream_exists)
Definition: matroskaenc.c:1116
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition: avcodec.h:1242
#define AV_DISPOSITION_DEFAULT
Definition: avformat.h:820
sample_rate
enum AVStereo3DType type
How views are packed within the video.
Definition: stereo3d.h:180
Views are packed in a checkerboard-like structure per pixel.
Definition: stereo3d.h:104
#define MATROSKA_ID_VIDEOCOLORMATRIXCOEFF
Definition: matroska.h:129
#define AV_DISPOSITION_DESCRIPTIONS
Definition: avformat.h:856
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:251
#define MATROSKA_ID_TRACKFLAGFORCED
Definition: matroska.h:100
#define MATROSKA_ID_TAGS
Definition: matroska.h:59
Views are on top of each other.
Definition: stereo3d.h:79
#define MATROSKA_ID_VIDEOCOLORPRIMARIES
Definition: matroska.h:140
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:87
int64_t sample_rate_offset
Definition: matroskaenc.c:100
#define MATROSKA_ID_VIDEOPROJECTIONPOSEPITCH
Definition: matroska.h:160
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
#define MATROSKA_ID_SEEKID
Definition: matroska.h:220
AVIOContext * pb
I/O context.
Definition: avformat.h:1394
int64_t codecpriv_offset
Definition: matroskaenc.c:104
static void put_ebml_uint(AVIOContext *pb, uint32_t elementid, uint64_t val)
Definition: matroskaenc.c:243
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:191
Public header for SHA-1 & SHA-256 hash function implementations.
#define MATROSKA_ID_BLOCK
Definition: matroska.h:235
#define MATROSKA_ID_INFO
Definition: matroska.h:56
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:600
#define MATROSKA_ID_TAGTARGETS_TRACKUID
Definition: matroska.h:212
mkv_attachment * entries
Definition: matroskaenc.c:114
uint32_t fileuid
Definition: matroskaenc.c:110
#define MATROSKA_ID_TAGLANG
Definition: matroska.h:206
struct AVSHA * av_sha_alloc(void)
Allocate an AVSHA context.
Definition: sha.c:45
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:53
#define MATROSKA_ID_TRACKS
Definition: matroska.h:57
void * buf
Definition: avisynth_c.h:766
Data found in BlockAdditional element of matroska container.
Definition: avcodec.h:1378
#define MATROSKA_ID_TRACKNAME
Definition: matroska.h:96
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
#define MATROSKA_ID_SEEKENTRY
Definition: matroska.h:217
Describe the class of an AVClass context structure.
Definition: log.h:67
#define AV_WB32(p, v)
Definition: intreadwrite.h:419
#define MATROSKA_ID_EDITIONENTRY
Definition: matroska.h:250
#define FF_COMPLIANCE_NORMAL
Definition: avcodec.h:2687
static int mkv_check_tag_name(const char *name, uint32_t elementid)
Definition: matroskaenc.c:1537
#define MATROSKA_ID_BLOCKGROUP
Definition: matroska.h:227
#define MATROSKA_ID_VIDEOPIXELHEIGHT
Definition: matroska.h:115
int32_t roll
Rotation around the forward vector [-180, 180].
Definition: spherical.h:128
static int mkv_write_tracks(AVFormatContext *s)
Definition: matroskaenc.c:1391
Rational number (pair of numerator and denominator).
Definition: rational.h:58
Mastering display metadata capable of representing the color volume of the display used to master the...
#define MATROSKA_ID_CUEDURATION
Definition: matroska.h:198
static int mkv_write_tag_targets(AVFormatContext *s, uint32_t elementid, unsigned int uid, ebml_master *tag)
Definition: matroskaenc.c:1512
#define MATROSKA_ID_CUETIME
Definition: matroska.h:191
Not part of ABI.
Definition: pixfmt.h:502
AVFieldOrder
Definition: avcodec.h:1599
Recommmends skipping the specified number of samples.
Definition: avcodec.h:1343
AVMediaType
Definition: avutil.h:199
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition: lfg.c:32
int64_t duration_offset
Definition: matroskaenc.c:139
#define MATROSKA_ID_VIDEOCOLORTRANSFERCHARACTERISTICS
Definition: matroska.h:138
#define MATROSKA_ID_TITLE
Definition: matroska.h:68
#define snprintf
Definition: snprintf.h:34
#define MATROSKA_ID_TRACKVIDEO
Definition: matroska.h:81
static int mkv_strip_wavpack(const uint8_t *src, uint8_t **pdst, int *size)
Definition: matroskaenc.c:1981
This structure describes how to handle spherical videos, outlining information about projection...
Definition: spherical.h:82
mkv_seekhead seekhead
Definition: matroskaenc.c:141
#define MATROSKA_ID_VIDEOPROJECTION
Definition: matroska.h:156
#define MATROSKA_ID_VIDEOCOLORMASTERINGMETA
Definition: matroska.h:144
misc parsing utilities
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(const int64_t *) pi *(1.0f/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(const int64_t *) pi *(1.0/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(UINT64_C(1)<< 63)))#define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};static void cpy1(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, len);}static void cpy2(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 2 *len);}static void cpy4(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 4 *len);}static void cpy8(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;}void swri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len){int ch;int off=0;const int os=(out->planar?1:out->ch_count)*out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){int planes=in->planar?in->ch_count:1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){int planes=out->planar?out->ch_count:1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){int planes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
#define MATROSKA_ID_VIDEOPROJECTIONPRIVATE
Definition: matroska.h:158
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
#define MATROSKA_ID_ATTACHMENTS
Definition: matroska.h:61
static int64_t pts
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:473
#define flags(name, subs,...)
Definition: cbs_av1.c:564
#define MATROSKA_ID_CHAPTERDISPLAY
Definition: matroska.h:254
static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par)
Definition: matroskaenc.c:582
int bits_per_raw_sample
This is the number of valid bits in each output sample.
Definition: avcodec.h:4091
#define MATROSKA_ID_FILENAME
Definition: matroska.h:244
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:106
#define MATROSKA_ID_BLOCKADDITIONAL
Definition: matroska.h:231
uint32_t bound_top
Distance from the top edge.
Definition: spherical.h:168
const AVMetadataConv ff_mkv_metadata_conv[]
Definition: matroska.c:141
#define MATROSKA_ID_CODECID
Definition: matroska.h:88
static const AVCodecTag additional_video_tags[]
Definition: matroskaenc.c:2691
mkv_seekhead_entry entries[MAX_SEEKHEAD_ENTRIES]
Definition: matroskaenc.c:76
static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par)
Definition: matroskaenc.c:619
#define MATROSKA_ID_VIDEOFIELDORDER
Definition: matroska.h:122
int64_t start
Definition: avformat.h:1312
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
int sample_rate
Audio only.
Definition: avcodec.h:4146
int ff_flac_write_header(AVIOContext *pb, const uint8_t *extradata, int extradata_size, int last_block)
#define MATROSKA_ID_VIDEOALPHAMODE
Definition: matroska.h:124
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
static int mkv_write_trailer(AVFormatContext *s)
Definition: matroskaenc.c:2484
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:87
Main libavformat public API header.
static int mkv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
Definition: matroskaenc.c:2660
attribute_deprecated int64_t convergence_duration
Definition: avcodec.h:1562
#define MATROSKA_ID_CUETRACK
Definition: matroska.h:195
#define MATROSKA_ID_SEEKPOSITION
Definition: matroska.h:221
#define MATROSKA_ID_CODECDELAY
Definition: matroska.h:94
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:84
#define MATROSKA_ID_CHAPTERTIMESTART
Definition: matroska.h:252
common internal api header.
#define MATROSKA_ID_VIDEOCOLORRANGE
Definition: matroska.h:137
enum AVSphericalProjection projection
Projection type.
Definition: spherical.h:86
Utilties for rational number calculation.
static void end_ebml_master_crc32_preliminary(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, int64_t *pos)
Complete ebml master without destroying the buffer, allowing for later updates.
Definition: matroskaenc.c:369
static int mkv_write_flush_packet(AVFormatContext *s, AVPacket *pkt)
Definition: matroskaenc.c:2468
int disposition
AV_DISPOSITION_* bit field.
Definition: avformat.h:928
static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid, uint64_t expectedsize)
Definition: matroskaenc.c:313
static void put_ebml_void(AVIOContext *pb, uint64_t size)
Write a void element of a given size.
Definition: matroskaenc.c:296
int64_t last_timestamp
Definition: matroskaenc.c:101
Stereoscopic video.
Views are packed per column.
Definition: stereo3d.h:141
AVRational time_base
time base in which the start/end timestamps are specified
Definition: avformat.h:1311
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:33
char * key
Definition: dict.h:86
int den
Denominator.
Definition: rational.h:60
#define MATROSKA_ID_SEGMENT
Definition: matroska.h:53
#define MAX_PCE_SIZE
Maximum size of a PCE including the 3-bit ID_PCE.
Definition: mpeg4audio.h:134
The optional settings (rendering instructions) that immediately follow the timestamp specifier of a W...
Definition: avcodec.h:1389
#define MATROSKA_ID_SEEKHEAD
Definition: matroska.h:60
#define EBML_ID_HEADER
Definition: matroska.h:33
uint32_t elementid
Definition: matroskaenc.c:70
A point in the output bytestream where a decoder can start decoding (i.e.
Definition: avio.h:122
mkv_attachments * attachments
Definition: matroskaenc.c:144
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:465
#define av_free(p)
char * value
Definition: dict.h:87
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:85
#define MATROSKA_ID_POINTENTRY
Definition: matroska.h:188
int len
static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb, AVStream *st, int mode, int *h_width, int *h_height)
Definition: matroskaenc.c:1018
#define MATROSKA_ID_FILEUID
Definition: matroska.h:247
int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args)
Add a bitstream filter to a stream.
Definition: utils.c:5572
static void put_ebml_binary(AVIOContext *pb, uint32_t elementid, const void *buf, int size)
Definition: matroskaenc.c:276
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:417
void * priv_data
Format private data.
Definition: avformat.h:1380
#define MATROSKA_ID_CHAPTERUID
Definition: matroska.h:262
char str[22]
Definition: matroska.h:354
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:346
uint32_t bound_left
Distance from the left edge.
Definition: spherical.h:167
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: avcodec.h:4078
int64_t relative_pos
relative offset from the position of the cluster containing the block
Definition: matroskaenc.c:86
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:4050
#define MATROSKA_ID_VIDEOCOLORMAXFALL
Definition: matroska.h:142
#define MATROSKA_ID_VIDEODISPLAYUNIT
Definition: matroska.h:120
int channels
Audio only.
Definition: avcodec.h:4142
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1532
static const AVOption options[]
Definition: matroskaenc.c:2707
#define EBML_ID_EBMLMAXSIZELENGTH
Definition: matroska.h:39
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:375
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1467
#define MATROSKA_ID_CHAPSTRING
Definition: matroska.h:255
int sample_rate
Definition: matroskaenc.c:99
#define av_freep(p)
#define MATROSKA_ID_TAGSTRING
Definition: matroska.h:205
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
Definition: dict.h:70
#define MODE_MATROSKAv2
Definition: matroskaenc.c:118
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
Definition: random_seed.c:120
static void put_ebml_string(AVIOContext *pb, uint32_t elementid, const char *str)
Definition: matroskaenc.c:284
AVOutputFormat ff_matroska_muxer
const CodecMime ff_mkv_image_mime_tags[]
Definition: matroska.c:122
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1022
static void put_ebml_sint(AVIOContext *pb, uint32_t elementid, int64_t val)
Definition: matroskaenc.c:256
#define MODE_WEBM
Definition: matroskaenc.c:119
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: avcodec.h:4040
static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: matroskaenc.c:2394
#define MATROSKA_ID_DURATION
Definition: matroska.h:67
#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:172
static void mkv_deinit(AVFormatContext *s)
Free the members allocated in the mux context.
Definition: matroskaenc.c:390
static mkv_cues * mkv_start_cues(int64_t segment_offset)
Definition: matroskaenc.c:489
int stream_index
Definition: avcodec.h:1535
int num_entries
Definition: matroskaenc.c:93
#define EBML_ID_DOCTYPEVERSION
Definition: matroska.h:41
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:904
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
static void end_ebml_master(AVIOContext *pb, ebml_master master)
Definition: matroskaenc.c:323
int64_t segment_offset
Definition: matroskaenc.c:135
static int mkv_write_tag(AVFormatContext *s, AVDictionary *m, uint32_t elementid, unsigned int uid)
Definition: matroskaenc.c:1551
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:999
#define MATROSKA_ID_ATTACHEDFILE
Definition: matroska.h:242
#define MATROSKA_ID_VIDEOCOLOR_GY
Definition: matroska.h:148
enum AVCodecID id
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:87
unsigned MaxFALL
Max average light level per frame (cd/m^2).
This structure stores compressed data.
Definition: avcodec.h:1510
static void mkv_write_field_order(AVIOContext *pb, int mode, enum AVFieldOrder field_order)
Definition: matroskaenc.c:979
mode
Use these values in ebur128_init (or&#39;ed).
Definition: ebur128.h:83
#define MATROSKA_ID_VIDEOCOLOR_RY
Definition: matroska.h:146
uint32_t blocksize
Definition: wv.h:35
static int mkv_query_codec(enum AVCodecID codec_id, int std_compliance)
Definition: matroskaenc.c:2595
static void put_xiph_size(AVIOContext *pb, int size)
Definition: matroskaenc.c:381
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1526
Not part of ABI.
Definition: pixfmt.h:526
#define MATROSKA_ID_VIDEOPIXELWIDTH
Definition: matroska.h:114
int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
Definition: avc.c:108
#define MATROSKA_ID_TRACKAUDIO
Definition: matroska.h:82
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
int(* filler)(InterplayACMContext *s, unsigned ind, unsigned col)
Definition: interplayacm.c:407
AVIOContext * tags_bc
Definition: matroskaenc.c:128
const CodecTags ff_mkv_codec_tags[]
Definition: matroska.c:29
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
static int ebml_id_size(uint32_t id)
Definition: matroskaenc.c:184
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
#define MATROSKA_ID_DISCARDPADDING
Definition: matroska.h:239
#define FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX
Tell ff_put_wav_header() to use WAVEFORMATEX even for PCM codecs.
Definition: riff.h:54
static int mkv_write_video_projection(AVFormatContext *s, AVIOContext *pb, AVStream *st)
Definition: matroskaenc.c:909
void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.c:191
const char * name
Definition: opengl_enc.c:102
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1388
static uint8_t tmp[11]
Definition: aes_ctr.c:26