Issue757 Messages msg3869 (view) Author: flicker Date: 2008-12-18.18:16:20 av_read_frame produce invalid packet pts value when reading AVI with some mpeg streams. av_mpeg4_decode_header in mpeg4video_parse not set has_b_frames in codec context according to low_delay member in MpegEncContext. This member will be set only when we call avcodec_decode_video. Path to fix this problem: Index: mpeg4video_parser.c =================================================================== --- mpeg4video_parser.c (revision 16215) +++ mpeg4video_parser.c (working copy) @@ -78,6 +78,8 @@ if (avctx->extradata_size && pc->first_picture){ init_get_bits(gb, avctx->extradata, avctx->extradata_size*8); ret = ff_mpeg4_decode_picture_header(s, gb); + if(s->flags& CODEC_FLAG_LOW_DELAY) + s->low_delay=1; } init_get_bits(gb, buf, 8 * buf_size); @@ -85,6 +87,7 @@ if (s->width) { avcodec_set_dimensions(avctx, s->width, s->height); } + avctx->has_b_frames = !s->low_delay; s1->pict_type= s->pict_type; pc->first_picture = 0; return ret; msg3874 (view) Author: michaelni Date: 2008-12-19.02:17:05 Your patch is buggy, it sets has_b_frames to a variable that may or may not be initialzed at that point, you provide no sample and no hint on how the pts are invalid. msg3878 (view) Author: flicker Date: 2008-12-19.13:21:05 may be it is buggy... like all ffmpeg library, and like all open source. But this patch solve my problem. I trying to read all packets from the stream and after that try to decode this packets. Don't ask me why, but i realy need this. When i reading packet all PTS==DTS, witch produce invalid order in reordered_opaque after decoding, but if i decode packets as soon as they readed, some PTS values in packets are AV_NOPTS_VALUE, and i can reconstruct reordered_opaque in right way at decoding step. In general, PTS value depends on avctx->has_b_frames, because it used in av_read_frame, right? Only avcodec_decode_video sets avctx->has_b_frames... and what if i never call avcodec_decode_video? All packets will be readed with invalid PTS? May be not extremly invalid, but different from case when i call avcodec_decode_video after reading evry packet. Why packet reading depends on codec processing?! I think it is not right. You choise is to use my patch or not to use. If you understend problem, you can make right (in you point of view) patch. So, mpeg1/mpeg2 stream parser sets avctx->has_b_frames in mpegvideo_extract_headers without any problems, can you tell me why mpeg4 parser can't do this? avcodec_decode_video of mpeg4 stream sets avctx->has_b_frames exacly in the same way like in my patch, am i right? AVI format store indexes at the end of file, and i can't cut usefull sample easy. msg3879 (view) Author: cehoyos Date: 2008-12-19.13:35:12 Please upload your uncut sample to ftp://ffmpeg.org/MPlayer/incoming/