Start a new cluster every 5 MB or 5 seconds

Originally committed as revision 10306 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
David Conrad 2007-09-05 00:23:00 +00:00
parent 6d50a935c9
commit 98186e416d

View File

@ -27,6 +27,7 @@
typedef struct MatroskaMuxContext { typedef struct MatroskaMuxContext {
offset_t segment; offset_t segment;
offset_t cluster; offset_t cluster;
uint64_t cluster_pts;
} MatroskaMuxContext; } MatroskaMuxContext;
static void put_ebml_id(ByteIOContext *pb, unsigned int id) static void put_ebml_id(ByteIOContext *pb, unsigned int id)
@ -249,18 +250,28 @@ static int mkv_write_header(AVFormatContext *s)
mkv->cluster = start_ebml_master(pb, MATROSKA_ID_CLUSTER); mkv->cluster = start_ebml_master(pb, MATROSKA_ID_CLUSTER);
put_ebml_uint(pb, MATROSKA_ID_CLUSTERTIMECODE, 0); put_ebml_uint(pb, MATROSKA_ID_CLUSTERTIMECODE, 0);
mkv->cluster_pts = 0;
return 0; return 0;
} }
static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
{ {
MatroskaMuxContext *mkv = s->priv_data;
ByteIOContext *pb = &s->pb; ByteIOContext *pb = &s->pb;
offset_t block; offset_t block;
// start a new cluster every 5 MB or 5 sec
if (url_ftell(pb) > mkv->cluster + 5*1024*1024 || pkt->pts > mkv->cluster_pts + 5000) {
end_ebml_master(pb, mkv->cluster);
mkv->cluster = start_ebml_master(pb, MATROSKA_ID_CLUSTER);
put_ebml_uint(pb, MATROSKA_ID_CLUSTERTIMECODE, pkt->pts);
mkv->cluster_pts = pkt->pts;
}
block = start_ebml_master(pb, MATROSKA_ID_SIMPLEBLOCK); block = start_ebml_master(pb, MATROSKA_ID_SIMPLEBLOCK);
put_byte(pb, 0x80 | pkt->stream_index); // this assumes stream_index is less than 127 put_byte(pb, 0x80 | pkt->stream_index); // this assumes stream_index is less than 127
put_be16(pb, pkt->pts); put_be16(pb, pkt->pts - mkv->cluster_pts);
put_byte(pb, !!(pkt->flags & PKT_FLAG_KEY)); put_byte(pb, !!(pkt->flags & PKT_FLAG_KEY));
put_buffer(pb, pkt->data, pkt->size); put_buffer(pb, pkt->data, pkt->size);
end_ebml_master(pb, block); end_ebml_master(pb, block);