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