comparison mxfenc.c @ 4437:9cb07916bf47 libavformat

retrieve flags from mxf_parse_mpeg2_frame using a param
author bcoudurier
date Tue, 10 Feb 2009 08:31:48 +0000
parents 98928aca0df9
children f70863323853
comparison
equal deleted inserted replaced
4436:98928aca0df9 4437:9cb07916bf47
1099 &mxf_mpeg2_codec_uls[6]; 1099 &mxf_mpeg2_codec_uls[6];
1100 } 1100 }
1101 return NULL; 1101 return NULL;
1102 } 1102 }
1103 1103
1104 static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt) 1104 static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt, int *flags)
1105 { 1105 {
1106 MXFContext *mxf = s->priv_data;
1107 MXFStreamContext *sc = st->priv_data; 1106 MXFStreamContext *sc = st->priv_data;
1108 uint32_t c = -1; 1107 uint32_t c = -1;
1109 int i; 1108 int i;
1110 1109
1111 mxf->index_entries[mxf->edit_units_count].flags = 0; 1110 *flags = 0;
1112 1111
1113 for(i = 0; i < pkt->size - 4; i++) { 1112 for(i = 0; i < pkt->size - 4; i++) {
1114 c = (c<<8) + pkt->data[i]; 1113 c = (c<<8) + pkt->data[i];
1115 if (c == 0x1B5) { 1114 if (c == 0x1B5) {
1116 if (i + 2 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x10) { // seq ext 1115 if (i + 2 < pkt->size && (pkt->data[i+1] & 0xf0) == 0x10) { // seq ext
1120 sc->interlaced = !(pkt->data[i+5] & 0x80); // progressive frame 1119 sc->interlaced = !(pkt->data[i+5] & 0x80); // progressive frame
1121 break; 1120 break;
1122 } 1121 }
1123 } else if (c == 0x1b8) { // gop 1122 } else if (c == 0x1b8) { // gop
1124 if (i + 4 < pkt->size && pkt->data[i+4]>>6 & 0x01) // closed 1123 if (i + 4 < pkt->size && pkt->data[i+4]>>6 & 0x01) // closed
1125 mxf->index_entries[mxf->edit_units_count].flags |= 0x80; // random access 1124 *flags |= 0x80; // random access
1126 } else if (c == 0x1b3) { // seq 1125 } else if (c == 0x1b3) { // seq
1127 mxf->index_entries[mxf->edit_units_count].flags |= 0x40; 1126 *flags |= 0x40;
1128 } else if (c == 0x100) { // pic 1127 } else if (c == 0x100) { // pic
1129 int pict_type = (pkt->data[i+2]>>3) & 0x07; 1128 int pict_type = (pkt->data[i+2]>>3) & 0x07;
1130 if (pict_type == 2) { // P frame 1129 if (pict_type == 2) { // P frame
1131 mxf->index_entries[mxf->edit_units_count].flags |= 0x22; 1130 *flags |= 0x22;
1132 st->codec->gop_size = 1; 1131 st->codec->gop_size = 1;
1133 } else if (pict_type == 3) { // B frame 1132 } else if (pict_type == 3) { // B frame
1134 mxf->index_entries[mxf->edit_units_count].flags |= 0x33; 1133 *flags |= 0x33;
1135 sc->temporal_reordering = -1; 1134 sc->temporal_reordering = -1;
1136 } else if (!pict_type) { 1135 } else if (!pict_type) {
1137 av_log(s, AV_LOG_ERROR, "error parsing mpeg2 frame\n"); 1136 av_log(s, AV_LOG_ERROR, "error parsing mpeg2 frame\n");
1138 return 0; 1137 return 0;
1139 } 1138 }
1304 { 1303 {
1305 MXFContext *mxf = s->priv_data; 1304 MXFContext *mxf = s->priv_data;
1306 ByteIOContext *pb = s->pb; 1305 ByteIOContext *pb = s->pb;
1307 AVStream *st = s->streams[pkt->stream_index]; 1306 AVStream *st = s->streams[pkt->stream_index];
1308 MXFStreamContext *sc = st->priv_data; 1307 MXFStreamContext *sc = st->priv_data;
1308 int flags = 0;
1309 1309
1310 if (!(mxf->edit_units_count % MXF_INDEX_CLUSTER_SIZE)) { 1310 if (!(mxf->edit_units_count % MXF_INDEX_CLUSTER_SIZE)) {
1311 mxf->index_entries = av_realloc(mxf->index_entries, 1311 mxf->index_entries = av_realloc(mxf->index_entries,
1312 (mxf->edit_units_count + MXF_INDEX_CLUSTER_SIZE)* 1312 (mxf->edit_units_count + MXF_INDEX_CLUSTER_SIZE)*
1313 sizeof(*mxf->index_entries)); 1313 sizeof(*mxf->index_entries));
1316 return -1; 1316 return -1;
1317 } 1317 }
1318 } 1318 }
1319 1319
1320 if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) { 1320 if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) {
1321 if (!mxf_parse_mpeg2_frame(s, st, pkt)) { 1321 if (!mxf_parse_mpeg2_frame(s, st, pkt, &flags)) {
1322 av_log(s, AV_LOG_ERROR, "could not get mpeg2 profile and level\n"); 1322 av_log(s, AV_LOG_ERROR, "could not get mpeg2 profile and level\n");
1323 return -1; 1323 return -1;
1324 } 1324 }
1325 } 1325 }
1326 1326
1330 } 1330 }
1331 1331
1332 if (st->index == 0) { 1332 if (st->index == 0) {
1333 mxf_write_klv_fill(s); 1333 mxf_write_klv_fill(s);
1334 mxf->index_entries[mxf->edit_units_count].offset = url_ftell(pb); 1334 mxf->index_entries[mxf->edit_units_count].offset = url_ftell(pb);
1335 mxf->index_entries[mxf->edit_units_count].flags = flags;
1335 mxf_write_system_item(s); 1336 mxf_write_system_item(s);
1336 1337
1337 mxf->edit_units_count++; 1338 mxf->edit_units_count++;
1338 } else if (st->index == 1) { 1339 } else if (st->index == 1) {
1339 mxf->index_entries[mxf->edit_units_count-1].slice_offset = 1340 mxf->index_entries[mxf->edit_units_count-1].slice_offset =