lavc can now perfectly seek in CFR videos

Originally committed to SVN as r164.
This commit is contained in:
Rodrigo Braz Monteiro 2006-02-25 02:27:40 +00:00
parent e8f7defb88
commit 6b17ec30b1
2 changed files with 18 additions and 13 deletions

View File

@ -179,7 +179,7 @@ void LAVCVideoProvider::UpdateDisplaySize() {
////////////////// //////////////////
// Get next frame // Get next frame
void LAVCVideoProvider::GetNextFrame() { bool LAVCVideoProvider::GetNextFrame() {
// Read packet // Read packet
AVPacket packet; AVPacket packet;
while (av_read_frame(formatContext, &packet)>=0) { while (av_read_frame(formatContext, &packet)>=0) {
@ -196,11 +196,13 @@ void LAVCVideoProvider::GetNextFrame() {
// Free packet // Free packet
av_free_packet(&packet); av_free_packet(&packet);
return; return true;
} }
} }
} }
av_free_packet(&packet);
// No more packets
return false;
} }
@ -286,21 +288,24 @@ wxBitmap LAVCVideoProvider::GetFrame(int n) {
// Needs to seek // Needs to seek
else { else {
// Get seek position // Get seek position
__int64 half = __int64(AV_TIME_BASE) * stream->r_frame_rate.den / stream->r_frame_rate.num / 2; //__int64 half = __int64(AV_TIME_BASE) * stream->r_frame_rate.den / stream->r_frame_rate.num / 2;
__int64 seekTo = __int64(n) * AV_TIME_BASE * stream->r_frame_rate.den / stream->r_frame_rate.num + stream->start_time; //__int64 seekTo = __int64(n) * AV_TIME_BASE * stream->r_frame_rate.den / stream->r_frame_rate.num + stream->start_time;
if (seekTo > half) seekTo -= half; //if (seekTo > half) seekTo -= half;
else seekTo = 0; //else seekTo = 0;
__int64 finalPos = av_rescale(seekTo,stream->time_base.den,AV_TIME_BASE * __int64(stream->time_base.num)); //__int64 finalPos = av_rescale(seekTo,stream->time_base.den,AV_TIME_BASE * __int64(stream->time_base.num));
// Seek to keyframe // Seek to keyframe
//int result = av_seek_frame(formatContext,vidStream,finalPos,0); int result = av_seek_frame(formatContext,vidStream,n,AVSEEK_FLAG_BACKWARD);
int result = av_seek_frame(formatContext,vidStream,finalPos,AVSEEK_FLAG_BACKWARD);
avcodec_flush_buffers(codecContext); avcodec_flush_buffers(codecContext);
// Seek until final frame // Seek until final frame
bool ok = true;
do { do {
GetNextFrame(); ok = GetNextFrame();
} while (lastDecodeTime < n); //if (!ok) {
// return wxBitmap(GetWidth(),GetHeight());
//}
} while (lastDecodeTime <= n && ok);
} }
// Bitmap // Bitmap

View File

@ -81,7 +81,7 @@ private:
int buffer2Size; int buffer2Size;
void UpdateDisplaySize(); void UpdateDisplaySize();
void GetNextFrame(); bool GetNextFrame();
void LoadVideo(wxString filename); void LoadVideo(wxString filename);
void Close(); void Close();
wxBitmap AVFrameToWX(AVFrame *frame); wxBitmap AVFrameToWX(AVFrame *frame);