________________________________________ From: libav-user-boun...@ffmpeg.org [libav-user-boun...@ffmpeg.org] on behalf of coo...@megaroms.co.uk [coo...@megaroms.co.uk] Sent: Friday, January 23, 2015 7:10 PM To: libav-user@ffmpeg.org Subject: [SPAM] [Libav-user] Reliably getting the current frame number
Hi all, I'm having some problems just doing a simple thing: getting the current frame number from a decoded AVFrame. I tried a few things (starting from the most obvious) but I couldn't find one that consistently works: 1) Look at AVFrame.display_picture_number. Sadly, this seems to be zero for all the files I've decoded. 2) Look at AVFrame.display_picture_number. This seems to count sequentially from zero for most files (e.g. MP4) but stays at zero for others (e.g. LAGS). (Aside: it also makes me wonder if the h264 is reordering frames for me.) 3) Use av_frame_get_best_effort_timestamp(frame) to get frame timestamp. This field always appears to be set but to convert it to a frame number I need to know the average display time of a frame. Sadly AVStream.avg_frame_rate is often zero. 4) Look at AVFrame.pts. Seems to stay stuck at zero for many files and I still can't convert it similar to 3. So, is it possible to get the current frame number reliably? (Background: I'm getting skipped frames when decoding a lagarith (LAGS) video. I'm trying to detect when a frame has been skipped which (hopefully) will give me a clue to why a frame is skipped.) Thanks. _______________________________________________ Libav-user mailing list Libav-user@ffmpeg.org http://ffmpeg.org/mailman/listinfo/libav-user you should rely on the AVPacket.pts, and rescale that value from the AVStream.time_base to 1/avg_framerate. you can compute the average framerate base on AVStream.time_base. int64_t framerate = floor( 1.00 / ( ( double )AVStream.time_base.num / ( double )AVStream.time_base.den ) ); int64_t fnumber = av_rescale_q( AVPacket.pts, AVStream.time_base, { 1, avg_framerate } ); just watch pay attention to the time_base your are using, the stream usually has different timebase than the codec. _______________________________________________ Libav-user mailing list Libav-user@ffmpeg.org http://ffmpeg.org/mailman/listinfo/libav-user