The following is a pseudo-code representation of part of my system. I
have already created working code to spew out sequences of frames from
an mp4 file. However, I have changed the structure slightly so that I
can introduce seeking.
Consider the following code...
AVFormatContext *FCtx
AVCodecContext *CCtx
AVFrame *pFrame;
AVFrame *pFrameRGB;
AVPacket *Pkt
void read_some_frames(int frames_wanted)
{
while(av_read_frame(FCtx, Pkt)>=0 && frames_found > frames wanted)
{
avcodec_decode_video(CCtx, pFrame, frameFinished, Pkt->data,
Pkt->size);
if (frameFinished)
{
++frames_found
use sws_scale to extract an RGB frame
}
av_free_packet(Pkt);
}
}
Assuming we are starting at a key frame (pFrame->key_frame is true)...
If I use this function to read 100 frames
i.e. read_some_frames(100)
- all is fine. The frames extract OK.
However, if I call this function 100 times
i.e. read_some_frames(1) * 100
- then it is as if the incremental nature of the read is lost and the
frames
simply get increasingly corrupt. I was under the impression that if I
defined
all the AV variables FCtx CCtx pFrame pFrameRGB Pkt globally (outside
the
function) then the 'stream pointer' would not be lost between
invocations.
1) Can anyone tell me why these two scenarios are different? What is so
crucial
about incrementing long the file within the while loop as opposed to
nipping in
out of the while loop to achieve the same thing?
2) The user in this case wishes to navigate via frame number rather than
time. Can anyone tell me if there is a better way to go to a particular
frame in the file other than converting frame number requested into a
timestamp and then using av_seek_frame?
Gary
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user