81 #define MODE_MATROSKAv2 0x01
82 #define MODE_WEBM 0x02
110 #define MAX_SEEKENTRY_SIZE 21
114 #define MAX_CUETRACKPOS_SIZE 22
117 #define MAX_CUEPOINT_SIZE(num_tracks) 12 + MAX_CUETRACKPOS_SIZE*num_tracks
151 while ((num+1) >> bytes*7) bytes++;
170 bytes = needed_bytes;
175 num |= 1ULL << bytes*7;
176 for (i = bytes - 1; i >= 0; i--)
184 while (tmp>>=8) bytes++;
188 for (i = bytes - 1; i >= 0; i--)
257 for (i = 0; i < size / 255; i++)
276 if (new_seekhead ==
NULL)
281 if (numelements > 0) {
356 currentpos = seekhead->
filepos;
406 uint64_t pts = entry->
pts;
413 for (j = 0; j < num_tracks; j++)
414 tracks[j].has_cue = 0;
415 for (j = 0; j < cues->
num_entries - i && entry[j].
pts == pts; j++) {
416 int tracknum = entry[j].
tracknum - 1;
417 av_assert0(tracknum>=0 && tracknum<num_tracks);
418 if (tracks[tracknum].has_cue)
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]);
480 int ret, codecpriv_size;
496 "Invalid extradata found, ALAC expects a 36-byte "
549 int i, j,
ret, default_stream_exists = 0;
552 if (ret < 0)
return ret;
567 int output_sample_rate = 0;
593 if (default_stream_exists) {
612 "Only VP8 video and Vorbis audio are supported for WebM.\n");
634 else if (!native_id) {
657 || st_mode >= MATROSKA_VIDEO_STEREO_MODE_COUNT) {
659 "The specified stereo mode is not valid.\n");
673 if (d_width > INT_MAX) {
698 if (output_sample_rate)
713 av_log(s,
AV_LOG_ERROR,
"Only audio, video, and subtitles are supported for Matroska.\n");
717 if (ret < 0)
return ret;
740 if (ret < 0)
return ret;
779 if ((p = strrchr(p,
'-')) &&
787 else if (*p >=
'a' && *p <=
'z')
812 if (ret < 0)
return ret;
840 if (ret < 0)
return ret;
850 if (ret < 0)
return ret;
860 if (ret < 0)
return ret;
882 if (ret < 0)
return ret;
890 const char *mimetype =
NULL;
917 "it cannot be deduced from the codec id.\n", i);
969 "The Matroska muxer does not yet support muxing %s\n",
1001 if (ret < 0)
return ret;
1008 uint32_t segment_uid[4];
1013 for (i = 0; i < 4; i++)
1025 AV_WB64(date_utc_buf, date_utc);
1036 if (ret < 0)
return ret;
1040 if (ret < 0)
return ret;
1043 if (ret < 0)
return ret;
1046 if (ret < 0)
return ret;
1071 int size = pkt_size + 4;
1082 int sh, sm, ss, sc, eh, em, es, ec;
1085 if (sscanf(p,
"%*[^,],%d:%d:%d%*c%d,%d:%d:%d%*c%d",
1086 &sh, &sm, &ss, &sc, &eh, &em, &es, &ec) != 8)
1088 start = 3600000LL*sh + 60000LL*sm + 1000LL*ss + 10LL*sc;
1089 end = 3600000LL*eh + 60000LL*em + 1000LL*es + 10LL*ec;
1097 int i, layer = 0, max_duration = 0,
size, line_size, data_size = pkt->
size;
1104 max_duration =
FFMAX(duration, max_duration);
1105 end = memchr(data,
'\n', data_size);
1106 size = line_size = end ? end-data+1 : data_size;
1107 size -= end ? (end[-1]==
'\r')+1 : 0;
1109 for (i=0; i<3; i++, start++)
1110 if (!(start = memchr(start,
',',
size-(start-data))))
1111 return max_duration;
1113 sscanf(data,
"Dialogue: %d,", &layer);
1114 i =
snprintf(buffer,
sizeof(buffer),
"%"PRId64
",%d,",
1117 memcpy(buffer+i, start,
size-i);
1120 "pts %" PRId64
", duration %d\n",
1133 data_size -= line_size;
1136 return max_duration;
1148 uint64_t additional_id = 0;
1149 ebml_master block_group, block_additions, block_more;
1152 "pts %" PRId64
", dts %" PRId64
", duration %d, flags %d\n",
1171 additional_id =
AV_RB64(side_data);
1173 side_data_size -= 8;
1176 if (side_data_size && additional_id == 1) {
1187 if (data != pkt->
data)
1190 if (side_data_size && additional_id == 1) {
1205 int i, duration = 0;
1208 int s_hour, s_min, s_sec, s_hsec, e_hour, e_min, e_sec, e_hsec;
1209 if (sscanf(*buf,
"%d:%2d:%2d%*1[,.]%3d --> %d:%2d:%2d%*1[,.]%3d",
1210 &s_hour, &s_min, &s_sec, &s_hsec,
1211 &e_hour, &e_min, &e_sec, &e_hsec) == 8) {
1212 s_min += 60*s_hour; e_min += 60*e_hour;
1213 s_sec += 60*s_min; e_sec += 60*e_min;
1214 s_hsec += 1000*s_sec; e_hsec += 1000*e_sec;
1215 duration = e_hsec - s_hsec;
1217 *buf += strcspn(*buf,
"\n") + 1;
1289 duration = mkv_write_ass_blocks(s, pb, pkt);
1306 if (ret < 0)
return ret;
1326 || cluster_size > 5*1024*1024 || ts > mkv->
cluster_pts + 5000
1329 " bytes, pts %" PRIu64
"\n",
avio_tell(pb), ts);
1361 int64_t currentpos, cuespos;
1394 cues_end - cuespos);
1398 if (cues_end < cuespos + mkv->reserve_cues_space)
1407 if (ret < 0)
return ret;
1472 #define OFFSET(x) offsetof(MatroskaMuxContext, x)
1473 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM
1475 {
"reserve_index_space",
"Reserve a given amount of space (in bytes) at the beginning "
1480 #if CONFIG_MATROSKA_MUXER
1481 static const AVClass matroska_class = {
1491 .mime_type =
"video/x-matroska",
1492 .extensions =
"mkv",
1494 .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
1496 .video_codec = CONFIG_LIBX264_ENCODER ?
1513 .priv_class = &matroska_class,
1517 #if CONFIG_WEBM_MUXER
1518 static const AVClass webm_class = {
1528 .mime_type =
"video/webm",
1529 .extensions =
"webm",
1538 .priv_class = &webm_class,
1542 #if CONFIG_MATROSKA_AUDIO_MUXER
1543 static const AVClass mka_class = {
1552 .mime_type =
"audio/x-matroska",
1553 .extensions =
"mka",
1555 .audio_codec = CONFIG_LIBVORBIS_ENCODER ?
1565 .priv_class = &mka_class,