Discussion:
[libav-user] libavcodec - frame accurate seeking question
Colin Braley
2008-08-01 15:40:13 UTC
Permalink
First of all, let me say the FFMpeg project in general is awesome, and
thanks a lot to the developers. Anyway, I have been coding an application
which
needs to import video files in as many formats as possible, and needs to do
fast frame-accurate seeking. I started out trying to use the
av_seek_frame(...)
function to try to do seeking. Here is some example code:

int frame = <frame number to seek to goes here>;
double t = framesToTime( frame );//function to convert frame number to time
in seconds
int64_t timestamp = t * AV_TIME_BASE;
av_seek_frame( pFormatCtx , -1 , timestamp + pFormatCtx->start_time ,
AVSEEK_FLAG_BACKWARD );

this works fine for some video formats, and doesn't work at all in others.
After searching the web, I came across this thread:
http://readlist.com/lists/mplayerhq.hu/ffmpeg-user/1/5936.html
with a lot of information. I tried all of the approaches mentioned to
getting av_seek_frame(...) to work, but none worked for all formats.
Here are my questions:

-Is av_seek_frame(...) worth using? It seems that many people online have
had trouble working with it, and if I need frame accurate seeking, should I
use this function?

-Where is the current file position stored when FFMpeg is reading a file? I
figure that if I can't get av_seek_frame(...) working well, I could just
index the file myself and get frame
accurate seeking working in this manner.

Thanks for all the help!

~Colin
Mike
2008-08-01 16:50:57 UTC
Permalink
I've just migrated from r12279 to r13712 and I'm seeing different behaviour
of the av_picture_pad function. In the earlier version, the function would
copy the source picture to the destination and then apply the padding of
specified color. With the latter version, I'm seeing the source picture is
copied to the destination, but then I see a strip of pink replacing the end
of the picture (the width of the padding) followed by the padding of
specified color. The source image is 704x480 and the destination image is
768x480, so the requested padding is (64=768-704) as right padding. The
r12279 build did not have the --enable-swscale option, while the r13712 does
have the --enable-swscale option. Any help is greatly appreciated.
Louis Brandy
2008-08-01 19:19:02 UTC
Permalink
Post by Colin Braley
-Where is the current file position stored when FFMpeg is reading a file? I
figure that if I can't get av_seek_frame(...) working well, I could just
index the file myself and get frame
accurate seeking working in this manner.
The problem is that "generalized" calculation of a timestamp that can
be passed to av_seek_frame() for frame accurate seeking is not
possible. For some formats it will work, and for others it won't.
Seems you've already figured this out.

I've built an index-based solution: See: http://lists.mplayerhq.hu/pipermail/libav-user/2008-July/001029.html

It uses time stamps as an index so you can use vanilla ffmpeg
libraries and it will build a seek-table that contains the frame
numbers of the keyframes and their time stamps. There are alot of
gotchas in different formats with this approach. Too many to list
here. I've tested it pretty extensively and it's not perfect but much
more accurate than naive time stamp calculations.
Colin Braley
2008-08-01 19:54:42 UTC
Permalink
Great library...I just had a look through the source code and it looks very
nice. Unfortunately, I am using Visual Studio and C++ for this project, so
it will be a chore to get everything to compile. Has anyone on here managed
to get this library working with VC++? Thanks again Louis for the library,
I might be dropping you a few questions when I start working with this thing
next Monday.

~Colin
Post by Louis Brandy
Post by Colin Braley
-Where is the current file position stored when FFMpeg is reading a file? I
figure that if I can't get av_seek_frame(...) working well, I could just
index the file myself and get frame
accurate seeking working in this manner.
The problem is that "generalized" calculation of a timestamp that can
be passed to av_seek_frame() for frame accurate seeking is not
possible. For some formats it will work, and for others it won't.
Seems you've already figured this out.
http://lists.mplayerhq.hu/pipermail/libav-user/2008-July/001029.html
It uses time stamps as an index so you can use vanilla ffmpeg
libraries and it will build a seek-table that contains the frame
numbers of the keyframes and their time stamps. There are alot of
gotchas in different formats with this approach. Too many to list
here. I've tested it pretty extensively and it's not perfect but much
more accurate than naive time stamp calculations.
_______________________________________________
libav-user mailing list
libav-user at mplayerhq.hu
https://lists.mplayerhq.hu/mailman/listinfo/libav-user
Louis Brandy
2008-08-01 20:14:16 UTC
Permalink
Post by Colin Braley
Great library...I just had a look through the source code and it looks very
nice. Unfortunately, I am using Visual Studio and C++ for this project, so
it will be a chore to get everything to compile. Has anyone on here managed
to get this library working with VC++? Thanks again Louis for the library,
I might be dropping you a few questions when I start working with this thing
next Monday.
~Colin
I don't think anyone has built it in VC++. I don't do much in VC++ but
I don't suspect it will be terribly difficult to port.

Feel free to email me if you want to collaborate on improving it. We
have very similar problems and I'm hoping to improve this library to
the point that its more generally useful.

-Louis

Loading...