diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2010-02-12 19:25:23 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2010-02-12 19:25:23 +0000 |
commit | 3566042a0dfd7c016e6e9945e63699dd7296adb2 (patch) | |
tree | 8ce68de21e9e8308fd9d1a51ac8825aad6db68e9 | |
parent | 9f1d760a278f59a015acbc3d432f0fddff57604e (diff) | |
download | ffmpeg-3566042a0dfd7c016e6e9945e63699dd7296adb2.tar.gz |
Try to support truncated h264 frames mixed with mpeg pes headers in mkv.
Fixes issue1585
Originally committed as revision 21772 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavcodec/avcodec.h | 1 | ||||
-rw-r--r-- | libavcodec/h264.c | 11 | ||||
-rw-r--r-- | libavcodec/options.c | 1 |
3 files changed, 13 insertions, 0 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 34b508301a..838d892bb7 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1308,6 +1308,7 @@ typedef struct AVCodecContext { #define FF_BUG_HPEL_CHROMA 2048 #define FF_BUG_DC_CLIP 4096 #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders. +#define FF_BUG_TRUNCATED 16384 //#define FF_BUG_FAKE_SCALABILITY 16 //Autodetection should work 100%. /** diff --git a/libavcodec/h264.c b/libavcodec/h264.c index bbe710edb2..dfe618b444 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -2257,6 +2257,10 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ } eos = get_cabac_terminate( &h->cabac ); + if((s->workaround_bugs & FF_BUG_TRUNCATED) && h->cabac.bytestream > h->cabac.bytestream_end + 2){ + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); + return 0; + } if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 2) { av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%td)\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytestream); ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); @@ -2492,8 +2496,15 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){ if (ptr==NULL || dst_length < 0){ return -1; } + i= buf_index + consumed; + if((s->workaround_bugs & FF_BUG_AUTODETECT) && i+3<next_avc && + buf[i]==0x00 && buf[i+1]==0x00 && buf[i+2]==0x01 && buf[i+3]==0xE0) + s->workaround_bugs |= FF_BUG_TRUNCATED; + + if(!(s->workaround_bugs & FF_BUG_TRUNCATED)){ while(ptr[dst_length - 1] == 0 && dst_length > 0) dst_length--; + } bit_length= !dst_length ? 0 : (8*dst_length - ff_h264_decode_rbsp_trailing(h, ptr + dst_length - 1)); if(s->avctx->debug&FF_DEBUG_STARTCODE){ diff --git a/libavcodec/options.c b/libavcodec/options.c index bb69ba80e4..e44da96c58 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -153,6 +153,7 @@ static const AVOption options[]={ {"hpel_chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_HPEL_CHROMA, INT_MIN, INT_MAX, V|D, "bug"}, {"dc_clip", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_DC_CLIP, INT_MIN, INT_MAX, V|D, "bug"}, {"ms", "workaround various bugs in microsofts broken decoders", 0, FF_OPT_TYPE_CONST, FF_BUG_MS, INT_MIN, INT_MAX, V|D, "bug"}, +{"trunc", "trancated frames", 0, FF_OPT_TYPE_CONST,FF_BUG_TRUNCATED, INT_MIN, INT_MAX, V|D, "bug"}, {"lelim", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)", OFFSET(luma_elim_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, {"celim", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)", OFFSET(chroma_elim_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, {"strict", "how strictly to follow the standards", OFFSET(strict_std_compliance), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|V|D|E, "strict"}, |