[Ffmpeg-devel] av_seek_frame() units
Andy Parkins
andyparkins
Tue Jul 5 10:17:32 CEST 2005
On Tuesday 2005 July 05 06:24, Steve Willis wrote:
> I would also very much like some more information on this. I asked a
> similar question last week, and am very grateful for the response. I am
> a newcomer to avcodec/avformat, and could really use some tips or
> example code on the best way to seek to a particular frame given its
> time, even if that frame is not a keyframe. Could someone explain the
> HURRY_UP mode that was suggested for quickly skipping from the nearest
> keyframe to the actual frame I am seeking?
>
> Like Ian, I need some help understanding how to map a timestamp to a
> framenumber as well.
I don't know for sure is my answer. However, I am having success treating the
units to av_seek_frame() as being in AV_TIME_BASE units (at present this is a
64 bit integer representing time in microseconds passed
AVFormatContext.start_time)
As to seeking to a particular (non-key) frame, I believe the suggestion from
Rich Felker was that you seek to the nearest key frame using av_seek_frame()
then enable hurry_up mode until you hit the frame you want. e.g. (error
checking and initialisation ommitted)
av_seek_frame( fmtCtx, -1, TARGET_PTS, AVSEEK_FLAG_BACKWARD );
CodecCtx->hurry_up = 1;
do {
av_read_frame( fmtCtx, &Packet );
// should really be checking that this is a video packet
MyPts = Packet.pts / Packet.duration *
AV_TIME_BASE / av_q2d( Stream->r_frame_rate);
if( MyPts > TARGET_PTS )
break;
avcodec_decode_video( CodecCtx, pFrame, &gotFrame, Packet.data,
Packet.size );
av_free_packet( &Packet );
} while(1);
CodecCtx->hurry_up = 0;
// Now near TARGET_PTS with Packet ready for decode (and free)
The calculation of MyPts is probably the answer to your question about frame
numbers and timestamp. I am sure that I am not doing this in the correct
way, but it's working for me :-)
Hope that's helped.
Andy
--
Dr Andrew Parkins, M Eng (hons), AMIEE
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20050705/fa8471ef/attachment.pgp>
More information about the ffmpeg-devel
mailing list