播放長度與百分比計算

總長度: _formatCtx->duration / AV_TIME_BASE;

當前frame的postion: avcodec_decode_video2(_videoCodecCtx, _videoFrame, &gotframe, &packet); float position = av_frame_get_best_effort_timestamp(_videoFrame) * _videoTimeBase;

當前播放百分比(0.0~1.0): AVStream *st = _formatCtx->streams[_videoStream]; float start_time = st->start_time * _videoTimeBase; avcodec_decode_video2(_videoCodecCtx, _videoFrame, &gotframe, &packet); float position = av_frame_get_best_effort_timestamp(_videoFrame) * _videoTimeBase; float video_position = position - start_time; float video_duration = _formatCtx->duration / AV_TIME_BASE; float video_persent = video_position / video_duration;

以下資料也許可以幫到你: 官網的sample: http://ffmpeg.org/doxygen/trunk/examples.html 非官方ffmpeg-tutorial https://github.com/chelyaev/ffmpeg-tutorial/blob/master/tutorial03.c 別人寫的簡易ffmpeg+SDL(程式碼不多): http://blog.csdn.net/leixiaohua1020/article/details/38868499