59 #define MAX_SEEKHEAD_ENTRIES 7 61 #define IS_SEEKABLE(pb, mkv) (((pb)->seekable & AVIO_SEEKABLE_NORMAL) && \ 120 #define MODE_MATROSKAv2 0x01 121 #define MODE_WEBM 0x02 160 uint32_t segment_uid[4];
165 #define MAX_EBML_HEADER_SIZE 35 169 #define MAX_SEEKENTRY_SIZE 21 172 #define MAX_CUETRACKPOS_SIZE 40 175 #define OPUS_SEEK_PREROLL 80000000 229 num |= 1ULL << bytes * 7;
230 for (
int i = bytes - 1;
i >= 0;
i--)
248 bytes = needed_bytes;
274 for (i = bytes - 1; i >= 0; i--)
281 uint64_t
tmp = 2*(val < 0 ? val^-1 :
val);
288 for (i = bytes - 1; i >= 0; i--)
300 const void *buf,
int size)
338 uint64_t expectedsize)
383 int length_size,
int keep_buffer,
390 if ((ret = (*dyn_cp)->error) < 0)
491 int error_on_seek_failure, int64_t destpos)
495 int64_t remaining, ret64;
499 return error_on_seek_failure ? ret64 : 0;
525 if ((ret64 =
avio_seek(pb, destpos, SEEK_SET)) < 0)
532 int64_t cluster_pos, int64_t relative_pos, int64_t
duration)
566 uint64_t
pts = entry->pts;
574 for (
int j = 0; j < num_tracks; j++)
575 tracks[j].has_cue = 0;
578 int idx = entry->stream_idx;
588 if (entry->duration > 0)
591 }
while (++entry < end && entry->pts == pts);
593 if ((ret = cuepoint->
error) < 0)
606 const uint8_t *header_start[3];
608 int first_header_size;
612 first_header_size = 30;
614 first_header_size = 42;
617 first_header_size, header_start, header_len);
624 for (j = 0; j < 2; j++) {
627 for (j = 0; j < 3; j++)
628 avio_write(pb, header_start[j], header_len[j]);
662 av_dict_set(&dict,
"WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0);
679 const uint8_t *extradata,
int extradata_size,
691 if (ret < 0 && (extradata_size || !
IS_SEEKABLE(s->
pb, mkv))) {
693 "Error parsing AAC extradata, unable to determine samplerate.\n");
739 "Invalid extradata found, ALAC expects a 36-byte " 765 int native_id,
int qt_id)
770 int ret, codecpriv_size;
789 for(i = 0; i < 0x5a - 8; i++)
825 if ((ret = dyn_cp->
error) >= 0 && codecpriv_size)
839 uint8_t colour[(2 + 1 + 8) * 18 + (2 + 1) + 1];
842 const void *side_data;
941 4 * (2 + 1 + 8) + (2 + 1 + 20));
974 (
double) spherical->
yaw / (1 << 16));
975 if (spherical->
pitch)
977 (
double) spherical->
pitch / (1 << 16));
980 (
double) spherical->
roll / (1 << 16));
988 switch (field_order) {
1002 switch (field_order) {
1036 int stereo_mode = atoi(tag->
value);
1044 if (stereo_mode < MATROSKA_VIDEO_STEREOMODE_TYPE_NB &&
1045 stereo_mode != 10 && stereo_mode != 12) {
1055 switch (stereo->
type) {
1105 "The specified stereo mode is not valid.\n");
1125 int output_sample_rate = 0;
1126 int display_width_div = 1;
1127 int display_height_div = 1;
1136 &sample_rate, &output_sample_rate);
1172 codec_id =
"D_WEBVTT/CAPTIONS";
1175 codec_id =
"D_WEBVTT/DESCRIPTIONS";
1178 codec_id =
"D_WEBVTT/METADATA";
1181 codec_id =
"D_WEBVTT/SUBTITLES";
1188 "Only VP8 or VP9 or AV1 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM.\n");
1220 av_log(s,
AV_LOG_ERROR,
"Raw RGB is not supported Natively in Matroska, you can use AVI or NUT or\n" 1221 "If you would like to store it anyway using VFW mode, enable allow_raw_vfw (-allow_raw_vfw 1)\n");
1249 else if (!native_id) {
1267 &display_height_div);
1281 if (d_width > INT_MAX) {
1285 if (d_width != par->
width || display_width_div != 1 || display_height_div != 1) {
1286 if (mkv->
mode ==
MODE_WEBM || display_width_div != 1 || display_height_div != 1) {
1300 }
else if (display_width_div != 1 || display_height_div != 1) {
1321 if (codecdelay < 0) {
1345 if (output_sample_rate)
1376 av_log(s,
AV_LOG_ERROR,
"Only audio, video, and subtitles are supported for Matroska.\n");
1396 int i,
ret, video_default_idx, audio_default_idx, subtitle_default_idx;
1406 int video_idx, audio_idx, subtitle_idx;
1408 video_idx = video_default_idx =
1409 audio_idx = audio_default_idx =
1410 subtitle_idx = subtitle_default_idx = -1;
1416 #define CASE(type, variable) \ 1417 case AVMEDIA_TYPE_ ## type: \ 1418 variable ## _idx = i; \ 1419 if (st->disposition & AV_DISPOSITION_DEFAULT) \ 1420 variable ## _default_idx = i; \ 1424 CASE(SUBTITLE, subtitle)
1429 video_default_idx =
FFMAX(video_default_idx, video_idx);
1430 audio_default_idx =
FFMAX(audio_default_idx, audio_idx);
1432 subtitle_default_idx =
FFMAX(subtitle_default_idx, subtitle_idx);
1438 i == video_default_idx || i == audio_default_idx ||
1439 i == subtitle_default_idx;
1460 if ((p = strrchr(p,
'-')) &&
1468 else if (*p >=
'a' && *p <=
'z')
1520 uint32_t elementid, uint64_t
uid)
1633 for (
unsigned j = 0; j <
i; j++)
1646 int ret, create_new_ids;
1672 #if FF_API_CHAPTER_ID_INT 1673 uint64_t
uid = create_new_ids ?
i + 1ULL : (uint32_t)c->
id;
1675 uint64_t uid = create_new_ids ?
i + 1ULL : c->
id;
1677 if (chapterstart < 0 || chapterstart > chapterend || chapterend < 0) {
1679 "Invalid chapter start (%"PRId64
") or end (%"PRId64
").\n",
1680 chapterstart, chapterend);
1736 return "text/plain";
1760 const char *mimetype;
1795 av_log(s,
AV_LOG_DEBUG,
"get_metadata_duration found duration in context metadata: %" PRId64
"\n", us);
1804 max =
FFMAX(max, us);
1818 int64_t creation_time;
1868 const char *ident =
"Lavf";
1875 int64_t date_utc = (creation_time - 978307200000000LL) * 1000;
1877 AV_WB64(date_utc_buf, date_utc);
1890 av_log(s,
AV_LOG_DEBUG,
"Write early duration from recording time = %" PRIu64
"\n", scaledDuration);
1891 }
else if (metadata_duration > 0) {
1894 av_log(s,
AV_LOG_DEBUG,
"Write early duration from metadata = %" PRIu64
"\n", scaledDuration);
1968 int size = pkt_size + track_num_size + 3;
2013 memcpy(dst + offset, src, header.
blocksize);
2029 uint32_t blockid,
const AVPacket *
pkt,
int keyframe)
2038 uint64_t additional_id;
2039 int64_t discard_padding = 0;
2040 unsigned track_number = track->
track_num;
2041 ebml_master block_group, block_additions, block_more;
2048 "Writing block of size %d with pts %" PRId64
", dts %" PRId64
", " 2049 "duration %" PRId64
" at relative offset %" PRId64
" in cluster " 2050 "at offset %" PRId64
". TrackNumber %u, keyframe %d\n",
2084 if (side_data && side_data_size >= 10) {
2095 if (side_data_size < 8 || (additional_id =
AV_RB64(side_data)) != 1) {
2099 side_data_size -= 8;
2103 if (side_data_size || discard_padding) {
2114 if (data != pkt->
data)
2121 if (discard_padding)
2124 if (side_data_size) {
2131 side_data, side_data_size);
2135 if (side_data_size || discard_padding)
2147 int size, id_size_int, settings_size_int;
2148 const char *
id, *settings;
2150 const int flags = 0;
2158 settings = settings ? settings :
"";
2160 if (id_size > INT_MAX - 2 || settings_size > INT_MAX - id_size - 2 ||
2161 pkt->
size > INT_MAX - settings_size - id_size - 2)
2164 size = id_size + 1 + settings_size + 1 + pkt->
size;
2169 "Writing block of size %d with pts %" PRId64
", dts %" PRId64
", " 2170 "duration %" PRId64
" at relative offset %" PRId64
" in cluster " 2171 "at offset %" PRId64
". TrackNumber %u, keyframe %d\n",
2184 id_size_int = id_size;
2185 settings_size_int = settings_size;
2186 avio_printf(pb,
"%.*s\n%.*s\n%.*s", id_size_int,
id, settings_size_int, settings, pkt->
size, pkt->
data);
2227 if (side_data_size && mkv->
track.
bc) {
2228 int filler, output_sample_rate = 0;
2233 if (!output_sample_rate)
2238 memcpy(par->
extradata, side_data, side_data_size);
2249 av_log(s,
AV_LOG_ERROR,
"Error parsing AAC extradata, unable to determine samplerate.\n");
2254 if (side_data_size && mkv->
track.
bc) {
2279 if ((ret = dyn_cp->
error) < 0 ||
2291 memcpy(par->
extradata, side_data, side_data_size);
2314 int64_t relative_packet_pos;
2324 if ((int16_t)cluster_time != cluster_time) {
2340 "Starting new cluster with timestamp " 2341 "%" PRId64
" at offset %" PRId64
" bytes\n",
2373 #if FF_API_CONVERGENCE_DURATION 2376 if (pkt->convergence_duration > 0) {
2377 duration = pkt->convergence_duration;
2407 int64_t cluster_time;
2409 int start_new_cluster;
2428 start_new_cluster = keyframe;
2432 start_new_cluster = 1;
2437 cluster_size > 4 * 1024))) {
2438 start_new_cluster = 1;
2440 start_new_cluster = 0;
2442 if (start_new_cluster) {
2460 "Could not write cached audio packet ret:%d\n", ret);
2485 "Flushing cluster at offset %" PRIu64
" bytes\n",
2497 int64_t endpos, ret64;
2505 "Could not write cached audio packet ret:%d\n", ret);
2529 int length_size = 0;
2545 size += 4 + length_size;
2548 "Insufficient space reserved for Cues: " 2549 "%d < %"PRIu64
". No Cues will be output.\n",
2622 char duration_string[20] =
"";
2629 snprintf(duration_string, 20,
"%02d:%02d:%012.9f",
2630 (
int) duration_sec / 3600, ((
int) duration_sec / 60) % 60,
2631 fmod(duration_sec, 60));
2685 for (k = 0; k <
i; k++) {
2686 if (tracks[k].uid == uid)
2698 unsigned nb_tracks = 0;
2709 "The Matroska muxer does not yet support muxing %s\n",
2737 for (i = 0; i < 4; i++)
2757 "as WebM doesn't support attachments.\n", i);
2760 "tag and it cannot be deduced from the codec id.\n", i);
2772 if (mkv->
is_dash && nb_tracks != 1)
2823 #define OFFSET(x) offsetof(MatroskaMuxContext, x) 2824 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM 2826 {
"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 },
2827 {
"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 },
2828 {
"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 },
2829 {
"dash",
"Create a WebM file conforming to WebM DASH specification",
OFFSET(is_dash),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
2830 {
"dash_track_number",
"Track number for the DASH stream",
OFFSET(dash_track_number),
AV_OPT_TYPE_INT, { .i64 = 1 }, 1, INT_MAX, FLAGS },
2831 {
"live",
"Write files assuming it is a live stream.",
OFFSET(is_live),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
2832 {
"allow_raw_vfw",
"allow RAW VFW mode",
OFFSET(allow_raw_vfw),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
2833 {
"flipped_raw_rgb",
"Raw RGB bitmaps in VFW mode are stored bottom-up",
OFFSET(flipped_raw_rgb),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
2834 {
"write_crc32",
"write a CRC32 element inside every Level 1 element",
OFFSET(write_crc),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
2836 {
"infer",
"For each track type, mark the first 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,
"default_mode" },
2837 {
"infer_no_subs",
"For each track type, mark the first 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,
"default_mode" },
2842 #if CONFIG_MATROSKA_MUXER 2843 static const AVClass matroska_class = {
2853 .mime_type =
"video/x-matroska",
2854 .extensions =
"mkv",
2856 .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
2858 .video_codec = CONFIG_LIBX264_ENCODER ?
2874 .priv_class = &matroska_class,
2878 #if CONFIG_WEBM_MUXER 2879 static const AVClass webm_class = {
2889 .mime_type =
"video/webm",
2890 .extensions =
"webm",
2904 .priv_class = &webm_class,
2908 #if CONFIG_MATROSKA_AUDIO_MUXER 2909 static const AVClass mka_class = {
2918 .mime_type =
"audio/x-matroska",
2919 .extensions =
"mka",
2921 .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
2935 .priv_class = &mka_class,
unsigned int nb_chapters
Number of chapters in AVChapter array.
int32_t pitch
Rotation around the right vector [-90, 90].
Context structure for the Lagged Fibonacci PRNG.
#define MATROSKA_ID_SEEKPREROLL
#define AV_STEREO3D_FLAG_INVERT
Inverted views, Right/Bottom represents the left view.
#define MATROSKA_ID_VIDEOPROJECTIONPOSEYAW
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
enum AVChromaLocation chroma_location
void avio_wb64(AVIOContext *s, uint64_t val)
#define MATROSKA_ID_BLOCKADDID
#define MATROSKA_ID_TRACKDEFAULTDURATION
enum AVFieldOrder field_order
Video only.
void avio_wl16(AVIOContext *s, unsigned int val)
static void put_ebml_size_unknown(AVIOContext *pb, int bytes)
Write an EBML size meaning "unknown size".
enum AVColorTransferCharacteristic color_trc
#define MATROSKA_ID_VIDEOFLAGINTERLACED
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define MATROSKA_ID_VIDEOCOLOR_GX
static int start_ebml_master_crc32(AVIOContext **dyn_cp, MatroskaMuxContext *mkv)
#define MATROSKA_ID_DATEUTC
int sizebytes
how many bytes were reserved for the size
The optional first identifier line of a WebVTT cue.
#define MATROSKA_ID_TRACKFLAGLACING
unsigned MaxCLL
Max content light level (cd/m^2).
#define MATROSKA_ID_TRACKENTRY
static int mkv_write_packet(AVFormatContext *s, const AVPacket *pkt)
#define MATROSKA_ID_VIDEODISPLAYHEIGHT
int64_t cluster_pos
offset of the cluster containing the block relative to the segment
ptrdiff_t const GLvoid * data
int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int flags)
Write WAVEFORMAT header structure.
static int mkv_init(struct AVFormatContext *s)
#define MAX_SEEKHEAD_ENTRIES
static int mkv_write_packet_internal(AVFormatContext *s, const AVPacket *pkt)
#define MATROSKA_ID_VIDEOPROJECTIONPOSEROLL
#define MATROSKA_ID_CUETRACKPOSITION
#define MATROSKA_ID_CODECPRIVATE
#define MATROSKA_ID_TRACKFLAGVISUALIMPAIRED
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
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 int mkv_new_chapter_ids_needed(const AVFormatContext *s)
static av_cold int init(AVCodecContext *avctx)
#define MATROSKA_ID_AUDIOBITDEPTH
#define CASE(type, variable)
#define MATROSKA_ID_TRACKFLAGDEFAULT
static const AVCodecTag additional_subtitle_tags[]
This side data should be associated with a video stream and contains Stereoscopic 3D information in f...
static int mkv_write_attachments(AVFormatContext *s)
Video represents a portion of a sphere mapped on a flat surface using equirectangular projection...
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
#define MATROSKA_ID_TAGTARGETS_ATTACHUID
int ff_hevc_annexb2mp4_buf(const uint8_t *buf_in, uint8_t **buf_out, int *size, int filter_ps, int *ps_count)
Writes Annex B formatted HEVC NAL units to a data buffer.
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
#define MATROSKA_ID_FILEDATA
const char * av_default_item_name(void *ptr)
Return the context name.
AVFormatInternal * internal
An opaque field for libavformat internal usage.
#define EBML_ID_DOCTYPEREADVERSION
#define us(width, name, range_min, range_max, subs,...)
#define MATROSKA_ID_BLOCKREFERENCE
static int mkv_write_header(AVFormatContext *s)
#define MATROSKA_ID_TRACKTYPE
enum AVMediaType codec_type
#define MATROSKA_ID_TAGTARGETS_CHAPTERUID
int ff_flac_is_native_layout(uint64_t channel_layout)
int64_t duration
duration of the block according to time base
static av_always_inline uint64_t av_double2int(double f)
Reinterpret a double as a 64-bit integer.
#define MATROSKA_ID_VIDEOCOLOR_RX
Video represents a sphere mapped on a flat surface using equirectangular projection.
static int mkv_write_tag(MatroskaMuxContext *mkv, const AVDictionary *m, AVIOContext **pb, ebml_master *tag, uint32_t elementid, uint64_t uid)
#define MATROSKA_ID_MUXINGAPP
int64_t cluster_time_limit
#define MATROSKA_ID_AUDIOCHANNELS
#define MATROSKA_ID_VIDEOPROJECTIONTYPE
Views are next to each other.
static void put_ebml_length(AVIOContext *pb, uint64_t length, int bytes)
Write a length as EBML variable length integer.
#define MATROSKA_ID_CUECLUSTERPOSITION
#define MATROSKA_ID_VIDEOCOLOR_LUMINANCEMAX
#define MAX_EBML_HEADER_SIZE
2 bytes * 7 for EBML IDs, 7 1-byte EBML lengths, 6 1-byte uint, 8 byte for "matroska" doctype string ...
int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
Converts AVChromaLocation to swscale x/y chroma position.
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_VIDEOCOLORCHROMASITINGHORZ
#define MATROSKA_ID_EDITIONFLAGDEFAULT
#define MATROSKA_ID_CLUSTERTIMECODE
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
This struct describes the properties of an encoded stream.
#define MATROSKA_ID_CHAPTERTIMEEND
enum AVColorSpace color_space
int64_t pos
absolute offset in the containing AVIOContext where the master's elements start
MatroskaVideoStereoModeType
Mastering display metadata (based on SMPTE-2086:2014).
#define MATROSKA_ID_FILEDESC
const AVCodecTag ff_codec_movvideo_tags[]
static int query_codec(enum AVCodecID id, int std_compliance)
int64_t cluster_pos
file offset of the current Cluster
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static const AVCodecTag additional_audio_tags[]
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void avio_wl32(AVIOContext *s, unsigned int val)
#define MATROSKA_ID_VIDEOCOLOR_BX
#define MATROSKA_ID_CHAPLANG
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. ...
#define MATROSKA_ID_TRACKLANGUAGE
A point in the output bytestream where the underlying AVIOContext might flush the buffer depending on...
Stereo 3D type: this structure describes how two videos are packed within a single video surface...
#define OPUS_SEEK_PREROLL
Seek preroll value for opus.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
int ff_mkv_stereo3d_conv(AVStream *st, MatroskaVideoStereoModeType stereo_mode)
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
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
#define MATROSKA_ID_TIMECODESCALE
static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int native_id, int qt_id)
#define MATROSKA_ID_SIMPLEBLOCK
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, const AVCodecParameters *par)
#define MATROSKA_ID_BLOCKMORE
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
AVStream ** streams
A list of all streams in the file.
#define MATROSKA_ID_CUERELATIVEPOSITION
A point in the output bytestream where a demuxer can start parsing (for non self synchronizing bytest...
#define MATROSKA_ID_AUDIOOUTSAMPLINGFREQ
#define MATROSKA_ID_VIDEOCOLOR
Public header for CRC hash function implementation.
int initial_padding
Audio only.
static int webm_query_codec(enum AVCodecID codec_id, int std_compliance)
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int flags
Flags modifying the (de)muxer behaviour.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
#define MATROSKA_ID_VIDEODISPLAYWIDTH
int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size)
Writes AV1 extradata (Sequence Header and Metadata OBUs) to the provided AVIOContext.
#define MATROSKA_ID_TRACKFLAGORIGINAL
#define MATROSKA_ID_BLOCKADDITIONS
static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int stream, int64_t ts, int64_t cluster_pos, int64_t relative_pos, int64_t duration)
static EbmlSyntax ebml_header[]
static int mkv_check_tag(const AVDictionary *m, uint32_t elementid)
Video is not stereoscopic (and metadata has to be there).
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static const uint8_t header[24]
#define MATROSKA_ID_TRACKNUMBER
#define MATROSKA_ID_VIDEOCOLOR_WHITEY
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
uint8_t * av_stream_get_side_data(const AVStream *stream, enum AVPacketSideDataType type, size_t *size)
Get side information from stream.
static uint64_t mkv_get_uid(const mkv_track *tracks, int i, AVLFG *c)
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
#define MATROSKA_ID_SEGMENTUID
static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, AVStream *st, mkv_track *track, AVIOContext *pb, int is_default)
uint64_t channel_layout
Audio only.
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_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static void mkv_add_seekhead_entry(MatroskaMuxContext *mkv, uint32_t elementid, uint64_t filepos)
#define MATROSKA_ID_TRACKUID
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define MATROSKA_ID_VIDEOSTEREOMODE
static void put_ebml_id(AVIOContext *pb, uint32_t id)
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
AVCodecID
Identify the syntax and semantics of the bitstream.
static int mkv_write_tags(AVFormatContext *s)
#define MATROSKA_ID_VIDEOCOLOR_BY
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void put_ebml_float(AVIOContext *pb, uint32_t elementid, double val)
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
AVDictionary * metadata
Metadata that applies to the whole file.
int flags
Additional information about the frame packing.
#define MATROSKA_ID_BLOCKDURATION
#define EBML_ID_EBMLREADVERSION
#define MATROSKA_ID_VIDEOCOLORMAXCLL
#define MAX_CUETRACKPOS_SIZE
4 * (1-byte EBML ID, 1-byte EBML size, 8-byte uint max)
#define MATROSKA_ID_VIDEOCOLOR_WHITEX
#define MATROSKA_ID_CLUSTER
const char * ff_convert_lang_to(const char *lang, enum AVLangCodespace target_codespace)
Convert a language code to a target codespace.
#define MATROSKA_ID_VIDEOCOLORCHROMASITINGVERT
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int ff_av1_filter_obus_buf(const uint8_t *in, uint8_t **out, int *size, int *offset)
Filter out AV1 OBUs not meant to be present in ISOBMFF sample data and return the result in a data bu...
Views are packed per line, as if interlaced.
enum AVColorPrimaries color_primaries
void ffio_reset_dyn_buf(AVIOContext *s)
Reset a dynamic buffer.
#define MATROSKA_ID_FILEMIMETYPE
#define MATROSKA_ID_WRITINGAPP
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int ff_isom_write_hvcc(AVIOContext *pb, const uint8_t *data, int size, int ps_array_completeness)
Writes HEVC extradata (parameter sets, declarative SEI NAL units) to the provided AVIOContext...
const char *const ff_matroska_video_stereo_mode[MATROSKA_VIDEO_STEREOMODE_TYPE_NB]
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
static void put_ebml_void(AVIOContext *pb, int size)
Write a void element of a given size.
enum AVMediaType codec_type
General type of the encoded data.
static int ebml_num_size(uint64_t num)
Returns how many bytes are needed to represent a number as EBML variable length integer.
int64_t id
unique ID to identify the chapter
static int mkv_write_chapters(AVFormatContext *s)
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t *size)
#define EBML_ID_EBMLMAXIDLENGTH
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...
AVRational avg_frame_rate
Average framerate.
const AVCodecTag ff_codec_wav_tags[]
int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size)
int flags
A combination of AV_PKT_FLAG values.
int extradata_size
Size of the extradata content in bytes.
const CodecTags ff_webm_codec_tags[]
Views are alternated temporally.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
uint32_t bound_bottom
Distance from the bottom edge.
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)
static int mkv_write_simpletag(AVIOContext *pb, const AVDictionaryEntry *t)
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...
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Video frame is split into 6 faces of a cube, and arranged on a 3x2 layout.
#define MATROSKA_ID_VIDEOCOLOR_LUMINANCEMIN
audio channel layout utility functions
#define EBML_ID_EBMLVERSION
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
void ffio_fill(AVIOContext *s, int b, int count)
#define AV_TIME_BASE
Internal time base represented as integer.
#define MATROSKA_ID_TAGTARGETS
const AVCodecTag ff_codec_bmp_tags[]
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
#define MATROSKA_ID_TAGNAME
static int64_t get_metadata_duration(AVFormatContext *s)
static int write_trailer(AVFormatContext *s1)
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
void avio_wb24(AVIOContext *s, unsigned int val)
This side data should be associated with a video stream and corresponds to the AVSphericalMapping str...
uint32_t bound_right
Distance from the right edge.
int ff_wv_parse_header(WvHeader *wv, const uint8_t *data)
Parse a WavPack block header.
#define MATROSKA_ID_SIMPLETAG
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
static int end_ebml_master_crc32_tentatively(AVIOContext *pb, ebml_stored_master *elem, MatroskaMuxContext *mkv, uint32_t id)
Output EBML master.
int avoid_negative_ts
Avoid negative timestamps during muxing.
#define MATROSKA_ID_CHAPTERATOM
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. ...
static int mkv_write_native_codecprivate(AVFormatContext *s, AVIOContext *pb, const AVCodecParameters *par, AVIOContext *dyn_cp)
int32_t yaw
Rotation around the up vector [-180, 180].
static int get_aac_sample_rates(AVFormatContext *s, MatroskaMuxContext *mkv, const uint8_t *extradata, int extradata_size, int *sample_rate, int *output_sample_rate)
enum AVColorRange color_range
Video only.
static int mkv_check_new_extra_data(AVFormatContext *s, const AVPacket *pkt)
Opaque data information usually sparse.
#define MATROSKA_ID_VIDEOCOLORSPACE
#define MATROSKA_ID_CHAPTERS
#define MATROSKA_ID_TRACKFLAGHEARINGIMPAIRED
#define MATROSKA_ID_TRACKFLAGTEXTDESCRIPTIONS
#define MATROSKA_ID_AUDIOSAMPLINGFREQ
ff_const59 struct AVOutputFormat * oformat
The output container format.
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
uint32_t padding
Number of pixels to pad from the edge of each cube face.
int metadata_header_padding
Number of bytes to be written as padding in a metadata header.
#define IS_SEEKABLE(pb, mkv)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int64_t end
chapter start/end time in time_base units
Content light level (based on CTA-861.3).
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
enum AVStereo3DType type
How views are packed within the video.
Views are packed in a checkerboard-like structure per pixel.
#define MATROSKA_ID_VIDEOCOLORMATRIXCOEFF
char * av_strdup(const char *s)
Duplicate a string.
#define MATROSKA_ID_TRACKFLAGFORCED
Views are on top of each other.
#define MATROSKA_ID_VIDEOCOLORPRIMARIES
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
int64_t sample_rate_offset
#define MATROSKA_ID_VIDEOPROJECTIONPOSEPITCH
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
#define MATROSKA_ID_SEEKID
AVIOContext * pb
I/O context.
static void put_ebml_uint(AVIOContext *pb, uint32_t elementid, uint64_t val)
void avio_w8(AVIOContext *s, int b)
#define MATROSKA_ID_BLOCK
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define MATROSKA_ID_TAGTARGETS_TRACKUID
#define MATROSKA_ID_TAGLANG
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
#define MATROSKA_ID_TRACKS
Data found in BlockAdditional element of matroska container.
#define MATROSKA_ID_TRACKNAME
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
static void mkv_write_video_color(AVIOContext *pb, const AVStream *st, const AVCodecParameters *par)
#define MATROSKA_ID_SEEKENTRY
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.
Describe the class of an AVClass context structure.
#define MATROSKA_ID_EDITIONENTRY
#define FF_COMPLIANCE_NORMAL
static int mkv_check_tag_name(const char *name, uint32_t elementid)
#define MATROSKA_ID_BLOCKGROUP
#define MATROSKA_ID_VIDEOPIXELHEIGHT
int32_t roll
Rotation around the forward vector [-180, 180].
static int mkv_write_tracks(AVFormatContext *s)
Rational number (pair of numerator and denominator).
#define MATROSKA_ID_CUEDURATION
#define MATROSKA_ID_CUETIME
Recommmends skipping the specified number of samples.
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
#define MATROSKA_ID_VIDEOCOLORTRANSFERCHARACTERISTICS
#define MATROSKA_ID_TITLE
#define MATROSKA_ID_TRACKVIDEO
static int mkv_strip_wavpack(const uint8_t *src, uint8_t **pdst, int *size)
This structure describes how to handle spherical videos, outlining information about projection...
int error
contains the error code or 0 if no error happened
#define MATROSKA_ID_VIDEOPROJECTION
#define MATROSKA_ID_VIDEOCOLORMASTERINGMETA
#define MATROSKA_ID_VIDEOPROJECTIONPRIVATE
This struct describes the properties of a single codec described by an AVCodecID. ...
#define MATROSKA_ID_ATTACHMENTS
void avio_wb16(AVIOContext *s, unsigned int val)
#define flags(name, subs,...)
#define MATROSKA_ID_CHAPTERDISPLAY
static int mkv_end_cluster(AVFormatContext *s)
int bits_per_raw_sample
This is the number of valid bits in each output sample.
#define MATROSKA_ID_FILENAME
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
#define MATROSKA_ID_BLOCKADDITIONAL
uint32_t bound_top
Distance from the top edge.
const AVMetadataConv ff_mkv_metadata_conv[]
#define MATROSKA_ID_CODECID
static const AVCodecTag additional_video_tags[]
mkv_seekhead_entry entries[MAX_SEEKHEAD_ENTRIES]
#define MATROSKA_ID_VIDEOFIELDORDER
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
int sample_rate
Audio only.
int ff_flac_write_header(AVIOContext *pb, const uint8_t *extradata, int extradata_size, int last_block)
#define MATROSKA_ID_VIDEOALPHAMODE
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static int mkv_write_trailer(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_RB64
static int put_flac_codecpriv(AVFormatContext *s, AVIOContext *pb, const AVCodecParameters *par)
static int mkv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
#define MATROSKA_ID_CUETRACK
static int put_wv_codecpriv(AVIOContext *pb, const AVCodecParameters *par)
#define MATROSKA_ID_SEEKPOSITION
#define MATROSKA_ID_CODECDELAY
#define FF_DISABLE_DEPRECATION_WARNINGS
#define MATROSKA_ID_CHAPTERTIMESTART
#define MATROSKA_ID_VIDEOCOLORRANGE
enum AVSphericalProjection projection
Projection type.
Utilties for rational number calculation.
int ffio_init_context(AVIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
static int mkv_write_tag_targets(MatroskaMuxContext *mkv, AVIOContext **pb, ebml_master *tag, uint32_t elementid, uint64_t uid)
static int mkv_write_flush_packet(AVFormatContext *s, AVPacket *pkt)
int disposition
AV_DISPOSITION_* bit field.
static ebml_master start_ebml_master(AVIOContext *pb, uint32_t elementid, uint64_t expectedsize)
void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par, int for_asf, int ignore_extradata, int rgb_frame_is_flipped)
Views are packed per column.
AVRational time_base
time base in which the start/end timestamps are specified
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
static int mkv_write_vtt_blocks(AVFormatContext *s, AVIOContext *pb, const AVPacket *pkt)
#define MATROSKA_ID_SEGMENT
#define MAX_PCE_SIZE
Maximum size of a PCE including the 3-bit ID_PCE.
static void mkv_write_video_projection(AVFormatContext *s, AVIOContext *pb, const AVStream *st)
The optional settings (rendering instructions) that immediately follow the timestamp specifier of a W...
#define MATROSKA_ID_SEEKHEAD
A point in the output bytestream where a decoder can start decoding (i.e.
A Quick Description Of Rate Distortion Theory We want to encode a video
#define MATROSKA_ID_TRACKFLAGCOMMENTARY
#define FF_ENABLE_DEPRECATION_WARNINGS
#define MATROSKA_ID_POINTENTRY
static int mkv_write_stereo_mode(AVFormatContext *s, AVIOContext *pb, AVStream *st, int mode, int *h_width, int *h_height)
#define MATROSKA_ID_FILEUID
static void put_ebml_binary(AVIOContext *pb, uint32_t elementid, const void *buf, int size)
static void mkv_start_seekhead(MatroskaMuxContext *mkv, AVIOContext *pb)
Initialize the SeekHead element to be ready to index level 1 Matroska elements.
void * priv_data
Format private data.
#define MATROSKA_ID_CHAPTERUID
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
static int check_bitstream(AVFormatContext *s, AVStream *st, AVPacket *pkt)
static void write_header(FFV1Context *f)
uint32_t bound_left
Distance from the left edge.
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
static const char * get_mimetype(const AVStream *st)
int bits_per_coded_sample
The number of bits per sample in the codedwords.
int64_t relative_pos
relative offset from the position of the cluster containing the block
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
#define MATROSKA_ID_VIDEOCOLORMAXFALL
#define MATROSKA_ID_VIDEODISPLAYUNIT
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static const AVOption options[]
#define EBML_ID_EBMLMAXSIZELENGTH
void avio_wb32(AVIOContext *s, unsigned int val)
enum AVMediaType avcodec_get_type(enum AVCodecID codec_id)
Get the type of the given codec.
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
#define MATROSKA_ID_CHAPSTRING
#define MATROSKA_ID_TAGSTRING
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
static void put_ebml_string(AVIOContext *pb, uint32_t elementid, const char *str)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
static void put_ebml_sint(AVIOContext *pb, uint32_t elementid, int64_t val)
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
#define MATROSKA_ID_DURATION
#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...
static void mkv_deinit(AVFormatContext *s)
Free the members allocated in the mux context.
#define EBML_ID_DOCTYPEVERSION
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
static void end_ebml_master(AVIOContext *pb, ebml_master master)
const char *const * mime_types
MIME type(s) associated with the codec.
AVRational r_frame_rate
Real base framerate of the stream.
#define MATROSKA_ID_ATTACHEDFILE
#define MATROSKA_ID_VIDEOCOLOR_GY
static int mkv_write_block(AVFormatContext *s, AVIOContext *pb, uint32_t blockid, const AVPacket *pkt, int keyframe)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
static double val(void *priv, double ch)
unsigned MaxFALL
Max average light level per frame (cd/m^2).
This structure stores compressed data.
static void mkv_write_field_order(AVIOContext *pb, int mode, enum AVFieldOrder field_order)
mode
Use these values in ebur128_init (or'ed).
#define MATROSKA_ID_VIDEOCOLOR_RY
static int mkv_query_codec(enum AVCodecID codec_id, int std_compliance)
static void put_xiph_size(AVIOContext *pb, int size)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define MATROSKA_ID_VIDEOPIXELWIDTH
static int mkv_blockgroup_size(int pkt_size, int track_num_size)
static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp, mkv_cues *cues, mkv_track *tracks, int num_tracks)
int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
#define MATROSKA_ID_TRACKAUDIO
#define AV_NOPTS_VALUE
Undefined timestamp value.
int(* filler)(InterplayACMContext *s, unsigned ind, unsigned col)
const CodecTags ff_mkv_codec_tags[]
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
static int ebml_id_size(uint32_t id)
#define MATROSKA_ID_DISCARDPADDING
#define FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX
Tell ff_put_wav_header() to use WAVEFORMATEX even for PCM codecs.
void * av_mallocz_array(size_t nmemb, size_t size)
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.