EmguFFmpeg
EmguFFmpeg copied to clipboard
Decode Frame at specific timestamp - How on earth do I seek?
How do I seek? Such a simple question, no comprehensive answers at all.
EDIT: Ignore everything below, Demuxer
implicitly casts itself to AVFormatContext*
.
I need to decode frames at specific timestamps. This is normally done with av_seek_frame. However this wrapper hasn't implemented it.
I tried using the function directly from FFmpeg.Autogen but it requires
AVFormatContext*
as an input and theDemuxer.Ref
is of typeAVFormatContext
.My first thought was doing
ffmpeg.av_seek_frame(&(demuxer.Ref), ...)
But of course,Cannot take the address of the given expression
Then I tried
fixed (AVFormatContext* fmt_ctx = &demuxer.Ref)
Same error.I will be honest, I don't really understand fixed statements, why they are even needed or how C# works with pointers and I would really appreciate some help.
In my memory av_seek_frame it seems like an old version of the API, the latest recommended practice is to use avformat_seek_file, call the av_seek_frame internally and add some processing. Please correct me if there is an error in the above information. I implemented a Seek feature here, but it hasn't been rigorously tested. public int Seek(TimeSpan time, int streamIndex = -1)
Seek works fine. However I'm having trouble to integrate it in my code. All I want to do is Seek to a very specific frame. Seek helps by reading the last keyframe before the actual frame I want. Then I have to decode frames until I get back the correct one. However I'm having trouble with the last part. Some of my attempts have resulted to frame data being read but not actually being decoded - i only saw the "deltas" (basically it treated p frames as i frames, which is wrong). Most of my other tries resulted in hangs/exceptions.
@teoAlivanoglou 1.The nearest keyframe before the seek position must be passed to the decoder. 2.Then decoded frame by frame to the seek position. 3.Read the decoder repeatedly until the end of the reading, note that the decoder has an internal buffer, and finally fill the decoder with empty data to squeeze out the data in the decoder buffer.