Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a FULL copy of a decoder?

I'm writing a video decoder (using FFMPEG/AVCodec) for a custom implementation of an mpeg4 video stream. The peculiarity of this video stream is that it could split into many "son" streams creating many P frames based on the same parent. The video stream I'm trying to decode is actually a sort of "video tree". Something like this:

I <--P <--P <---------------------P <-------------- P <------------ P
           \ <--P <--P <--P        \ <--P <--P       \ <--P <--P 

I've already wrote a basic decoder which works fine when I decide to follow one path, the problem is when I try to follow more than one path in the video tree. At this point I need to "fork" my decoder to follow two different video streams. the split could occur not only after a key frame, but even after a P frame, so I need to duplicate the AVCodecContext (I use avcodec_copy_context) but it seems to create new decoder from a clean status.. it seems to ignore the previous video status, so the decoded P frames are "applied" to an empty video frame. Probably copying the context using avcodec_copy_context is not enough... Any suggestion? How can I duplicate the context and the complete status of the decoder? Or, is there any other way to decode my stream using references? Thanks!

like image 583
damicolo Avatar asked Aug 02 '11 15:08

damicolo


1 Answers

According to the documentation: "The resulting destination codec context will be unopened, i.e. you are required to call avcodec_open() before you can use this AVCodecContext to decode/encode video/audio data."

So in order to get to the point where you are in the other decoder, I guess you would have to open the stream and seek to that same position (av_seek_frame).

Alternatively you could maintain several decoders in parallel from the beginning in case you need to fork later. This could be an option if you only need a few paths in parallel.

Or you use only a single decoder, and seek around in this instance, like e.g. with a DVD menu structure, if you only need to display a single path at any time.

like image 154
azt Avatar answered Sep 24 '22 15:09

azt