83 #define MODE_MATROSKAv2 0x01
84 #define MODE_WEBM 0x02
115 #define MAX_SEEKENTRY_SIZE 21
119 #define MAX_CUETRACKPOS_SIZE 22
122 #define MAX_CUEPOINT_SIZE(num_tracks) 12 + MAX_CUETRACKPOS_SIZE*num_tracks
156 while ((num+1) >> bytes*7) bytes++;
171 assert(num < (1ULL<<56)-1);
175 bytes = needed_bytes;
178 assert(bytes >= needed_bytes);
180 num |= 1ULL << bytes*7;
181 for (i = bytes - 1; i >= 0; i--)
189 while (tmp>>=8) bytes++;
193 for (i = bytes - 1; i >= 0; i--)
205 const void *buf,
int size)
262 for (i = 0; i < size / 255; i++)
281 if (new_seekhead ==
NULL)
286 if (numelements > 0) {
307 sizeof(*seekhead->
entries))) < 0) {
362 currentpos = seekhead->
filepos;
389 sizeof(*cues->
entries))) < 0) {
413 uint64_t pts = entry->
pts;
420 for (j = 0; j < cues->
num_entries - i && entry[j].
pts == pts; j++) {
438 int first_header_size;
442 first_header_size = 30;
444 first_header_size = 42;
447 first_header_size, header_start, header_len) < 0) {
453 for (j = 0; j < 2; j++) {
456 for (j = 0; j < 3; j++)
457 avio_write(pb, header_start[j], header_len[j]);
489 int ret, codecpriv_size;
509 "Invalid extradata found, ALAC expects a 36-byte "
563 if (ret < 0)
return ret;
574 int output_sample_rate = 0;
616 "Only VP8 video and Vorbis audio are supported for WebM.\n");
635 else if (!native_id) {
683 if (output_sample_rate)
698 av_log(s,
AV_LOG_ERROR,
"Only audio, video, and subtitles are supported for Matroska.\n");
702 if (ret < 0)
return ret;
725 if (ret < 0)
return ret;
766 if ((p = strrchr(p,
'-')) &&
774 else if (*p >=
'a' && *p <=
'z')
799 if (ret < 0)
return ret;
828 if (ret < 0)
return ret;
838 if (ret < 0)
return ret;
848 if (ret < 0)
return ret;
870 if (ret < 0)
return ret;
878 const char *mimetype =
NULL;
904 "it cannot be deduced from the codec id.\n", i);
956 if (ret < 0)
return ret;
963 uint32_t segment_uid[4];
968 for (i = 0; i < 4; i++)
986 if (ret < 0)
return ret;
990 if (ret < 0)
return ret;
993 if (ret < 0)
return ret;
996 if (ret < 0)
return ret;
1035 int size = pkt_size + 4;
1046 int sh, sm, ss, sc, eh, em, es, ec;
1047 uint64_t start, end;
1049 if (sscanf(p,
"%*[^,],%d:%d:%d%*c%d,%d:%d:%d%*c%d",
1050 &sh, &sm, &ss, &sc, &eh, &em, &es, &ec) != 8)
1052 start = 3600000*sh + 60000*sm + 1000*ss + 10*sc;
1053 end = 3600000*eh + 60000*em + 1000*es + 10*ec;
1060 int i, layer = 0, max_duration = 0,
size, line_size, data_size = pkt->
size;
1067 max_duration =
FFMAX(duration, max_duration);
1068 end = memchr(data,
'\n', data_size);
1069 size = line_size = end ? end-data+1 : data_size;
1070 size -= end ? (end[-1]==
'\r')+1 : 0;
1072 for (i=0; i<3; i++, start++)
1073 if (!(start = memchr(start,
',',
size-(start-data))))
1074 return max_duration;
1076 sscanf(data,
"Dialogue: %d,", &layer);
1077 i = snprintf(buffer,
sizeof(buffer),
"%"PRId64
",%d,",
1080 memcpy(buffer+i, start,
size-i);
1083 "pts %" PRId64
", duration %d\n",
1096 data_size -= line_size;
1099 return max_duration;
1140 memcpy(dst + offset, src, header.
blocksize);
1165 "pts %" PRId64
", dts %" PRId64
", duration %d, flags %d\n",
1196 if (data != pkt->
data)
1205 int s_hour, s_min, s_sec, s_hsec, e_hour, e_min, e_sec, e_hsec;
1206 if (sscanf(*buf,
"%d:%2d:%2d%*1[,.]%3d --> %d:%2d:%2d%*1[,.]%3d",
1207 &s_hour, &s_min, &s_sec, &s_hsec,
1208 &e_hour, &e_min, &e_sec, &e_hsec) == 8) {
1209 s_min += 60*s_hour; e_min += 60*e_hour;
1210 s_sec += 60*s_min; e_sec += 60*e_min;
1211 s_hsec += 1000*s_sec; e_hsec += 1000*e_sec;
1212 duration = e_hsec - s_hsec;
1214 *buf += strcspn(*buf,
"\n") + 1;
1294 if (ret < 0)
return ret;
1307 int64_t cluster_time;
1330 cluster_size > 4 * 1024))) {
1332 " bytes, pts %" PRIu64
"dts %" PRIu64
"\n",
1392 int64_t currentpos, cuespos;
1414 if (ret < 0)
return ret;
1430 cues_end - cuespos);
1434 if (cues_end < cuespos + mkv->reserve_cues_space)
1443 if (ret < 0)
return ret;
1481 #define OFFSET(x) offsetof(MatroskaMuxContext, x)
1482 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM
1484 {
"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 },
1485 {
"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 },
1486 {
"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 },
1490 #if CONFIG_MATROSKA_MUXER
1491 static const AVClass matroska_class = {
1501 .mime_type =
"video/x-matroska",
1502 .extensions =
"mkv",
1518 .priv_class = &matroska_class,
1522 #if CONFIG_WEBM_MUXER
1523 static const AVClass webm_class = {
1533 .mime_type =
"video/webm",
1534 .extensions =
"webm",
1543 .priv_class = &webm_class,
1547 #if CONFIG_MATROSKA_AUDIO_MUXER
1548 static const AVClass mka_class = {
1557 .mime_type =
"audio/x-matroska",
1558 .extensions =
"mka",
1569 .priv_class = &mka_class,