| 6339 | } |
| 6340 | |
| 6341 | static int ffmpeg_is_keyframe( hb_stream_t *stream ) |
| 6342 | { |
| 6343 | uint8_t *pkt; |
| 6344 | |
| 6345 | switch (stream->ffmpeg_ic->streams[stream->ffmpeg_video_id]->codecpar->codec_id) |
| 6346 | { |
| 6347 | case AV_CODEC_ID_VC1: |
| 6348 | // XXX the VC1 codec doesn't mark key frames so to get previews |
| 6349 | // we do it ourselves here. The decoder gets messed up if it |
| 6350 | // doesn't get a SEQ header first so we consider that to be a key frame. |
| 6351 | pkt = stream->ffmpeg_pkt->data; |
| 6352 | if ( !pkt[0] && !pkt[1] && pkt[2] == 1 && pkt[3] == 0x0f ) |
| 6353 | return 1; |
| 6354 | |
| 6355 | return 0; |
| 6356 | |
| 6357 | case AV_CODEC_ID_WMV3: |
| 6358 | // XXX the ffmpeg WMV3 codec doesn't mark key frames. |
| 6359 | // Only M$ could make I-frame detection this complicated: there |
| 6360 | // are two to four bits of unused junk ahead of the frame type |
| 6361 | // so we have to look at the sequence header to find out how much |
| 6362 | // to skip. Then there are three different ways of coding the type |
| 6363 | // depending on whether it's main or advanced profile then whether |
| 6364 | // there are bframes or not so we have to look at the sequence |
| 6365 | // header to get that. |
| 6366 | pkt = stream->ffmpeg_pkt->data; |
| 6367 | uint8_t *seqhdr = stream->ffmpeg_ic->streams[stream->ffmpeg_video_id]->codecpar->extradata; |
| 6368 | int pshift = 2; |
| 6369 | if ( ( seqhdr[3] & 0x02 ) == 0 ) |
| 6370 | // no FINTERPFLAG |
| 6371 | ++pshift; |
| 6372 | if ( ( seqhdr[3] & 0x80 ) == 0 ) |
| 6373 | // no RANGEREDUCTION |
| 6374 | ++pshift; |
| 6375 | if ( seqhdr[3] & 0x70 ) |
| 6376 | // stream has b-frames |
| 6377 | return ( ( pkt[0] >> pshift ) & 0x3 ) == 0x01; |
| 6378 | |
| 6379 | return ( ( pkt[0] >> pshift ) & 0x2 ) == 0; |
| 6380 | |
| 6381 | default: |
| 6382 | break; |
| 6383 | } |
| 6384 | return ( stream->ffmpeg_pkt->flags & AV_PKT_FLAG_KEY ); |
| 6385 | } |
| 6386 | |
| 6387 | hb_buffer_t * hb_ffmpeg_read( hb_stream_t *stream ) |
| 6388 | { |