Go to the documentation of this file.
24 #include "config_components.h"
75 #define MAX_SEEKHEAD_ENTRIES 7
78 #define MAX_EBML_LENGTH ((1ULL << 56) - 2)
81 #define MAX_SUPPORTED_EBML_LENGTH FFMIN(MAX_EBML_LENGTH, INT_MAX)
83 #define MODE_MATROSKAv2 0x01
84 #define MODE_WEBM 0x02
86 #define IS_WEBM(mkv) (CONFIG_WEBM_MUXER && CONFIG_MATROSKA_MUXER ? \
87 ((mkv)->mode == MODE_WEBM) : CONFIG_WEBM_MUXER)
88 #define IS_SEEKABLE(pb, mkv) (((pb)->seekable & AVIO_SEEKABLE_NORMAL) && \
154 #define EBML_WRITER(max_nb_elems) \
155 EbmlElement elements[max_nb_elems]; \
156 EbmlWriter writer = (EbmlWriter){ .elements = elements, \
157 .current_master_element = -1 }
269 #define MAX_SEEKENTRY_SIZE 21
272 #define MAX_CUETRACKPOS_SIZE 40
276 #define DURATION_STRING_LENGTH 19
279 #define DURATION_SIMPLETAG_SIZE (2 + 1 + (2 + 1 + 8) + (2 + 1 + DURATION_STRING_LENGTH))
282 #define OPUS_SEEK_PREROLL 80000000
293 avio_w8(pb, (uint8_t)(
id >> (
i * 8)));
338 num |= 1ULL << bytes * 7;
339 for (
int i = bytes - 1;
i >= 0;
i--)
340 avio_w8(pb, (uint8_t)(num >>
i * 8));
357 bytes = needed_bytes;
383 for (
i = bytes - 1;
i >= 0;
i--)
395 const void *buf,
int size)
433 uint64_t expectedsize)
516 #if SIZE_MAX > UINT64_MAX
561 #if SIZE_MAX > UINT64_MAX
562 len = FF_MIN(
len, UINT64_MAX);
596 int remaining_elems);
603 uint64_t total_size = 0;
605 master->priv.master.nb_elements = nb_elems;
606 for (; elem++, nb_elems > 0;) {
617 elem +=
ret, nb_elems -=
ret;
619 master->size = total_size;
621 return master->priv.master.nb_elements;
675 switch (elem->
type) {
708 switch (elem->
type) {
720 for (
int i = elem->
size; --
i >= 0; )
727 : (
const uint8_t*)elem->
priv.
str;
738 for (
int i = 0;
i < nb_elems;
i++)
783 int length_size,
int keep_buffer,
786 uint8_t *buf, crc[4];
790 if ((
ret = (*dyn_cp)->error) < 0)
891 int error_on_seek_failure,
int64_t destpos)
899 return error_on_seek_failure ? ret64 : 0;
925 if ((ret64 =
avio_seek(pb, destpos, SEEK_SET)) < 0)
947 while (idx > 0 && entries[idx - 1].
pts > ts)
949 memmove(&entries[idx + 1], &entries[idx],
952 entries[idx].
pts = ts;
977 for (
int j = 0; j < num_tracks; j++)
978 tracks[j].has_cue = 0;
981 int idx =
entry->stream_idx;
991 if (
entry->duration > 0)
994 }
while (++entry < end && entry->
pts ==
pts);
996 if (cuepoint->
error < 0)
997 return cuepoint->
error;
1007 const uint8_t *extradata,
int extradata_size)
1009 const uint8_t *header_start[3];
1011 int first_header_size;
1015 first_header_size = 30;
1017 first_header_size = 42;
1020 first_header_size, header_start, header_len);
1027 for (j = 0; j < 2; j++) {
1030 for (j = 0; j < 3; j++)
1031 avio_write(pb, header_start[j], header_len[j]);
1036 #if CONFIG_MATROSKA_MUXER
1037 static int put_wv_codecpriv(
AVIOContext *pb,
const uint8_t *extradata,
int extradata_size)
1039 if (extradata && extradata_size == 2)
1048 const uint8_t *extradata,
int extradata_size)
1059 if (write_comment) {
1067 av_dict_set(&dict,
"WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0);
1084 const uint8_t *extradata,
int extradata_size,
1085 int *sample_rate,
int *output_sample_rate)
1098 "Error parsing AAC extradata, unable to determine samplerate.\n");
1108 *output_sample_rate = *sample_rate;
1119 const uint8_t *extradata,
1121 unsigned *size_to_reserve)
1134 #if CONFIG_MATROSKA_MUXER
1136 return put_flac_codecpriv(
s, dyn_cp, par, extradata, extradata_size);
1138 return put_wv_codecpriv(dyn_cp, extradata, extradata_size);
1144 extradata_size, 0,
s);
1149 if (extradata_size < 36) {
1151 "Invalid extradata found, ALAC expects a 36-byte "
1156 extradata_size - 12);
1160 avio_write(dyn_cp, extradata, extradata_size);
1165 unsigned stream_identifier, data_component_id;
1168 stream_identifier = 0x30;
1169 data_component_id = 0x0008;
1172 stream_identifier = 0x87;
1173 data_component_id = 0x0012;
1177 "Unset/unknown ARIB caption profile %d utilized!\n",
1181 avio_w8(dyn_cp, stream_identifier);
1191 avio_write(dyn_cp, extradata, extradata_size);
1199 const uint8_t *extradata,
int extradata_size,
1200 int native_id,
int qt_id,
1201 uint8_t **codecpriv,
int *codecpriv_size,
1202 unsigned *max_payload_size)
1205 unsigned size_to_reserve = 0;
1210 extradata, extradata_size,
1214 #if CONFIG_MATROSKA_MUXER
1223 avio_wb32(dyn_cp, 0x5a + extradata_size);
1227 avio_write(dyn_cp, extradata, extradata_size);
1265 if (dyn_cp->
error < 0)
1266 return dyn_cp->
error;
1267 *max_payload_size = *codecpriv_size + size_to_reserve;
1273 const uint8_t *codecpriv,
unsigned codecpriv_size)
1275 unsigned total_codecpriv_size = 0, total_size;
1277 av_assert1(codecpriv_size <= max_payload_size);
1279 if (!max_payload_size)
1284 if (codecpriv_size) {
1287 total_codecpriv_size = 2
U + length_size + codecpriv_size;
1288 if (total_codecpriv_size + 1 == total_size) {
1291 total_codecpriv_size++;
1297 if (total_codecpriv_size < total_size)
1302 uint8_t *side_data,
int side_data_size,
1304 mkv_track *track,
unsigned alternative_size)
1308 unsigned max_payload_size;
1309 int ret, codecpriv_size;
1312 side_data, side_data_size, 1, 0,
1313 &codecpriv, &codecpriv_size, &max_payload_size);
1316 if (codecpriv_size > track->
codecpriv_size && !alternative_size) {
1320 av_assert1(alternative_size < track->codecpriv_size);
1321 codecpriv_size = alternative_size;
1325 codecpriv, codecpriv_size);
1331 memcpy(par->
extradata, side_data, side_data_size);
1338 #define MAX_VIDEO_COLOR_ELEMS 20
1421 #define MAX_VIDEO_PROJECTION_ELEMS 6
1423 double *yaw,
double *roll)
1468 "non-orthogonal transformation.\n");
1479 double *yaw,
double *pitch,
double *roll)
1530 *yaw = (
double) spherical->
yaw / (1 << 16);
1532 *roll = (
double) spherical->
roll / (1 << 16);
1541 double yaw = 0, pitch = 0, roll = 0;
1560 #define MAX_FIELD_ORDER_ELEMS 2
1564 switch (field_order) {
1578 switch (field_order) {
1600 #define MAX_STEREO_MODE_ELEMS 1
1604 int *h_width,
int *h_height)
1606 const char *error_message_addendum =
"";
1613 #define FLAG(STEREOMODETYPE, BOOL) | (BOOL) << (STEREOMODETYPE)
1614 #define WDIV1(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM) \
1615 FLAG(STEREOMODETYPE, WDIV)
1616 #define WDIV2(STEREOMODETYPE, WDIV, HDIV, WEBM) \
1617 FLAG(STEREOMODETYPE, WDIV)
1621 #define HDIV1(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM) \
1622 FLAG(STEREOMODETYPE, HDIV)
1623 #define HDIV2(STEREOMODETYPE, WDIV, HDIV, WEBM) \
1624 FLAG(STEREOMODETYPE, HDIV)
1627 #define WEBM1(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM) \
1628 FLAG(STEREOMODETYPE, WEBM)
1629 #define WEBM2(STEREOMODETYPE, WDIV, HDIV, WEBM) \
1630 FLAG(STEREOMODETYPE, WEBM)
1645 long stereo_mode = strtol(
tag->value,
NULL, 0);
1655 #define STEREOMODE(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM) \
1656 [(STEREO3DTYPE)][!!((FLAGS) & AV_STEREO3D_FLAG_INVERT)] = (STEREOMODETYPE) + 1,
1657 #define NOTHING(STEREOMODETYPE, WDIV, HDIV, WEBM)
1658 static const unsigned char conversion_table[][2] = {
1682 if (is_webm && !(webm_bitfield >>
format)) {
1683 error_message_addendum =
" for WebM";
1687 *h_width = 1 << ((width_bitfield >>
format) & 1);
1688 *h_height = 1 << ((height_bitfield >>
format) & 1);
1696 "The specified stereo mode is not valid%s.\n",
1697 error_message_addendum);
1705 #if CONFIG_MATROSKA_MUXER
1763 int display_width_div = 1, display_height_div = 1;
1764 uint8_t color_space[4], projection_private[20];
1768 int cropped_width = par->
width, cropped_height = par->
height;
1782 &display_height_div);
1794 if (sd && sd->
size ==
sizeof(uint32_t) * 4) {
1795 uint64_t top, bottom,
left, right;
1803 (top + bottom) >= par->
height) {
1817 cropped_width -=
left + right;
1818 cropped_height -= top + bottom;
1825 if (d_width > INT_MAX) {
1829 if (d_width != cropped_width || display_width_div != 1 || display_height_div != 1) {
1830 if (
IS_WEBM(mkv) || display_width_div != 1 || display_height_div != 1) {
1832 d_width / display_width_div);
1834 cropped_height / display_height_div);
1842 display_aspect_ratio.
num);
1844 display_aspect_ratio.
den);
1849 }
else if (display_width_div != 1 || display_height_div != 1) {
1851 cropped_width / display_width_div);
1853 cropped_height / display_height_div);
1861 color_space,
sizeof(color_space));
1889 int output_sample_rate = 0;
1905 tag &&
tag->value[0] ?
tag->value :
"und");
1930 codec_id =
"D_WEBVTT/DESCRIPTIONS";
1943 "Only VP8 or VP9 or AV1 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM.\n");
1979 av_log(
s,
AV_LOG_ERROR,
"Raw RGB is not supported Natively in Matroska, you can use AVI or NUT or\n"
1980 "If you would like to store it anyway using VFW mode, enable allow_raw_vfw (-allow_raw_vfw 1)\n");
1988 int audio_frame_samples;
2000 if (frame_rate.
num > 0)
2003 if (CONFIG_MATROSKA_MUXER && !native_id &&
2013 else if (!native_id) {
2031 if (codecdelay < 0) {
2044 #if CONFIG_MATROSKA_MUXER
2047 &sample_rate, &output_sample_rate);
2056 if (audio_frame_samples)
2068 if (output_sample_rate)
2099 av_log(
s,
AV_LOG_ERROR,
"Only audio, video, and subtitles are supported for Matroska.\n");
2108 int codecpriv_size, max_payload_size;
2113 &codecpriv, &codecpriv_size, &max_payload_size);
2132 int video_default_idx = -1, audio_default_idx = -1, subtitle_default_idx = -1;
2143 int video_idx = -1, audio_idx = -1, subtitle_idx = -1;
2145 for (
i =
s->nb_streams - 1;
i >= 0;
i--) {
2149 #define CASE(type, variable) \
2150 case AVMEDIA_TYPE_ ## type: \
2151 variable ## _idx = i; \
2152 if (st->disposition & AV_DISPOSITION_DEFAULT) \
2153 variable ## _default_idx = i; \
2157 CASE(SUBTITLE, subtitle)
2162 video_default_idx =
FFMAX(video_default_idx, video_idx);
2163 audio_default_idx =
FFMAX(audio_default_idx, audio_idx);
2165 subtitle_default_idx =
FFMAX(subtitle_default_idx, subtitle_idx);
2167 for (
i = 0;
i <
s->nb_streams;
i++) {
2170 i == video_default_idx ||
i == audio_default_idx ||
2171 i == subtitle_default_idx;
2187 const uint8_t *lang =
NULL;
2193 if ((p = strrchr(p,
'-')) &&
2201 else if (*p >=
'a' && *p <=
'z')
2218 uint32_t elementid, uint64_t
uid)
2243 uint32_t elementid, uint64_t
uid)
2248 int ret = 0,
size, tag_written = 0;
2262 else if (!tag_written)
2266 if (tmp_bc->
error) {
2295 for (
i = 0;
i <
s->nb_streams;
i++) {
2312 for (
i = 0;
i <
s->nb_streams;
i++) {
2335 for (
unsigned i = 0;
i <
s->nb_chapters;
i++) {
2336 if (!
s->chapters[
i]->id)
2338 for (
unsigned j = 0; j <
i; j++)
2339 if (
s->chapters[j]->id ==
s->chapters[
i]->id)
2351 int ret, create_new_ids;
2371 for (
unsigned i = 0;
i <
s->nb_chapters;
i++) {
2376 uint64_t
uid = create_new_ids ?
i + 1ULL :
c->id;
2379 if (chapterstart < 0 || chapterstart > chapterend || chapterend < 0) {
2381 "Invalid chapter start (%"PRId64
") or end (%"PRId64
").\n",
2382 chapterstart, chapterend);
2439 return desc->mime_types[0];
2441 return "text/plain";
2460 for (
i = 0;
i <
s->nb_streams;
i++) {
2465 const char *mimetype;
2505 av_log(
s,
AV_LOG_DEBUG,
"get_metadata_duration found duration in context metadata: %" PRId64
"\n",
us);
2509 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
2522 const char *doctype,
int version)
2561 const char *ident =
"Lavf";
2568 int64_t date_utc = (creation_time - 978307200000000LL) * 1000;
2569 uint8_t date_utc_buf[8];
2570 AV_WB64(date_utc_buf, date_utc);
2580 if (
s->duration > 0) {
2583 av_log(
s,
AV_LOG_DEBUG,
"Write early duration from recording time = %" PRIu64
"\n", scaledDuration);
2584 }
else if (metadata_duration > 0) {
2587 av_log(
s,
AV_LOG_DEBUG,
"Write early duration from metadata = %" PRIu64
"\n", scaledDuration);
2611 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
2657 if (
s->metadata_header_padding > 0) {
2658 if (
s->metadata_header_padding == 1)
2659 s->metadata_header_padding++;
2694 #if CONFIG_MATROSKA_MUXER
2727 if (srclen <
header.blocksize)
2743 srclen -=
header.blocksize;
2765 const uint8_t *
id, *settings;
2766 size_t id_size, settings_size;
2769 if (total > INT_MAX)
2776 if (id_size > INT_MAX - total || settings_size > INT_MAX - (total += id_size))
2778 *
size = total += settings_size;
2790 size_t size, uint64_t additional_id)
2802 int force_blockgroup,
int64_t relative_packet_pos)
2806 size_t side_data_size;
2807 uint64_t additional_id;
2808 unsigned track_number = track->
track_num;
2831 "Writing block of size %d with pts %" PRId64
", dts %" PRId64
", "
2832 "duration %" PRId64
" at relative offset %" PRId64
" in cluster "
2833 "at offset %" PRId64
". TrackNumber %u, keyframe %d\n",
2840 if (side_data && side_data_size >= 10) {
2842 if (discard_padding) {
2854 if (side_data && side_data_size >= 8 &&
2866 if (side_data && side_data_size) {
2867 uint8_t *payload = t35_buf;
2868 size_t payload_size =
sizeof(t35_buf) - 6;
2872 bytestream_put_be16(&payload, 0x01);
2873 bytestream_put_byte(&payload, 0x04);
2889 if (!force_blockgroup && writer.nb_elements == 2) {
2892 writer.nb_elements--;
2897 }
else if (!keyframe)
2910 for (
unsigned i = 0;
i <
s->nb_streams;
i++)
2929 size_t side_data_size;
2936 #if CONFIG_MATROSKA_MUXER
2938 if (side_data_size && mkv->
track.
bc) {
2939 int output_sample_rate = 0;
2940 ret = get_aac_sample_rates(
s, mkv, side_data, side_data_size,
2944 if (!output_sample_rate)
2947 par, mkv->
track.
bc, track, 0);
2955 av_log(
s,
AV_LOG_ERROR,
"Error parsing AAC extradata, unable to determine samplerate.\n");
2960 if (side_data_size && mkv->
track.
bc) {
2967 par, mkv->
track.
bc, track, 0);
2980 par, mkv->
track.
bc, track, 4);
3018 if ((int16_t)cluster_time != cluster_time) {
3035 "Starting new cluster with timestamp "
3036 "%" PRId64
" at offset %" PRId64
" bytes\n",
3048 relative_packet_pos);
3078 int start_new_cluster;
3097 start_new_cluster = keyframe;
3101 start_new_cluster = 1;
3106 cluster_size > 4 * 1024))) {
3107 start_new_cluster = 1;
3109 start_new_cluster = 0;
3111 if (start_new_cluster) {
3129 "Could not write cached audio packet ret:%d\n",
ret);
3154 "Flushing cluster at offset %" PRIu64
" bytes\n",
3174 "Could not write cached audio packet ret:%d\n",
ret);
3198 int length_size = 0;
3215 size += 4 + length_size;
3223 "Insufficient space reserved for Cues: "
3224 "%d < %"PRIu64
". No Cues will be output.\n",
3258 if (size < mkv->reserve_cues_space)
3293 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
3328 for (
i = 0;
i <
s->nb_streams; ++
i) {
3345 snprintf(duration_string,
sizeof(duration_string),
"%02d:%02d:%012.9f",
3346 (
int) duration_sec / 3600, ((
int) duration_sec / 60) % 60,
3347 fmod(duration_sec, 60));
3376 for (k = 0; k <
i; k++) {
3377 if (tracks[k].
uid ==
uid)
3390 unsigned nb_tracks = 0;
3395 for (
i = 0;
i <
s->nb_streams;
i++) {
3404 "The Matroska muxer does not yet support muxing %s\n",
3410 if (
s->avoid_negative_ts < 0) {
3411 s->avoid_negative_ts = 1;
3415 if (!CONFIG_MATROSKA_MUXER ||
3416 (CONFIG_WEBM_MUXER && !strcmp(
s->oformat->name,
"webm"))) {
3432 for (
i = 0;
i < 4;
i++)
3436 for (
i = 0;
i <
s->nb_streams;
i++) {
3442 #if CONFIG_MATROSKA_MUXER
3444 track->
reformat = mkv_reformat_wavpack;
3453 track->
reformat = mkv_reformat_h2645;
3481 "as WebM doesn't support attachments.\n",
i);
3484 "tag and it cannot be deduced from the codec id.\n",
i);
3496 if (mkv->
is_dash && nb_tracks != 1)
3512 }
else if (CONFIG_MATROSKA_MUXER &&
3543 #define OFFSET(x) offsetof(MatroskaMuxContext, x)
3544 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM
3546 {
"reserve_index_space",
"reserve a given amount of space (in bytes) at the beginning of the file for the index (cues)",
OFFSET(reserve_cues_space),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX,
FLAGS },
3547 {
"cues_to_front",
"move Cues (the index) to the front by shifting data if necessary",
OFFSET(move_cues_to_front),
AV_OPT_TYPE_BOOL, { .i64 = 0}, 0, 1,
FLAGS },
3548 {
"cluster_size_limit",
"store at most the provided amount of bytes in a cluster",
OFFSET(cluster_size_limit),
AV_OPT_TYPE_INT , { .i64 = -1 }, -1, INT_MAX,
FLAGS },
3549 {
"cluster_time_limit",
"store at most the provided number of milliseconds in a cluster",
OFFSET(cluster_time_limit),
AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX,
FLAGS },
3550 {
"dash",
"create a WebM file conforming to WebM DASH specification",
OFFSET(is_dash),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
FLAGS },
3551 {
"dash_track_number",
"track number for the DASH stream",
OFFSET(dash_track_number),
AV_OPT_TYPE_INT, { .i64 = 1 }, 1, INT_MAX,
FLAGS },
3554 {
"flipped_raw_rgb",
"store raw RGB bitmaps in VFW mode in bottom-up mode",
OFFSET(flipped_raw_rgb),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
FLAGS },
3555 {
"write_crc32",
"write a CRC32 element inside every Level 1 element",
OFFSET(write_crc),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
FLAGS },
3557 {
"infer",
"for each track type, mark each track of disposition default as default; if none exists, mark the first track as default", 0,
AV_OPT_TYPE_CONST, { .i64 =
DEFAULT_MODE_INFER }, 0, 0,
FLAGS, .unit =
"default_mode" },
3558 {
"infer_no_subs",
"for each track type, mark each track of disposition default as default; for audio and video: if none exists, mark the first track as default", 0,
AV_OPT_TYPE_CONST, { .i64 =
DEFAULT_MODE_INFER_NO_SUBS }, 0, 0,
FLAGS, .unit =
"default_mode" },
3570 #if CONFIG_MATROSKA_MUXER
3588 .
p.
name =
"matroska",
3590 .p.mime_type =
"video/x-matroska",
3591 .p.extensions =
"mkv",
3593 .p.audio_codec = CONFIG_LIBVORBIS_ENCODER ?
3595 .p.video_codec = CONFIG_LIBX264_ENCODER ?
3613 .query_codec = mkv_query_codec,
3620 #if CONFIG_WEBM_MUXER
3633 .p.mime_type =
"video/webm",
3634 .p.extensions =
"webm",
3644 .query_codec = webm_query_codec,
3657 #if CONFIG_MATROSKA_AUDIO_MUXER
3659 .
p.
name =
"matroska",
3661 .p.mime_type =
"audio/x-matroska",
3662 .p.extensions =
"mka",
3664 .p.audio_codec = CONFIG_LIBVORBIS_ENCODER ?
#define MATROSKA_ID_TAGTARGETS_ATTACHUID
@ AV_PKT_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define MATROSKA_ID_VIDEODISPLAYUNIT
#define MATROSKA_ID_CODECPRIVATE
#define MATROSKA_ID_TRACKNUMBER
#define MATROSKA_ID_TRACKFLAGVISUALIMPAIRED
#define AV_LOG_WARNING
Something somehow does not look correct.
#define MATROSKA_ID_CHAPSTRING
#define IS_SEEKABLE(pb, mkv)
static int mkv_init(struct AVFormatContext *s)
#define MATROSKA_ID_TAGTARGETS
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
#define MATROSKA_ID_CLUSTERTIMECODE
static int ebml_num_size(uint64_t num)
Returns how many bytes are needed to represent a number as EBML variable length integer.
@ AVIO_DATA_MARKER_BOUNDARY_POINT
A point in the output bytestream where a demuxer can start parsing (for non self synchronizing bytest...
static int mkv_write_packet(AVFormatContext *s, const AVPacket *pkt)
#define MATROSKA_ID_TITLE
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static void put_ebml_size_unknown(AVIOContext *pb, int bytes)
Write an EBML size meaning "unknown size".
static void ebml_writer_add_string(EbmlWriter *writer, uint32_t id, const char *str)
static int mkv_write_packet_internal(AVFormatContext *s, const AVPacket *pkt)
static void ebml_writer_add_float(EbmlWriter *writer, uint32_t id, double val)
enum AVMediaType codec_type
General type of the encoded data.
enum AVSphericalProjection projection
Projection type.
#define AV1_SANE_SEQUENCE_HEADER_MAX_BITS
uint32_t bound_bottom
Distance from the bottom edge.
#define MATROSKA_ID_VIDEOCOLORMASTERINGMETA
static int ebml_writer_master_len(EbmlWriter *writer, EbmlElement *elem, int remaining_elems)
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
@ AV_PKT_DATA_FRAME_CROPPING
The number of pixels to discard from the top/bottom/left/right border of the decoded frame to obtain ...
This struct describes the properties of an encoded stream.
#define EBML_ID_EBMLMAXSIZELENGTH
static int mkv_new_chapter_ids_needed(const AVFormatContext *s)
enum AVColorSpace color_space
static int end_ebml_master_crc32(AVIOContext *pb, AVIOContext **dyn_cp, MatroskaMuxContext *mkv, uint32_t id, int length_size, int keep_buffer, int add_seekentry)
#define MATROSKA_ID_TRACKFLAGTEXTDESCRIPTIONS
@ 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...
enum AVMediaType avcodec_get_type(enum AVCodecID codec_id)
Get the type of the given codec.
#define MATROSKA_ID_VIDEOPIXELWIDTH
int containing_master
-1 if no parent exists
#define MATROSKA_ID_AUDIOSAMPLINGFREQ
@ AV_PKT_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata (based on SMPTE-2086:2014).
#define OPUS_SEEK_PREROLL
Seek preroll value for opus.
void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par, int for_asf, int ignore_extradata, int rgb_frame_is_flipped)
#define MATROSKA_ID_DISCARDPADDING
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
@ MATROSKA_VIDEO_FIELDORDER_BB
static void ebml_writer_add_uint(EbmlWriter *writer, uint32_t id, uint64_t val)
#define MATROSKA_ID_DURATION
#define MATROSKA_ID_VIDEOCOLORCHROMASITINGVERT
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
#define MATROSKA_ID_VIDEOCOLORPRIMARIES
#define MATROSKA_ID_SEGMENT
#define MATROSKA_ID_BLKADDIDTYPE
unsigned MaxCLL
Max content light level (cd/m^2).
int ff_isom_write_vvcc(AVIOContext *pb, const uint8_t *data, int size, int ps_array_completeness)
Writes H.266/VVC extradata (parameter sets, declarative SEI NAL units) to the provided AVIOContext.
static int ebml_writer_write(EbmlWriter *writer, AVIOContext *pb)
#define MATROSKA_ID_CHAPTERS
@ AVCOL_TRC_NB
Not part of ABI.
static int ebml_writer_elem_write(const EbmlElement *elem, AVIOContext *pb)
#define MATROSKA_ID_VIDEOCOLOR_BY
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
#define MATROSKA_ID_BLOCKDURATION
#define MATROSKA_ID_VIDEOCOLORRANGE
#define MATROSKA_ID_BLOCK
#define MATROSKA_ID_TRACKDEFAULTDURATION
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
static void put_xiph_size(AVIOContext *pb, int size)
@ AVCOL_SPC_NB
Not part of ABI.
AVRational avg_frame_rate
Average framerate.
@ MATROSKA_VIDEO_INTERLACE_FLAG_INTERLACED
static int mkv_write_attachments(AVFormatContext *s)
#define MATROSKA_ID_DATEUTC
static int ebml_id_size(uint32_t id)
int error
contains the error code or 0 if no error happened
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.
const AVCodecTag ff_codec_wav_tags[]
#define MATROSKA_ID_VIDEOPIXELCROPT
#define MATROSKA_ID_VIDEOPIXELCROPB
static void put_ebml_binary(AVIOContext *pb, uint32_t elementid, const void *buf, int size)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
@ AV_SPHERICAL_EQUIRECTANGULAR_TILE
Video represents a portion of a sphere mapped on a flat surface using equirectangular projection.
#define MAX_VIDEO_COLOR_ELEMS
enum AVChannelOrder order
Channel order used in this layout.
#define MATROSKA_ID_CUETIME
#define AV_PROFILE_ARIB_PROFILE_C
uint64_t mask
This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used for AV_CHANNEL_ORDER_AMBISONIC ...
#define MATROSKA_ID_CUERELATIVEPOSITION
int nb_channels
Number of channels in this layout.
#define MAX_PCE_SIZE
Maximum size of a PCE including the 3-bit ID_PCE.
int ff_flac_is_native_layout(uint64_t channel_layout)
@ AV_CODEC_ID_HDMV_PGS_SUBTITLE
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
@ AV_SPHERICAL_EQUIRECTANGULAR
Video represents a sphere mapped on a flat surface using equirectangular projection.
enum AVMediaType codec_type
union AVChannelLayout::@432 u
Details about which channels are present in this layout.
#define MATROSKA_ID_CHAPLANG
#define MATROSKA_ID_CUEDURATION
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
@ AV_FIELD_BT
Bottom coded first, top displayed first.
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
@ MATROSKA_VIDEO_DISPLAYUNIT_UNKNOWN
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
#define MATROSKA_ID_VIDEOCOLOR_LUMINANCEMAX
@ AV_PKT_DATA_DOVI_CONF
DOVI configuration ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2....
void avio_wl16(AVIOContext *s, unsigned int val)
enum AVColorPrimaries color_primaries
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
#define MATROSKA_ID_VIDEOCOLOR_WHITEY
#define NOTHING(STEREOMODETYPE, WDIV, HDIV, WEBM)
#define AV_PROFILE_ARIB_PROFILE_A
#define HDIV1(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM)
static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid, uint64_t expectedsize)
@ AV_FIELD_TT
Top coded_first, top displayed first.
#define DVCC_DVVC_BLOCK_TYPE_NAME
#define MATROSKA_ID_AUDIOOUTSAMPLINGFREQ
#define MAX_SUPPORTED_EBML_LENGTH
#define MATROSKA_ID_VIDEOPROJECTIONPRIVATE
int bits_per_raw_sample
This is the number of valid bits in each output sample.
static int ebml_writer_sint_len(EbmlElement *elem)
#define MATROSKA_ID_CHAPTERDISPLAY
#define MATROSKA_ID_TRACKUID
#define EBML_ID_DOCTYPEVERSION
@ AVCOL_RANGE_NB
Not part of ABI.
static void put_ebml_uint(AVIOContext *pb, uint32_t elementid, uint64_t val)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
const char *const ff_matroska_video_stereo_mode[MATROSKA_VIDEO_STEREOMODE_TYPE_NB]
static double val(void *priv, double ch)
@ MATROSKA_BLOCK_ADD_ID_TYPE_ITU_T_T35
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
#define MATROSKA_ID_VIDEOALPHAMODE
#define us(width, name, range_min, range_max, subs,...)
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
#define MATROSKA_ID_VIDEOCOLOR_WHITEX
@ AV_FIELD_TB
Top coded first, bottom displayed first.
@ MATROSKA_TRACK_TYPE_METADATA
@ MATROSKA_VIDEO_FIELDORDER_TT
@ AV_PKT_DATA_WEBVTT_SETTINGS
The optional settings (rendering instructions) that immediately follow the timestamp specifier of a W...
@ AV_CODEC_ID_DVB_SUBTITLE
MatroskaVideoStereoModeType
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
enum AVColorTransferCharacteristic color_trc
#define MATROSKA_ID_BLKADDIDNAME
static int mkv_write_tracks(AVFormatContext *s)
#define MATROSKA_ID_BLOCKADDITIONAL
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
#define MATROSKA_ID_VIDEOFIELDORDER
#define MATROSKA_ID_VIDEOPIXELCROPR
static const AVOption options[]
static void put_ebml_id(AVIOContext *pb, uint32_t id)
#define EBML_ID_EBMLMAXIDLENGTH
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
int64_t relative_pos
relative offset from the position of the cluster containing the block
static int mkv_update_codecprivate(AVFormatContext *s, MatroskaMuxContext *mkv, uint8_t *side_data, int side_data_size, AVCodecParameters *par, AVIOContext *pb, mkv_track *track, unsigned alternative_size)
int avpriv_mpeg4audio_get_config2(MPEG4AudioConfig *c, const uint8_t *buf, int size, int sync_extension, void *logctx)
Parse MPEG-4 systems extradata from a raw buffer to retrieve audio configuration.
static int ebml_writer_block_len(EbmlElement *elem)
This struct describes the properties of a single codec described by an AVCodecID.
static void end_ebml_master(AVIOContext *pb, ebml_master master)
#define MATROSKA_ID_FILEUID
@ MATROSKA_VIDEO_INTERLACE_FLAG_PROGRESSIVE
int av_chroma_location_enum_to_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
Converts AVChromaLocation to swscale x/y chroma position.
@ AVCOL_PRI_NB
Not part of ABI.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
#define MATROSKA_ID_VIDEODISPLAYWIDTH
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
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
static int mkv_write_flush_packet(AVFormatContext *s, AVPacket *pkt)
static void ebml_writer_add_block(EbmlWriter *writer, MatroskaMuxContext *mkv)
@ MATROSKA_VIDEO_FIELDORDER_BT
int64_t cluster_pos
file offset of the current Cluster
#define MATROSKA_ID_TAGNAME
uint32_t bound_top
Distance from the top edge.
static void ebml_writer_open_master(EbmlWriter *writer, uint32_t id)
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static void ebml_writer_add_uid(EbmlWriter *writer, uint32_t id, uint64_t val)
#define MATROSKA_ID_TIMECODESCALE
static const char * get_mimetype(const AVStream *st)
static void ebml_writer_add_sint(EbmlWriter *writer, uint32_t id, int64_t val)
static const AVClass matroska_webm_class
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define MATROSKA_ID_CUETRACKPOSITION
static const AVCodecTag additional_audio_tags[]
#define MATROSKA_ID_SEEKENTRY
void ff_isom_put_dvcc_dvvc(void *logctx, uint8_t out[ISOM_DVCC_DVVC_SIZE], const AVDOVIDecoderConfigurationRecord *dovi)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define MATROSKA_ID_TRACKTYPE
static void ebml_writer_close_master(EbmlWriter *writer)
#define MATROSKA_ID_SEGMENTUID
#define MATROSKA_ID_TRACKBLKADDMAPPING
@ AV_PKT_DATA_STEREO3D
This side data should be associated with a video stream and contains Stereoscopic 3D information in f...
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static av_const int sint_size(int64_t val)
int64_t cluster_time_limit
#define MATROSKA_ID_AUDIOCHANNELS
#define MATROSKA_ID_BLKADDIDVALUE
int nb_coded_side_data
Amount of entries in coded_side_data.
int ff_format_shift_data(AVFormatContext *s, int64_t read_start, int shift_size)
Make shift_size amount of space at read_start by shifting data in the output at read_start until the ...
#define MATROSKA_ID_VIDEOSTEREOMODE
static void mkv_start_seekhead(MatroskaMuxContext *mkv, AVIOContext *pb)
Initialize the SeekHead element to be ready to index level 1 Matroska elements.
const CodecTags ff_webm_codec_tags[]
#define HDIV2(STEREOMODETYPE, WDIV, HDIV, WEBM)
@ AV_CODEC_ID_ARIB_CAPTION
int flags
Additional information about the frame packing.
#define MATROSKA_ID_VIDEOCOLORSPACE
#define MATROSKA_ID_TRACKNAME
#define EBML_ID_DOCTYPEREADVERSION
#define MATROSKA_ID_TRACKFLAGHEARINGIMPAIRED
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define LIBAVUTIL_VERSION_INT
#define MATROSKA_ID_BLOCKGROUP
#define MATROSKA_ID_VIDEOCOLOR_LUMINANCEMIN
Describe the class of an AVClass context structure.
static int mkv_assemble_codecprivate(AVFormatContext *s, AVIOContext *dyn_cp, AVCodecParameters *par, const uint8_t *extradata, int extradata_size, int native_id, int qt_id, uint8_t **codecpriv, int *codecpriv_size, unsigned *max_payload_size)
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
#define MATROSKA_ID_ATTACHMENTS
#define STEREOMODE_STEREO3D_MAPPING(MAP, MKV_ONLY)
int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int flags)
Write WAVEFORMAT header structure.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define MATROSKA_ID_CHAPTERATOM
@ MATROSKA_TRACK_TYPE_AUDIO
static int ebml_length_size(uint64_t length)
Calculate how many bytes are needed to represent the length field of an EBML element whose payload ha...
#define STEREOMODE(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM)
#define MATROSKA_ID_TRACKFLAGORIGINAL
@ MATROSKA_VIDEO_DISPLAYUNIT_DAR
uint64_t default_duration_high
Rational number (pair of numerator and denominator).
#define MATROSKA_ID_WRITINGAPP
int ff_isom_write_hvcc(AVIOContext *pb, const uint8_t *data, int size, int ps_array_completeness, void *logctx)
Writes HEVC extradata (parameter sets and declarative SEI NAL units with nuh_layer_id == 0,...
#define MATROSKA_ID_VIDEOCOLOR_GY
@ AV_CODEC_ID_DVD_SUBTITLE
#define MAX_VIDEO_PROJECTION_ELEMS
const char * av_default_item_name(void *ptr)
Return the context name.
#define MATROSKA_ID_SIMPLETAG
#define MATROSKA_ID_VIDEOPROJECTION
static int mkv_assemble_native_codecprivate(AVFormatContext *s, AVIOContext *dyn_cp, const AVCodecParameters *par, const uint8_t *extradata, int extradata_size, unsigned *size_to_reserve)
static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, const AVCodecParameters *par, const uint8_t *extradata, int extradata_size)
#define MATROSKA_ID_SEEKID
static void put_ebml_num(AVIOContext *pb, uint64_t num, int bytes)
Write a number as EBML variable length integer on bytes bytes.
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
void avio_w8(AVIOContext *s, int b)
#define MATROSKA_ID_CHAPTERTIMESTART
const AVCodecTag ff_codec_movvideo_tags[]
void ffio_fill(AVIOContext *s, int b, int64_t count)
static void mkv_add_seekhead_entry(MatroskaMuxContext *mkv, uint32_t elementid, uint64_t filepos)
int64_t sample_rate_offset
static uint64_t mkv_get_uid(const mkv_track *tracks, int i, AVLFG *c)
@ MATROSKA_TRACK_TYPE_VIDEO
static EbmlElement * ebml_writer_add(EbmlWriter *writer, uint32_t id, EbmlType type)
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
static int64_t get_metadata_duration(AVFormatContext *s)
AVChannelLayout ch_layout
Audio only.
#define MATROSKA_ID_FILEMIMETYPE
#define MATROSKA_ID_VIDEODISPLAYHEIGHT
#define WDIV1(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM)
#define DURATION_STRING_LENGTH
DURATION_STRING_LENGTH must be <= 112 or the containing simpletag will need more than one byte for it...
@ AV_PKT_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
#define MATROSKA_ID_TRACKAUDIO
@ AVCOL_RANGE_UNSPECIFIED
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
int sample_rate
Audio only.
static void put_ebml_float(AVIOContext *pb, uint32_t elementid, double val)
static av_const int uint_size(uint64_t val)
AVCodecID
Identify the syntax and semantics of the bitstream.
const AVPacketSideData * av_packet_side_data_get(const AVPacketSideData *sd, int nb_sd, enum AVPacketSideDataType type)
Get side information from a side data array.
#define MATROSKA_ID_VIDEOCOLORMAXCLL
@ AV_PKT_DATA_SPHERICAL
This side data should be associated with a video stream and corresponds to the AVSphericalMapping str...
#define MATROSKA_ID_TRACKENTRY
#define WDIV2(STEREOMODETYPE, WDIV, HDIV, WEBM)
int extradata_size
Size of the extradata content in bytes.
int ff_wv_parse_header(WvHeader *wv, const uint8_t *data)
Parse a WavPack block header.
static void mkv_put_codecprivate(AVIOContext *pb, unsigned max_payload_size, const uint8_t *codecpriv, unsigned codecpriv_size)
static int mkv_write_header(AVFormatContext *s)
uint64_t default_duration_low
int64_t duration
duration of the block according to time base
int nb_elements
-1 if not finished
static void ebml_writer_add_bin(EbmlWriter *writer, uint32_t id, const uint8_t *data, size_t size)
int64_t blockadditionmapping_offset
#define MATROSKA_ID_AUDIOBITDEPTH
Context structure for the Lagged Fibonacci PRNG.
#define MATROSKA_ID_TRACKFLAGDEFAULT
@ AV_SPHERICAL_CUBEMAP
Video frame is split into 6 faces of a cube, and arranged on a 3x2 layout.
#define MATROSKA_ID_TRACKFLAGCOMMENTARY
void ffio_reset_dyn_buf(AVIOContext *s)
Reset a dynamic buffer.
static int mkv_write_stereo_mode(AVFormatContext *s, EbmlWriter *writer, const AVCodecParameters *par, const AVStream *st, int is_webm, int *h_width, int *h_height)
#define MATROSKA_ID_TRACKFLAGLACING