I have written a video player using the Tao framework using Tao.SDL and
Tao.FFmpeg.
I have the video player working where I can set the file and start
playing it from a specific frame (i think). The following code works to
get the video started from a desired point, however in the playing loop
I want to be able to seek to another part of the stream. The number I
pass as frameNum is a long that was previously set as the packet.pts
from a pre-processing step on the playable video.
|
if (frameNum != 0)
{
FFmpeg.av_seek_frame(pFormatContext, videoStartIndex, frameNum,
FFmpeg.AVSEEK_FLAG_ANY);
}
while ((FFmpeg.av_read_frame(pFormatContext, pPacket) >=
0)&&(running)&&(outFrameCount != 0))
{
while (Sdl.SDL_PollEvent(out evt) != 0)
{
if (evt.type == Sdl.SDL_QUIT)
{
running = false;
}
}
Packet = (FFmpeg.AVPacket)Marshal.PtrToStructure(pPacket,
typeof(FFmpeg.AVPacket));
if (Packet.stream_index == videoStartIndex)
{
byteCount = FFmpeg.avcodec_decode_video(pVideoCodecContext, pFrame, ref
frameFinished, Packet.data, Packet.size);
if (byteCount < 0)
{
MessageBox.Show("Couldn't decode frame.");
}
if (frameFinished != 0)
{
int res = FFmpeg.img_convert(pPicture, (int)PixFmt, pFrame,
(int)videoCodecContext.pix_fmt, width, height);
picture = (FFmpeg.AVPicture)Marshal.PtrToStructure(pPicture,
typeof(FFmpeg.AVPicture));
ViewVideo();
}
}
}
|
I have tried putting another seek call in the while loop that only gets
called under certain conditions (example below) and thus is supposed to
dynamically seek to another part of the video stream. However, all this
does is cause the video sequence to flash, miss a couple of frames and
then continue where it left off before it was interupted by the seek
call to a new frame location, i.e. it won't relocate to the new seek
point and continue playing from there.
|
if(certain conditions are met){
frameNum = new frame location(i.e. previous stored packet.pts);
FFmpeg.av_seek_frame(pFormatContext, videoStartIndex, frameNum,
FFmpeg.AVSEEK_FLAG_ANY);
}
|
I think its that something needs to be reset but I'm not sure if its the
packet or what. I pass it a packet.pts but I'm also not sure if this is
correct or if I should be converting it to some form of timebase before
I pass it. I can get a very ugly solution by reloading the whole file
and starting the above while loop from scratch again, however it seems
like alot of overhead. Would anyone have any ideas or advice, if so I
would really appreciate hearing about them. Thanks.
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user