Go to the documentation of this file.
24 #include "config_components.h"
74 #define MAX_SEEKHEAD_ENTRIES 7
77 #define MAX_EBML_LENGTH ((1ULL << 56) - 2)
80 #define MAX_SUPPORTED_EBML_LENGTH FFMIN(MAX_EBML_LENGTH, INT_MAX)
82 #define MODE_MATROSKAv2 0x01
83 #define MODE_WEBM 0x02
85 #define IS_WEBM(mkv) (CONFIG_WEBM_MUXER && CONFIG_MATROSKA_MUXER ? \
86 ((mkv)->mode == MODE_WEBM) : CONFIG_WEBM_MUXER)
87 #define IS_SEEKABLE(pb, mkv) (((pb)->seekable & AVIO_SEEKABLE_NORMAL) && \
153 #define EBML_WRITER(max_nb_elems) \
154 EbmlElement elements[max_nb_elems]; \
155 EbmlWriter writer = (EbmlWriter){ .elements = elements, \
156 .current_master_element = -1 }
268 #define MAX_SEEKENTRY_SIZE 21
271 #define MAX_CUETRACKPOS_SIZE 40
275 #define DURATION_STRING_LENGTH 19
278 #define DURATION_SIMPLETAG_SIZE (2 + 1 + (2 + 1 + 8) + (2 + 1 + DURATION_STRING_LENGTH))
281 #define OPUS_SEEK_PREROLL 80000000
292 avio_w8(pb, (uint8_t)(
id >> (
i * 8)));
337 num |= 1ULL << bytes * 7;
338 for (
int i = bytes - 1;
i >= 0;
i--)
339 avio_w8(pb, (uint8_t)(num >>
i * 8));
356 bytes = needed_bytes;
382 for (
i = bytes - 1;
i >= 0;
i--)
394 const void *buf,
int size)
432 uint64_t expectedsize)
515 #if SIZE_MAX > UINT64_MAX
560 #if SIZE_MAX > UINT64_MAX
561 len = FF_MIN(
len, UINT64_MAX);
595 int remaining_elems);
602 uint64_t total_size = 0;
604 master->priv.master.nb_elements = nb_elems;
605 for (; elem++, nb_elems > 0;) {
616 elem +=
ret, nb_elems -=
ret;
618 master->size = total_size;
620 return master->priv.master.nb_elements;
674 switch (elem->
type) {
707 switch (elem->
type) {
719 for (
int i = elem->
size; --
i >= 0; )
726 : (
const uint8_t*)elem->
priv.
str;
737 for (
int i = 0;
i < nb_elems;
i++)
782 int length_size,
int keep_buffer,
785 uint8_t *buf, crc[4];
789 if ((
ret = (*dyn_cp)->error) < 0)
890 int error_on_seek_failure,
int64_t destpos)
898 return error_on_seek_failure ? ret64 : 0;
924 if ((ret64 =
avio_seek(pb, destpos, SEEK_SET)) < 0)
946 while (idx > 0 && entries[idx - 1].
pts > ts)
948 memmove(&entries[idx + 1], &entries[idx],
951 entries[idx].
pts = ts;
976 for (
int j = 0; j < num_tracks; j++)
977 tracks[j].has_cue = 0;
980 int idx =
entry->stream_idx;
990 if (
entry->duration > 0)
993 }
while (++entry < end && entry->
pts ==
pts);
995 if (cuepoint->
error < 0)
996 return cuepoint->
error;
1006 const uint8_t *extradata,
int extradata_size)
1008 const uint8_t *header_start[3];
1010 int first_header_size;
1014 first_header_size = 30;
1016 first_header_size = 42;
1019 first_header_size, header_start, header_len);
1026 for (j = 0; j < 2; j++) {
1029 for (j = 0; j < 3; j++)
1030 avio_write(pb, header_start[j], header_len[j]);
1035 #if CONFIG_MATROSKA_MUXER
1036 static int put_wv_codecpriv(
AVIOContext *pb,
const uint8_t *extradata,
int extradata_size)
1038 if (extradata && extradata_size == 2)
1047 const uint8_t *extradata,
int extradata_size)
1058 if (write_comment) {
1066 av_dict_set(&dict,
"WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0);
1083 const uint8_t *extradata,
int extradata_size,
1084 int *sample_rate,
int *output_sample_rate)
1097 "Error parsing AAC extradata, unable to determine samplerate.\n");
1107 *output_sample_rate = *sample_rate;
1118 const uint8_t *extradata,
1120 unsigned *size_to_reserve)
1133 #if CONFIG_MATROSKA_MUXER
1135 return put_flac_codecpriv(
s, dyn_cp, par, extradata, extradata_size);
1137 return put_wv_codecpriv(dyn_cp, extradata, extradata_size);
1143 extradata_size, 0,
s);
1145 if (extradata_size < 36) {
1147 "Invalid extradata found, ALAC expects a 36-byte "
1152 extradata_size - 12);
1156 avio_write(dyn_cp, extradata, extradata_size);
1161 unsigned stream_identifier, data_component_id;
1164 stream_identifier = 0x30;
1165 data_component_id = 0x0008;
1168 stream_identifier = 0x87;
1169 data_component_id = 0x0012;
1173 "Unset/unknown ARIB caption profile %d utilized!\n",
1177 avio_w8(dyn_cp, stream_identifier);
1187 avio_write(dyn_cp, extradata, extradata_size);
1195 const uint8_t *extradata,
int extradata_size,
1196 int native_id,
int qt_id,
1197 uint8_t **codecpriv,
int *codecpriv_size,
1198 unsigned *max_payload_size)
1201 unsigned size_to_reserve = 0;
1206 extradata, extradata_size,
1210 #if CONFIG_MATROSKA_MUXER
1219 avio_wb32(dyn_cp, 0x5a + extradata_size);
1223 avio_write(dyn_cp, extradata, extradata_size);
1261 if (dyn_cp->
error < 0)
1262 return dyn_cp->
error;
1263 *max_payload_size = *codecpriv_size + size_to_reserve;
1269 const uint8_t *codecpriv,
unsigned codecpriv_size)
1271 unsigned total_codecpriv_size = 0, total_size;
1273 av_assert1(codecpriv_size <= max_payload_size);
1275 if (!max_payload_size)
1280 if (codecpriv_size) {
1283 total_codecpriv_size = 2
U + length_size + codecpriv_size;
1284 if (total_codecpriv_size + 1 == total_size) {
1287 total_codecpriv_size++;
1293 if (total_codecpriv_size < total_size)
1298 uint8_t *side_data,
int side_data_size,
1300 mkv_track *track,
unsigned alternative_size)
1304 unsigned max_payload_size;
1305 int ret, codecpriv_size;
1308 side_data, side_data_size, 1, 0,
1309 &codecpriv, &codecpriv_size, &max_payload_size);
1312 if (codecpriv_size > track->
codecpriv_size && !alternative_size) {
1316 av_assert1(alternative_size < track->codecpriv_size);
1317 codecpriv_size = alternative_size;
1321 codecpriv, codecpriv_size);
1327 memcpy(par->
extradata, side_data, side_data_size);
1334 #define MAX_VIDEO_COLOR_ELEMS 20
1417 #define MAX_VIDEO_PROJECTION_ELEMS 6
1419 double *yaw,
double *roll)
1464 "non-orthogonal transformation.\n");
1475 double *yaw,
double *pitch,
double *roll)
1526 *yaw = (
double) spherical->
yaw / (1 << 16);
1528 *roll = (
double) spherical->
roll / (1 << 16);
1537 double yaw = 0, pitch = 0, roll = 0;
1556 #define MAX_FIELD_ORDER_ELEMS 2
1560 switch (field_order) {
1574 switch (field_order) {
1596 #define MAX_STEREO_MODE_ELEMS 1
1600 int *h_width,
int *h_height)
1602 const char *error_message_addendum =
"";
1609 #define FLAG(STEREOMODETYPE, BOOL) | (BOOL) << (STEREOMODETYPE)
1610 #define WDIV1(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM) \
1611 FLAG(STEREOMODETYPE, WDIV)
1612 #define WDIV2(STEREOMODETYPE, WDIV, HDIV, WEBM) \
1613 FLAG(STEREOMODETYPE, WDIV)
1617 #define HDIV1(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM) \
1618 FLAG(STEREOMODETYPE, HDIV)
1619 #define HDIV2(STEREOMODETYPE, WDIV, HDIV, WEBM) \
1620 FLAG(STEREOMODETYPE, HDIV)
1623 #define WEBM1(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM) \
1624 FLAG(STEREOMODETYPE, WEBM)
1625 #define WEBM2(STEREOMODETYPE, WDIV, HDIV, WEBM) \
1626 FLAG(STEREOMODETYPE, WEBM)
1641 long stereo_mode = strtol(
tag->value,
NULL, 0);
1651 #define STEREOMODE(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM) \
1652 [(STEREO3DTYPE)][!!((FLAGS) & AV_STEREO3D_FLAG_INVERT)] = (STEREOMODETYPE) + 1,
1653 #define NOTHING(STEREOMODETYPE, WDIV, HDIV, WEBM)
1654 static const unsigned char conversion_table[][2] = {
1678 if (is_webm && !(webm_bitfield >>
format)) {
1679 error_message_addendum =
" for WebM";
1683 *h_width = 1 << ((width_bitfield >>
format) & 1);
1684 *h_height = 1 << ((height_bitfield >>
format) & 1);
1692 "The specified stereo mode is not valid%s.\n",
1693 error_message_addendum);
1701 #if CONFIG_MATROSKA_MUXER
1759 int display_width_div = 1, display_height_div = 1;
1760 uint8_t color_space[4], projection_private[20];
1764 int cropped_width = par->
width, cropped_height = par->
height;
1778 &display_height_div);
1790 if (sd && sd->
size ==
sizeof(uint32_t) * 4) {
1791 uint64_t top, bottom,
left, right;
1799 (top + bottom) >= par->
height) {
1813 cropped_width -=
left + right;
1814 cropped_height -= top + bottom;
1821 if (d_width > INT_MAX) {
1825 if (d_width != cropped_width || display_width_div != 1 || display_height_div != 1) {
1826 if (
IS_WEBM(mkv) || display_width_div != 1 || display_height_div != 1) {
1828 d_width / display_width_div);
1830 cropped_height / display_height_div);
1838 display_aspect_ratio.
num);
1840 display_aspect_ratio.
den);
1845 }
else if (display_width_div != 1 || display_height_div != 1) {
1847 cropped_width / display_width_div);
1849 cropped_height / display_height_div);
1857 color_space,
sizeof(color_space));
1885 int output_sample_rate = 0;
1901 tag &&
tag->value[0] ?
tag->value :
"und");
1926 codec_id =
"D_WEBVTT/DESCRIPTIONS";
1939 "Only VP8 or VP9 or AV1 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM.\n");
1975 av_log(
s,
AV_LOG_ERROR,
"Raw RGB is not supported Natively in Matroska, you can use AVI or NUT or\n"
1976 "If you would like to store it anyway using VFW mode, enable allow_raw_vfw (-allow_raw_vfw 1)\n");
1984 int audio_frame_samples;
1996 if (frame_rate.
num > 0)
1999 if (CONFIG_MATROSKA_MUXER && !native_id &&
2009 else if (!native_id) {
2027 if (codecdelay < 0) {
2040 #if CONFIG_MATROSKA_MUXER
2043 &sample_rate, &output_sample_rate);
2052 if (audio_frame_samples)
2064 if (output_sample_rate)
2095 av_log(
s,
AV_LOG_ERROR,
"Only audio, video, and subtitles are supported for Matroska.\n");
2104 int codecpriv_size, max_payload_size;
2109 &codecpriv, &codecpriv_size, &max_payload_size);
2128 int video_default_idx = -1, audio_default_idx = -1, subtitle_default_idx = -1;
2139 int video_idx = -1, audio_idx = -1, subtitle_idx = -1;
2141 for (
i =
s->nb_streams - 1;
i >= 0;
i--) {
2145 #define CASE(type, variable) \
2146 case AVMEDIA_TYPE_ ## type: \
2147 variable ## _idx = i; \
2148 if (st->disposition & AV_DISPOSITION_DEFAULT) \
2149 variable ## _default_idx = i; \
2153 CASE(SUBTITLE, subtitle)
2158 video_default_idx =
FFMAX(video_default_idx, video_idx);
2159 audio_default_idx =
FFMAX(audio_default_idx, audio_idx);
2161 subtitle_default_idx =
FFMAX(subtitle_default_idx, subtitle_idx);
2163 for (
i = 0;
i <
s->nb_streams;
i++) {
2166 i == video_default_idx ||
i == audio_default_idx ||
2167 i == subtitle_default_idx;
2183 const uint8_t *lang =
NULL;
2189 if ((p = strrchr(p,
'-')) &&
2197 else if (*p >=
'a' && *p <=
'z')
2214 uint32_t elementid, uint64_t
uid)
2239 uint32_t elementid, uint64_t
uid)
2244 int ret = 0,
size, tag_written = 0;
2258 else if (!tag_written)
2262 if (tmp_bc->
error) {
2291 for (
i = 0;
i <
s->nb_streams;
i++) {
2308 for (
i = 0;
i <
s->nb_streams;
i++) {
2331 for (
unsigned i = 0;
i <
s->nb_chapters;
i++) {
2332 if (!
s->chapters[
i]->id)
2334 for (
unsigned j = 0; j <
i; j++)
2335 if (
s->chapters[j]->id ==
s->chapters[
i]->id)
2347 int ret, create_new_ids;
2367 for (
unsigned i = 0;
i <
s->nb_chapters;
i++) {
2372 uint64_t
uid = create_new_ids ?
i + 1ULL :
c->id;
2375 if (chapterstart < 0 || chapterstart > chapterend || chapterend < 0) {
2377 "Invalid chapter start (%"PRId64
") or end (%"PRId64
").\n",
2378 chapterstart, chapterend);
2435 return desc->mime_types[0];
2437 return "text/plain";
2456 for (
i = 0;
i <
s->nb_streams;
i++) {
2461 const char *mimetype;
2501 av_log(
s,
AV_LOG_DEBUG,
"get_metadata_duration found duration in context metadata: %" PRId64
"\n",
us);
2505 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
2518 const char *doctype,
int version)
2557 const char *ident =
"Lavf";
2564 int64_t date_utc = (creation_time - 978307200000000LL) * 1000;
2565 uint8_t date_utc_buf[8];
2566 AV_WB64(date_utc_buf, date_utc);
2576 if (
s->duration > 0) {
2579 av_log(
s,
AV_LOG_DEBUG,
"Write early duration from recording time = %" PRIu64
"\n", scaledDuration);
2580 }
else if (metadata_duration > 0) {
2583 av_log(
s,
AV_LOG_DEBUG,
"Write early duration from metadata = %" PRIu64
"\n", scaledDuration);
2607 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
2653 if (
s->metadata_header_padding > 0) {
2654 if (
s->metadata_header_padding == 1)
2655 s->metadata_header_padding++;
2690 #if CONFIG_MATROSKA_MUXER
2723 if (srclen <
header.blocksize)
2739 srclen -=
header.blocksize;
2761 const uint8_t *
id, *settings;
2762 size_t id_size, settings_size;
2765 if (total > INT_MAX)
2772 if (id_size > INT_MAX - total || settings_size > INT_MAX - (total += id_size))
2774 *
size = total += settings_size;
2786 size_t size, uint64_t additional_id)
2798 int force_blockgroup,
int64_t relative_packet_pos)
2802 size_t side_data_size;
2803 uint64_t additional_id;
2804 unsigned track_number = track->
track_num;
2827 "Writing block of size %d with pts %" PRId64
", dts %" PRId64
", "
2828 "duration %" PRId64
" at relative offset %" PRId64
" in cluster "
2829 "at offset %" PRId64
". TrackNumber %u, keyframe %d\n",
2836 if (side_data && side_data_size >= 10) {
2838 if (discard_padding) {
2850 if (side_data && side_data_size >= 8 &&
2862 if (side_data && side_data_size) {
2863 uint8_t *payload = t35_buf;
2864 size_t payload_size =
sizeof(t35_buf) - 6;
2868 bytestream_put_be16(&payload, 0x01);
2869 bytestream_put_byte(&payload, 0x04);
2885 if (!force_blockgroup && writer.nb_elements == 2) {
2888 writer.nb_elements--;
2893 }
else if (!keyframe)
2906 for (
unsigned i = 0;
i <
s->nb_streams;
i++)
2925 size_t side_data_size;
2932 #if CONFIG_MATROSKA_MUXER
2934 if (side_data_size && mkv->
track.
bc) {
2935 int output_sample_rate = 0;
2936 ret = get_aac_sample_rates(
s, mkv, side_data, side_data_size,
2940 if (!output_sample_rate)
2943 par, mkv->
track.
bc, track, 0);
2951 av_log(
s,
AV_LOG_ERROR,
"Error parsing AAC extradata, unable to determine samplerate.\n");
2956 if (side_data_size && mkv->
track.
bc) {
2963 par, mkv->
track.
bc, track, 0);
2976 par, mkv->
track.
bc, track, 4);
3014 if ((int16_t)cluster_time != cluster_time) {
3031 "Starting new cluster with timestamp "
3032 "%" PRId64
" at offset %" PRId64
" bytes\n",
3044 relative_packet_pos);
3074 int start_new_cluster;
3093 start_new_cluster = keyframe;
3097 start_new_cluster = 1;
3102 cluster_size > 4 * 1024))) {
3103 start_new_cluster = 1;
3105 start_new_cluster = 0;
3107 if (start_new_cluster) {
3125 "Could not write cached audio packet ret:%d\n",
ret);
3150 "Flushing cluster at offset %" PRIu64
" bytes\n",
3170 "Could not write cached audio packet ret:%d\n",
ret);
3194 int length_size = 0;
3211 size += 4 + length_size;
3219 "Insufficient space reserved for Cues: "
3220 "%d < %"PRIu64
". No Cues will be output.\n",
3254 if (size < mkv->reserve_cues_space)
3289 for (
unsigned i = 0;
i <
s->nb_streams;
i++) {
3324 for (
i = 0;
i <
s->nb_streams; ++
i) {
3341 snprintf(duration_string,
sizeof(duration_string),
"%02d:%02d:%012.9f",
3342 (
int) duration_sec / 3600, ((
int) duration_sec / 60) % 60,
3343 fmod(duration_sec, 60));
3372 for (k = 0; k <
i; k++) {
3373 if (tracks[k].
uid ==
uid)
3386 unsigned nb_tracks = 0;
3391 for (
i = 0;
i <
s->nb_streams;
i++) {
3400 "The Matroska muxer does not yet support muxing %s\n",
3406 if (
s->avoid_negative_ts < 0) {
3407 s->avoid_negative_ts = 1;
3411 if (!CONFIG_MATROSKA_MUXER ||
3412 (CONFIG_WEBM_MUXER && !strcmp(
s->oformat->name,
"webm"))) {
3428 for (
i = 0;
i < 4;
i++)
3432 for (
i = 0;
i <
s->nb_streams;
i++) {
3438 #if CONFIG_MATROSKA_MUXER
3440 track->
reformat = mkv_reformat_wavpack;
3447 track->
reformat = mkv_reformat_h2645;
3475 "as WebM doesn't support attachments.\n",
i);
3478 "tag and it cannot be deduced from the codec id.\n",
i);
3490 if (mkv->
is_dash && nb_tracks != 1)
3506 }
else if (CONFIG_MATROSKA_MUXER &&
3537 #define OFFSET(x) offsetof(MatroskaMuxContext, x)
3538 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM
3540 {
"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 },
3541 {
"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 },
3542 {
"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 },
3543 {
"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 },
3544 {
"dash",
"create a WebM file conforming to WebM DASH specification",
OFFSET(is_dash),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
FLAGS },
3545 {
"dash_track_number",
"track number for the DASH stream",
OFFSET(dash_track_number),
AV_OPT_TYPE_INT, { .i64 = 1 }, 1, INT_MAX,
FLAGS },
3548 {
"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 },
3549 {
"write_crc32",
"write a CRC32 element inside every Level 1 element",
OFFSET(write_crc),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
FLAGS },
3551 {
"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" },
3552 {
"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" },
3564 #if CONFIG_MATROSKA_MUXER
3582 .
p.
name =
"matroska",
3584 .p.mime_type =
"video/x-matroska",
3585 .p.extensions =
"mkv",
3587 .p.audio_codec = CONFIG_LIBVORBIS_ENCODER ?
3589 .p.video_codec = CONFIG_LIBX264_ENCODER ?
3607 .query_codec = mkv_query_codec,
3614 #if CONFIG_WEBM_MUXER
3627 .p.mime_type =
"video/webm",
3628 .p.extensions =
"webm",
3638 .query_codec = webm_query_codec,
3651 #if CONFIG_MATROSKA_AUDIO_MUXER
3653 .
p.
name =
"matroska",
3655 .p.mime_type =
"audio/x-matroska",
3656 .p.extensions =
"mka",
3658 .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).
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
union EbmlElement::@399 priv
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
#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)
union AVChannelLayout::@428 u
Details about which channels are present in this layout.
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)
@ DEFAULT_MODE_PASSTHROUGH
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
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define MATROSKA_ID_VIDEOCOLOR_GX
#define FF_OFMT_FLAG_ALLOW_FLUSH
This flag indicates that the muxer stores data internally and supports flushing it.
int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
uint32_t bound_right
Distance from the right edge.
static void mkv_write_field_order(EbmlWriter *writer, int is_webm, enum AVFieldOrder field_order)
@ AV_PKT_DATA_DYNAMIC_HDR10_PLUS
HDR10+ dynamic metadata associated with a video frame.
const char * ff_convert_lang_to(const char *lang, enum AVLangCodespace target_codespace)
Convert a language code to a target codespace.
#define MATROSKA_ID_FILEDATA
int sizebytes
how many bytes were reserved for the size
#define MATROSKA_ID_VIDEOPROJECTIONPOSEPITCH
static int mkv_handle_spherical(void *logctx, EbmlWriter *writer, const AVCodecParameters *par, uint8_t private[], double *yaw, double *pitch, double *roll)
#define MATROSKA_ID_BLOCKMORE
#define MAX_SEEKHEAD_ENTRIES
@ MATROSKA_BLOCK_ADD_ID_TYPE_OPAQUE
int current_master_element
#define AV_NOPTS_VALUE
Undefined timestamp value.
static void put_ebml_void(AVIOContext *pb, int size)
Write a void element of a given size.
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
#define MATROSKA_ID_VIDEOCOLORMAXFALL
uint64_t size
excluding id and length field
#define FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX
Tell ff_put_wav_header() to use WAVEFORMATEX even for PCM codecs.
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
This function is the same as av_get_audio_frame_duration(), except it works with AVCodecParameters in...
int profile
Codec-specific bitstream restrictions that the stream conforms to.
@ AVCHROMA_LOC_UNSPECIFIED
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
@ AVIO_DATA_MARKER_SYNC_POINT
A point in the output bytestream where a decoder can start decoding (i.e.
unsigned codecpriv_size
size reserved for CodecPrivate excluding header+length field
static int start_ebml_master_crc32(AVIOContext **dyn_cp, MatroskaMuxContext *mkv)
#define MATROSKA_ID_POINTENTRY
static const uint8_t header[24]
#define MATROSKA_ID_BLKADDIDEXTRADATA
#define CASE(type, variable)
int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size, int write_seq_header)
Writes AV1 extradata (Sequence Header and Metadata OBUs) to the provided AVIOContext.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
#define MAX_FIELD_ORDER_ELEMS
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
void avio_wb32(AVIOContext *s, unsigned int val)
#define FF_COMPLIANCE_NORMAL
uint32_t padding
Number of pixels to pad from the edge of each cube face.
static const AVCodecTag additional_subtitle_tags[]
struct MatroskaMuxContext * mkv
used by EBML_BLOCK
void avio_wl32(AVIOContext *s, unsigned int val)
static void mkv_write_blockadditional(EbmlWriter *writer, const uint8_t *buf, size_t size, uint64_t additional_id)
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
static void mkv_write_video_projection(void *logctx, EbmlWriter *wr, const AVCodecParameters *par, uint8_t private[])
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
static void mkv_write_tag_targets(MatroskaMuxContext *mkv, AVIOContext *pb, uint32_t elementid, uint64_t uid)
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
int flags
A combination of AV_PKT_FLAG values.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
static int mkv_write_trailer(AVFormatContext *s)
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
#define MATROSKA_ID_VIDEOPIXELHEIGHT
static int mkv_write_tags(AVFormatContext *s)
#define AV_LOG_INFO
Standard information.
#define MATROSKA_ID_MUXINGAPP
static void mkv_write_video_color(EbmlWriter *writer, const AVStream *st, const AVCodecParameters *par)
#define MATROSKA_ID_EDITIONFLAGDEFAULT
#define MATROSKA_ID_FILEDESC
void ff_nal_units_write_list(const NALUList *list, AVIOContext *pb, const uint8_t *buf)
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
#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...
#define MATROSKA_ID_VIDEOPROJECTIONTYPE
static av_always_inline uint64_t av_double2int(double f)
Reinterpret a double as a 64-bit integer.
#define MATROSKA_ID_FILENAME
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
int32_t roll
Rotation around the forward vector [-180, 180].
#define MATROSKA_ID_CODECID
int direct
avio_read and avio_write should if possible be satisfied directly instead of going through a buffer,...
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
static void put_ebml_length(AVIOContext *pb, uint64_t length, int bytes)
Write a length as EBML variable length integer.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
#define av_builtin_constant_p
#define AV_TIME_BASE
Internal time base represented as integer.
#define MATROSKA_ID_CUECLUSTERPOSITION
int64_t cluster_pos
offset of the cluster containing the block relative to the segment
static void mkv_write_default_duration(mkv_track *track, AVIOContext *pb, AVRational duration)
#define MATROSKA_ID_CUETRACK
mkv_seekhead_entry entries[MAX_SEEKHEAD_ENTRIES]
@ AV_FIELD_BB
Bottom coded first, bottom displayed first.
#define MATROSKA_ID_SEEKPOSITION
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define MATROSKA_ID_CLUSTER
#define MATROSKA_ID_TRACKLANGUAGE
int64_t pos
absolute offset in the containing AVIOContext where the master's elements start
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
#define MATROSKA_ID_VIDEOFLAGINTERLACED
#define EBML_WRITER(max_nb_elems)
#define MATROSKA_BLOCK_ADD_ID_ITU_T_T35
const AVMetadataConv ff_mkv_metadata_conv[]
static int mkv_write_track_video(AVFormatContext *s, MatroskaMuxContext *mkv, const AVStream *st, const AVCodecParameters *par, AVIOContext *pb)
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
enum AVColorRange color_range
Video only.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
static int mkv_check_tag_name(const char *name, uint32_t elementid)
AVPacketSideData * coded_side_data
Additional data associated with the entire stream.
#define MATROSKA_ID_CHAPTERUID
void * av_calloc(size_t nmemb, size_t size)
static int mkv_reformat_av1(MatroskaMuxContext *mkv, AVIOContext *pb, const AVPacket *pkt, int *size)
static void ebml_writer_close_or_discard_master(EbmlWriter *writer)
enum AVFieldOrder field_order
Video only.
static int mkv_write_tag(MatroskaMuxContext *mkv, const AVDictionary *m, AVIOContext **pb, unsigned reserved_size, uint32_t elementid, uint64_t uid)
This struct represents dynamic metadata for color volume transform - application 4 of SMPTE 2094-40:2...
static int mkv_end_cluster(AVFormatContext *s)
#define MATROSKA_ID_VIDEOPROJECTIONPOSEYAW
static void ebml_write_header(AVIOContext *pb, const char *doctype, int version)
static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp, AVIOContext *cuepoint, const mkv_cues *cues, mkv_track *tracks, int num_tracks, uint64_t offset)
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
@ AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL
Data found in BlockAdditional element of matroska container.
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
static int mkv_write_block(void *logctx, MatroskaMuxContext *mkv, AVIOContext *pb, const AVCodecParameters *par, mkv_track *track, const AVPacket *pkt, int keyframe, int64_t ts, uint64_t duration, int force_blockgroup, int64_t relative_packet_pos)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
@ DEFAULT_MODE_INFER_NO_SUBS
int32_t pitch
Rotation around the right vector [-90, 90].
int ff_av1_filter_obus(AVIOContext *pb, const uint8_t *buf, int size)
Filter out AV1 OBUs not meant to be present in ISOBMFF sample data and write the resulting bitstream ...
enum AVStereo3DType type
How views are packed within the video.
#define MATROSKA_ID_VIDEOCOLOR_BX
#define MATROSKA_ID_TAGSTRING
static void put_ebml_string(AVIOContext *pb, uint32_t elementid, const char *str)
#define MATROSKA_ID_VIDEOCOLORMATRIXCOEFF
#define WEBM1(STEREOMODETYPE, STEREO3DTYPE, FLAGS, WDIV, HDIV, WEBM)
@ AV_CODEC_ID_TEXT
raw UTF-8 text
#define MATROSKA_ID_SIMPLEBLOCK
static int ebml_writer_str_len(EbmlElement *elem)
#define MATROSKA_ID_VIDEOPIXELCROPL
@ MATROSKA_BLOCK_ADD_ID_TYPE_DVVC
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
enum AVChromaLocation chroma_location
static void mkv_deinit(AVFormatContext *s)
Free the members allocated in the mux context.
#define WEBM2(STEREOMODETYPE, WDIV, HDIV, WEBM)
static int ebml_writer_uint_len(EbmlElement *elem)
@ AV_PKT_DATA_WEBVTT_IDENTIFIER
The optional first identifier line of a WebVTT cue.
#define MAX_STEREO_MODE_ELEMS
static int webm_reformat_vtt(MatroskaMuxContext *mkv, AVIOContext *pb, const AVPacket *pkt, int *size)
#define MATROSKA_ID_EDITIONENTRY
int(* reformat)(struct MatroskaMuxContext *, AVIOContext *, const AVPacket *, int *size)
const AVCodecTag ff_codec_bmp_tags[]
#define MATROSKA_ID_TRACKMAXBLKADDID
#define EBML_ID_EBMLVERSION
#define DURATION_SIMPLETAG_SIZE
2 + 1 Simpletag header, 2 + 1 + 8 Name "DURATION", rest for TagString
#define ISOM_DVCC_DVVC_SIZE
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
static int ebml_writer_elem_len(EbmlWriter *writer, EbmlElement *elem, int remaining_elems)
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
#define MATROSKA_ID_TAGLANG
#define MATROSKA_ID_VIDEOCOLOR
@ AV_OPT_TYPE_INT
Underlying C type is int.
static int mkv_check_bitstream(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
#define MATROSKA_ID_VIDEOCOLORTRANSFERCHARACTERISTICS
A Quick Description Of Rate Distortion Theory We want to encode a video
#define MATROSKA_ID_VIDEOCOLOR_RX
static int end_ebml_master_crc32_tentatively(AVIOContext *pb, ebml_stored_master *elem, MatroskaMuxContext *mkv, uint32_t id)
Output EBML master.
@ MATROSKA_TRACK_TYPE_SUBTITLE
static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int stream, int64_t ts, int64_t cluster_pos, int64_t relative_pos, int64_t duration)
AVRational r_frame_rate
Real base framerate of the stream.
@ AV_PKT_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
int ff_flac_write_header(AVIOContext *pb, const uint8_t *extradata, int extradata_size, int last_block)
@ MATROSKA_VIDEO_PROJECTION_TYPE_EQUIRECTANGULAR
static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt)
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.
void avio_wb64(AVIOContext *s, uint64_t val)
#define MATROSKA_ID_VIDEOCOLORCHROMASITINGHORZ
char * av_strdup(const char *s)
Duplicate a string.
#define MATROSKA_ID_BLOCKREFERENCE
static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, AVStream *st, mkv_track *track, AVIOContext *pb, int is_default)
int bits_per_coded_sample
The number of bits per sample in the codedwords.
#define MATROSKA_ID_VIDEOCOLOR_RY
@ MATROSKA_VIDEO_FIELDORDER_TB
#define ITU_T_T35_COUNTRY_CODE_US
uint32_t bound_left
Distance from the left edge.
AVPacket * pkt
Used to hold temporary packets for the generic demuxing code.
static void ebml_writer_write_block(const EbmlElement *elem, AVIOContext *pb)
#define MATROSKA_ID_TRACKVIDEO
void avio_wb24(AVIOContext *s, unsigned int val)
const CodecTags ff_mkv_codec_tags[]
#define MATROSKA_ID_TRACKFLAGFORCED
@ MATROSKA_VIDEO_STEREOMODE_TYPE_NB
static void scale(int *out, const int *in, const int w, const int h, const int shift)
#define EBML_ID_EBMLREADVERSION
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
#define ITU_T_T35_PROVIDER_CODE_SMTPE
unsigned MaxFALL
Max average light level per frame (cd/m^2).
This structure stores compressed data.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
static int mkv_write_chapters(AVFormatContext *s)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define MATROSKA_ID_ATTACHEDFILE
#define MATROSKA_ID_CODECDELAY
static int mkv_write_seekhead(AVIOContext *pb, MatroskaMuxContext *mkv, int error_on_seek_failure, int64_t destpos)
Write the SeekHead to the file at the location reserved for it and seek to destpos afterwards.
#define MAX_CUETRACKPOS_SIZE
4 * (1-byte EBML ID, 1-byte EBML size, 8-byte uint max)
void avio_wb16(AVIOContext *s, unsigned int val)
#define MATROSKA_ID_TAGTARGETS_TRACKUID
static void mkv_handle_rotation(void *logctx, const AVCodecParameters *par, double *yaw, double *roll)
The exact code depends on how similar the blocks are and how related they are to the block
#define MATROSKA_ID_CHAPTERTIMEEND
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
@ EBML_BLOCK
pseudo-type for writing (Simple)Blocks
#define MATROSKA_ID_TRACKS
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
#define MATROSKA_ID_SEEKPREROLL
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
#define MATROSKA_ID_SEEKHEAD
static int mkv_write_simpletag(AVIOContext *pb, const AVDictionaryEntry *t)
@ MATROSKA_BLOCK_ADD_ID_TYPE_DVCC
int ff_nal_units_create_list(NALUList *list, const uint8_t *buf, int size)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
int initial_padding
Audio only.
#define MATROSKA_ID_VIDEOPROJECTIONPOSEROLL
#define MATROSKA_ID_BLOCKADDID
static void put_ebml_uid(AVIOContext *pb, uint32_t elementid, uint64_t uid)
Write a (random) UID with fixed size to make the output more deterministic.
static void mkv_write_blockadditionmapping(AVFormatContext *s, const MatroskaMuxContext *mkv, const AVCodecParameters *par, AVIOContext *pb, mkv_track *track, const AVStream *st)
This structure describes how to handle spherical videos, outlining information about projection,...
int64_t lowest_ts_allowed
This is the lowest ts allowed in this track; it may be set by the muxer during init or write_header a...
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
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
int32_t yaw
Rotation around the up vector [-180, 180].
#define MATROSKA_ID_TAGTARGETS_CHAPTERUID
@ MATROSKA_VIDEO_PROJECTION_TYPE_CUBEMAP
static int mkv_write_info(AVFormatContext *s)
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
#define MATROSKA_ID_BLOCKADDITIONS
@ AVIO_DATA_MARKER_FLUSH_POINT
A point in the output bytestream where the underlying AVIOContext might flush the buffer depending on...
int avoid_negative_ts_use_pts