78 #define MODE_MATROSKAv2 0x01
79 #define MODE_WEBM 0x02
104 #define MAX_SEEKENTRY_SIZE 21
108 #define MAX_CUETRACKPOS_SIZE 22
111 #define MAX_CUEPOINT_SIZE(num_tracks) 12 + MAX_CUETRACKPOS_SIZE*num_tracks
145 while ((num+1) >> bytes*7) bytes++;
164 bytes = needed_bytes;
169 num |= 1ULL << bytes*7;
170 for (i = bytes - 1; i >= 0; i--)
178 while (tmp>>=8) bytes++;
182 for (i = bytes - 1; i >= 0; i--)
194 const void *buf,
int size)
251 for (i = 0; i < size / 255; i++)
270 if (new_seekhead ==
NULL)
275 if (numelements > 0) {
350 currentpos = seekhead->
filepos;
400 uint64_t pts = entry->
pts;
407 for (j = 0; j < num_tracks; j++)
408 tracks[j].has_cue = 0;
409 for (j = 0; j < cues->
num_entries - i && entry[j].
pts == pts; j++) {
410 int tracknum = entry[j].
tracknum - 1;
411 av_assert0(tracknum>=0 && tracknum<num_tracks);
412 if (tracks[tracknum].has_cue)
432 int first_header_size;
436 first_header_size = 30;
438 first_header_size = 42;
441 first_header_size, header_start, header_len) < 0) {
447 for (j = 0; j < 2; j++) {
450 for (j = 0; j < 3; j++)
451 avio_write(pb, header_start[j], header_len[j]);
474 int ret, codecpriv_size;
490 "Invalid extradata found, ALAC expects a 36-byte "
543 int i, j, ret, default_stream_exists = 0;
546 if (ret < 0)
return ret;
561 int output_sample_rate = 0;
587 if (default_stream_exists) {
606 "Only VP8 video and Vorbis audio are supported for WebM.\n");
628 else if (!native_id) {
651 || st_mode >= MATROSKA_VIDEO_STEREO_MODE_COUNT) {
653 "The specified stereo mode is not valid.\n");
661 if (d_width > INT_MAX) {
686 if (output_sample_rate)
701 av_log(s,
AV_LOG_ERROR,
"Only audio, video, and subtitles are supported for Matroska.\n");
705 if (ret < 0)
return ret;
728 if (ret < 0)
return ret;
767 if ((p = strrchr(p,
'-')) &&
775 else if (*p >=
'a' && *p <=
'z')
800 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;
905 "it cannot be deduced from the codec id.\n", i);
957 "The Matroska muxer does not yet support muxing %s\n",
989 if (ret < 0)
return ret;
996 uint32_t segment_uid[4];
1001 for (i = 0; i < 4; i++)
1013 AV_WB64(date_utc_buf, date_utc);
1024 if (ret < 0)
return ret;
1028 if (ret < 0)
return ret;
1031 if (ret < 0)
return ret;
1034 if (ret < 0)
return ret;
1055 int size = pkt_size + 4;
1066 int sh, sm, ss, sc, eh, em, es, ec;
1067 uint64_t start,
end;
1069 if (sscanf(p,
"%*[^,],%d:%d:%d%*c%d,%d:%d:%d%*c%d",
1070 &sh, &sm, &ss, &sc, &eh, &em, &es, &ec) != 8)
1072 start = 3600000LL*sh + 60000LL*sm + 1000LL*ss + 10LL*sc;
1073 end = 3600000LL*eh + 60000LL*em + 1000LL*es + 10LL*ec;
1080 int i, layer = 0, max_duration = 0,
size, line_size, data_size = pkt->
size;
1087 max_duration =
FFMAX(duration, max_duration);
1088 end = memchr(data,
'\n', data_size);
1089 size = line_size = end ? end-data+1 : data_size;
1090 size -= end ? (end[-1]==
'\r')+1 : 0;
1092 for (i=0; i<3; i++, start++)
1093 if (!(start = memchr(start,
',',
size-(start-data))))
1094 return max_duration;
1096 sscanf(data,
"Dialogue: %d,", &layer);
1097 i =
snprintf(buffer,
sizeof(buffer),
"%"PRId64
",%d,",
1100 memcpy(buffer+i, start,
size-i);
1103 "pts %" PRId64
", duration %d\n",
1116 data_size -= line_size;
1119 return max_duration;
1132 "pts %" PRId64
", dts %" PRId64
", duration %d, flags %d\n",
1153 if (data != pkt->
data)
1162 int s_hour, s_min, s_sec, s_hsec, e_hour, e_min, e_sec, e_hsec;
1163 if (sscanf(*buf,
"%d:%2d:%2d%*1[,.]%3d --> %d:%2d:%2d%*1[,.]%3d",
1164 &s_hour, &s_min, &s_sec, &s_hsec,
1165 &e_hour, &e_min, &e_sec, &e_hsec) == 8) {
1166 s_min += 60*s_hour; e_min += 60*e_hour;
1167 s_sec += 60*s_min; e_sec += 60*e_min;
1168 s_hsec += 1000*s_sec; e_hsec += 1000*e_sec;
1169 duration = e_hsec - s_hsec;
1171 *buf += strcspn(*buf,
"\n") + 1;
1258 if (ret < 0)
return ret;
1291 || cluster_size > 5*1024*1024 || ts > mkv->
cluster_pts + 5000
1294 " bytes, pts %" PRIu64
"\n",
avio_tell(pb), ts);
1324 int64_t currentpos, cuespos;
1349 if (ret < 0)
return ret;
1415 #if CONFIG_MATROSKA_MUXER
1419 .mime_type =
"video/x-matroska",
1420 .extensions =
"mkv",
1422 .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
1424 .video_codec = CONFIG_LIBX264_ENCODER ?
1440 #if CONFIG_WEBM_MUXER
1444 .mime_type =
"video/webm",
1445 .extensions =
"webm",
1457 #if CONFIG_MATROSKA_AUDIO_MUXER
1461 .mime_type =
"audio/x-matroska",
1462 .extensions =
"mka",
1464 .audio_codec = CONFIG_LIBVORBIS_ENCODER ?