Mercurial > libavformat.hg
comparison mxfenc.c @ 4449:aaae79b414f3 libavformat
parse mpeg2 gop header time code and use it
author | bcoudurier |
---|---|
date | Wed, 11 Feb 2009 08:02:23 +0000 |
parents | 587ce9359a9b |
children | 21945a5288cb |
comparison
equal
deleted
inserted
replaced
4448:587ce9359a9b | 4449:aaae79b414f3 |
---|---|
124 unsigned body_partitions_count; | 124 unsigned body_partitions_count; |
125 int last_key_index; ///< index of last key frame | 125 int last_key_index; ///< index of last key frame |
126 uint64_t duration; | 126 uint64_t duration; |
127 AVStream *timecode_track; | 127 AVStream *timecode_track; |
128 int timecode_base; ///< rounded time code base (25 or 30) | 128 int timecode_base; ///< rounded time code base (25 or 30) |
129 int timecode_start; ///< value from mpeg-2 essence gop header | 129 int timecode_start; ///< frame number computed from mpeg-2 gop header timecode |
130 int timecode_drop_frame; ///< time code use drop frame method frop mpeg-2 essence gop header | 130 int timecode_drop_frame; ///< time code use drop frame method frop mpeg-2 essence gop header |
131 } MXFContext; | 131 } MXFContext; |
132 | 132 |
133 static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd }; | 133 static const uint8_t uuid_base[] = { 0xAD,0xAB,0x44,0x24,0x2f,0x25,0x4d,0xc7,0x92,0xff,0x29,0xbd }; |
134 static const uint8_t umid_base[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x01,0x0D,0x00,0x13,0x00,0x00,0x00 }; | 134 static const uint8_t umid_base[] = { 0x06,0x0A,0x2B,0x34,0x01,0x01,0x01,0x05,0x01,0x01,0x0D,0x00,0x13,0x00,0x00,0x00 }; |
1206 } | 1206 } |
1207 | 1207 |
1208 static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt, int *flags) | 1208 static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt, int *flags) |
1209 { | 1209 { |
1210 MXFStreamContext *sc = st->priv_data; | 1210 MXFStreamContext *sc = st->priv_data; |
1211 MXFContext *mxf = s->priv_data; | |
1211 uint32_t c = -1; | 1212 uint32_t c = -1; |
1212 int i; | 1213 int i; |
1213 | 1214 |
1214 *flags = 0; | 1215 *flags = 0; |
1215 | 1216 |
1222 } else if (i + 5 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x80) { // pict coding ext | 1223 } else if (i + 5 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x80) { // pict coding ext |
1223 sc->interlaced = !(pkt->data[i+5] & 0x80); // progressive frame | 1224 sc->interlaced = !(pkt->data[i+5] & 0x80); // progressive frame |
1224 break; | 1225 break; |
1225 } | 1226 } |
1226 } else if (c == 0x1b8) { // gop | 1227 } else if (c == 0x1b8) { // gop |
1227 if (i + 4 < pkt->size && pkt->data[i+4]>>6 & 0x01) // closed | 1228 if (i + 4 < pkt->size) { |
1228 *flags |= 0x80; // random access | 1229 if (pkt->data[i+4]>>6 & 0x01) // closed |
1230 *flags |= 0x80; // random access | |
1231 if (!mxf->header_written) { | |
1232 unsigned hours = (pkt->data[i+1]>>2) & 0x1f; | |
1233 unsigned minutes = ((pkt->data[i+1] & 0x03) << 4) | (pkt->data[i+2]>>4); | |
1234 unsigned seconds = ((pkt->data[i+2] & 0x07) << 3) | (pkt->data[i+3]>>5); | |
1235 unsigned frames = ((pkt->data[i+3] & 0x1f) << 1) | (pkt->data[i+4]>>7); | |
1236 mxf->timecode_drop_frame = !!(pkt->data[i+1] & 0x80); | |
1237 mxf->timecode_start = (hours*3600 + minutes*60 + seconds) * | |
1238 mxf->timecode_base + frames; | |
1239 if (mxf->timecode_drop_frame) { | |
1240 unsigned tminutes = 60 * hours + minutes; | |
1241 mxf->timecode_start -= 2 * (tminutes - tminutes / 10); | |
1242 } | |
1243 av_log(s, AV_LOG_DEBUG, "frame %d %d:%d:%d%c%d\n", mxf->timecode_start, | |
1244 hours, minutes, seconds, mxf->timecode_drop_frame ? ';':':', frames); | |
1245 } | |
1246 } | |
1229 } else if (c == 0x1b3) { // seq | 1247 } else if (c == 0x1b3) { // seq |
1230 *flags |= 0x40; | 1248 *flags |= 0x40; |
1231 } else if (c == 0x100) { // pic | 1249 } else if (c == 0x100) { // pic |
1232 int pict_type = (pkt->data[i+2]>>3) & 0x07; | 1250 int pict_type = (pkt->data[i+2]>>3) & 0x07; |
1233 if (pict_type == 2) { // P frame | 1251 if (pict_type == 2) { // P frame |
1370 MXFContext *mxf = s->priv_data; | 1388 MXFContext *mxf = s->priv_data; |
1371 ByteIOContext *pb = s->pb; | 1389 ByteIOContext *pb = s->pb; |
1372 unsigned frame; | 1390 unsigned frame; |
1373 uint32_t time_code; | 1391 uint32_t time_code; |
1374 | 1392 |
1375 frame = mxf->last_indexed_edit_unit + mxf->edit_units_count; | 1393 frame = mxf->timecode_start + mxf->last_indexed_edit_unit + mxf->edit_units_count; |
1376 | 1394 |
1377 // write system metadata pack | 1395 // write system metadata pack |
1378 put_buffer(pb, system_metadata_pack_key, 16); | 1396 put_buffer(pb, system_metadata_pack_key, 16); |
1379 klv_encode_ber_length(pb, 57); | 1397 klv_encode_ber_length(pb, 57); |
1380 put_byte(pb, 0x5c); // UL, user date/time stamp, picture and sound item present | 1398 put_byte(pb, 0x5c); // UL, user date/time stamp, picture and sound item present |