82 #define MODE_MATROSKAv2 0x01
83 #define MODE_WEBM 0x02
111 #define MAX_SEEKENTRY_SIZE 21
115 #define MAX_CUETRACKPOS_SIZE 22
118 #define MAX_CUEPOINT_SIZE(num_tracks) 12 + MAX_CUETRACKPOS_SIZE*num_tracks
152 while ((num+1) >> bytes*7) bytes++;
171 bytes = needed_bytes;
176 num |= 1ULL << bytes*7;
177 for (i = bytes - 1; i >= 0; i--)
185 while (tmp>>=8) bytes++;
189 for (i = bytes - 1; i >= 0; i--)
258 for (i = 0; i < size / 255; i++)
277 if (new_seekhead == NULL)
282 if (numelements > 0) {
357 currentpos = seekhead->
filepos;
407 uint64_t pts = entry->
pts;
414 for (j = 0; j < num_tracks; j++)
415 tracks[j].has_cue = 0;
416 for (j = 0; j < cues->
num_entries - i && entry[j].
pts == pts; j++) {
417 int tracknum = entry[j].
tracknum - 1;
418 av_assert0(tracknum>=0 && tracknum<num_tracks);
419 if (tracks[tracknum].has_cue)
439 int first_header_size;
443 first_header_size = 30;
445 first_header_size = 42;
448 first_header_size, header_start, header_len) < 0) {
454 for (j = 0; j < 2; j++) {
457 for (j = 0; j < 3; j++)
458 avio_write(pb, header_start[j], header_len[j]);
490 int ret, codecpriv_size;
508 "Invalid extradata found, ALAC expects a 36-byte "
561 int i, j,
ret, default_stream_exists = 0;
564 if (ret < 0)
return ret;
579 int output_sample_rate = 0;
605 }
else if (tag && tag->
value) {
609 if (default_stream_exists) {
618 codec_id =
"D_WEBVTT/CAPTIONS";
621 codec_id =
"D_WEBVTT/DESCRIPTIONS";
624 codec_id =
"D_WEBVTT/METADATA";
627 codec_id =
"D_WEBVTT/SUBTITLES";
649 "Only VP8,VP9 video and Vorbis,Opus(experimental, use -strict -2) audio and WebVTT subtitles are supported for WebM.\n");
671 else if (!native_id) {
694 || st_mode >= MATROSKA_VIDEO_STEREO_MODE_COUNT) {
696 "The specified stereo mode is not valid.\n");
710 if (d_width > INT_MAX) {
735 if (output_sample_rate)
754 av_log(s,
AV_LOG_ERROR,
"Only audio, video, and subtitles are supported for Matroska.\n");
760 if (ret < 0)
return ret;
784 if (ret < 0)
return ret;
823 if ((p = strrchr(p,
'-')) &&
831 else if (*p >=
'a' && *p <=
'z')
856 if (ret < 0)
return ret;
884 if (ret < 0)
return ret;
894 if (ret < 0)
return ret;
904 if (ret < 0)
return ret;
926 if (ret < 0)
return ret;
934 const char *mimetype = NULL;
961 "it cannot be deduced from the codec id.\n", i);
1013 "The Matroska muxer does not yet support muxing %s\n",
1045 if (ret < 0)
return ret;
1052 uint32_t segment_uid[4];
1057 for (i = 0; i < 4; i++)
1069 AV_WB64(date_utc_buf, date_utc);
1080 if (ret < 0)
return ret;
1084 if (ret < 0)
return ret;
1087 if (ret < 0)
return ret;
1090 if (ret < 0)
return ret;
1097 if (mkv->
cues == NULL)
1115 int size = pkt_size + 4;
1126 int sh, sm, ss, sc, eh, em, es, ec;
1129 if (sscanf(p,
"%*[^,],%d:%d:%d%*c%d,%d:%d:%d%*c%d",
1130 &sh, &sm, &ss, &sc, &eh, &em, &es, &ec) != 8)
1132 start = 3600000LL*sh + 60000LL*sm + 1000LL*ss + 10LL*sc;
1133 end = 3600000LL*eh + 60000LL*em + 1000LL*es + 10LL*ec;
1141 int i, layer = 0, max_duration = 0,
size, line_size, data_size = pkt->
size;
1148 max_duration =
FFMAX(duration, max_duration);
1149 end = memchr(data,
'\n', data_size);
1150 size = line_size = end ? end-data+1 : data_size;
1151 size -= end ? (end[-1]==
'\r')+1 : 0;
1153 for (i=0; i<3; i++, start++)
1154 if (!(start = memchr(start,
',',
size-(start-data))))
1155 return max_duration;
1157 sscanf(data,
"Dialogue: %d,", &layer);
1158 i =
snprintf(buffer,
sizeof(buffer),
"%"PRId64
",%d,",
1161 memcpy(buffer+i, start,
size-i);
1164 "pts %" PRId64
", duration %d\n",
1177 data_size -= line_size;
1180 return max_duration;
1222 memcpy(dst + offset, src, header.
blocksize);
1242 uint8_t *data = NULL, *side_data = NULL;
1245 uint64_t additional_id = 0;
1246 ebml_master block_group, block_additions, block_more;
1249 "pts %" PRId64
", dts %" PRId64
", duration %d, flags %d\n",
1274 additional_id =
AV_RB64(side_data);
1276 side_data_size -= 8;
1279 if (side_data_size && additional_id == 1) {
1290 if (data != pkt->
data)
1293 if (side_data_size && additional_id == 1) {
1308 int i, duration = 0;
1311 int s_hour, s_min, s_sec, s_hsec, e_hour, e_min, e_sec, e_hsec;
1312 if (sscanf(*buf,
"%d:%2d:%2d%*1[,.]%3d --> %d:%2d:%2d%*1[,.]%3d",
1313 &s_hour, &s_min, &s_sec, &s_hsec,
1314 &e_hour, &e_min, &e_sec, &e_hsec) == 8) {
1315 s_min += 60*s_hour; e_min += 60*e_hour;
1316 s_sec += 60*s_min; e_sec += 60*e_min;
1317 s_hsec += 1000*s_sec; e_hsec += 1000*e_sec;
1318 duration = e_hsec - s_hsec;
1320 *buf += strcspn(*buf,
"\n") + 1;
1345 int id_size, settings_size,
size;
1348 const int flags = 0;
1358 size = id_size + 1 + settings_size + 1 + pkt->
size;
1361 "pts %" PRId64
", dts %" PRId64
", duration %d, flags %d\n",
1371 avio_printf(pb,
"%.*s\n%.*s\n%.*s", id_size,
id, settings_size, settings, pkt->
size, pkt->
data);
1430 duration = mkv_write_ass_blocks(s, pb, pkt);
1449 if (ret < 0)
return ret;
1469 || cluster_size > 5*1024*1024 || ts > mkv->
cluster_pts + 5000
1472 " bytes, pts %" PRIu64
"\n",
avio_tell(pb), ts);
1507 int64_t currentpos, cuespos;
1540 cues_end - cuespos);
1544 if (cues_end < cuespos + mkv->reserve_cues_space)
1553 if (ret < 0)
return ret;
1618 #define OFFSET(x) offsetof(MatroskaMuxContext, x)
1619 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM
1621 {
"reserve_index_space",
"Reserve a given amount of space (in bytes) at the beginning "
1626 #if CONFIG_MATROSKA_MUXER
1627 static const AVClass matroska_class = {
1637 .mime_type =
"video/x-matroska",
1638 .extensions =
"mkv",
1640 .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
1642 .video_codec = CONFIG_LIBX264_ENCODER ?
1659 .priv_class = &matroska_class,
1663 #if CONFIG_WEBM_MUXER
1664 static const AVClass webm_class = {
1674 .mime_type =
"video/webm",
1675 .extensions =
"webm",
1685 .priv_class = &webm_class,
1689 #if CONFIG_MATROSKA_AUDIO_MUXER
1690 static const AVClass mka_class = {
1699 .mime_type =
"audio/x-matroska",
1700 .extensions =
"mka",
1702 .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
1712 .priv_class = &mka_class,