comparison matroskaenc.c @ 2433:0c047310f205 libavformat

Write one cluster and SimpleBlocks for the frames. Should now create playable mkv files for some video codecs (H.264 and VP3 checked)
author conrad
date Wed, 05 Sep 2007 00:22:52 +0000
parents 68743e7fa627
children 273c76713989
comparison
equal deleted inserted replaced
2432:68743e7fa627 2433:0c047310f205
23 #include "riff.h" 23 #include "riff.h"
24 #include "matroska.h" 24 #include "matroska.h"
25 25
26 typedef struct MatroskaMuxContext { 26 typedef struct MatroskaMuxContext {
27 offset_t segment; 27 offset_t segment;
28 offset_t cluster;
28 } MatroskaMuxContext; 29 } MatroskaMuxContext;
29 30
30 static void put_ebml_id(ByteIOContext *pb, unsigned int id) 31 static void put_ebml_id(ByteIOContext *pb, unsigned int id)
31 { 32 {
32 if (id >= 0x3fffff) 33 if (id >= 0x3fffff)
213 // ms precision is the de-facto standard timescale for mkv files 214 // ms precision is the de-facto standard timescale for mkv files
214 av_set_pts_info(st, 64, 1, 1000); 215 av_set_pts_info(st, 64, 1, 1000);
215 } 216 }
216 end_ebml_master(pb, tracks); 217 end_ebml_master(pb, tracks);
217 218
219 mkv->cluster = start_ebml_master(pb, MATROSKA_ID_CLUSTER);
220 put_ebml_uint(pb, MATROSKA_ID_CLUSTERTIMECODE, 0);
221
218 return 0; 222 return 0;
219 } 223 }
220 224
221 static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) 225 static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
222 { 226 {
223 ByteIOContext *pb = &s->pb; 227 ByteIOContext *pb = &s->pb;
228
229 block = start_ebml_master(pb, MATROSKA_ID_SIMPLEBLOCK);
230 put_byte(pb, 0x80 | pkt->stream_index); // this assumes stream_index is less than 127
231 put_be16(pb, pkt->pts);
232 put_byte(pb, !!(pkt->flags & PKT_FLAG_KEY));
224 put_buffer(pb, pkt->data, pkt->size); 233 put_buffer(pb, pkt->data, pkt->size);
234 end_ebml_master(pb, block);
225 return 0; 235 return 0;
226 } 236 }
227 237
228 static int mkv_write_trailer(AVFormatContext *s) 238 static int mkv_write_trailer(AVFormatContext *s)
229 { 239 {
230 MatroskaMuxContext *mkv = s->priv_data; 240 MatroskaMuxContext *mkv = s->priv_data;
231 ByteIOContext *pb = &s->pb; 241 ByteIOContext *pb = &s->pb;
242 end_ebml_master(pb, mkv->cluster);
232 end_ebml_master(pb, mkv->segment); 243 end_ebml_master(pb, mkv->segment);
233 return 0; 244 return 0;
234 } 245 }
235 246
236 AVOutputFormat matroska_muxer = { 247 AVOutputFormat matroska_muxer = {