| 1281 | } |
| 1282 | |
| 1283 | static int isIframe( hb_stream_t *stream, const uint8_t *buf, int len ) |
| 1284 | { |
| 1285 | // For mpeg2: look for a gop start or i-frame picture start |
| 1286 | // for h.264: look for idr nal type or a slice header for an i-frame |
| 1287 | // for vc1: look for a Sequence header |
| 1288 | int ii; |
| 1289 | uint32_t strid = 0; |
| 1290 | |
| 1291 | |
| 1292 | int vid = pes_index_of_video( stream ); |
| 1293 | hb_pes_stream_t *pes = &stream->pes.list[vid]; |
| 1294 | if ( pes->stream_type <= 2 || |
| 1295 | pes->codec_param == AV_CODEC_ID_MPEG1VIDEO || |
| 1296 | pes->codec_param == AV_CODEC_ID_MPEG2VIDEO ) |
| 1297 | { |
| 1298 | // This section of the code handles MPEG-1 and MPEG-2 video streams |
| 1299 | for (ii = 0; ii < len; ii++) |
| 1300 | { |
| 1301 | strid = (strid << 8) | buf[ii]; |
| 1302 | if ( ( strid >> 8 ) == 1 ) |
| 1303 | { |
| 1304 | // we found a start code |
| 1305 | uint8_t id = strid; |
| 1306 | switch ( id ) |
| 1307 | { |
| 1308 | case 0xB8: // group_start_code (GOP header) |
| 1309 | case 0xB3: // sequence_header code |
| 1310 | return 1; |
| 1311 | |
| 1312 | case 0x00: // picture_start_code |
| 1313 | // picture_header, let's see if it's an I-frame |
| 1314 | if (ii < len - 3) |
| 1315 | { |
| 1316 | // check if picture_coding_type == 1 |
| 1317 | if ((buf[ii+2] & (0x7 << 3)) == (1 << 3)) |
| 1318 | { |
| 1319 | // found an I-frame picture |
| 1320 | return 1; |
| 1321 | } |
| 1322 | } |
| 1323 | break; |
| 1324 | } |
| 1325 | } |
| 1326 | } |
| 1327 | // didn't find an I-frame |
| 1328 | return 0; |
| 1329 | } |
| 1330 | if ( pes->stream_type == 0x1b || pes->codec_param == AV_CODEC_ID_H264 ) |
| 1331 | { |
| 1332 | // we have an h.264 stream |
| 1333 | for (ii = 0; ii < len; ii++) |
| 1334 | { |
| 1335 | strid = (strid << 8) | buf[ii]; |
| 1336 | if ( ( strid >> 8 ) == 1 ) |
| 1337 | { |
| 1338 | // we found a start code - remove the ref_idc from the nal type |
| 1339 | uint8_t nal_type = strid & 0x1f; |
| 1340 | if ( nal_type == 0x01 ) |
no test coverage detected