15

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!

Thanos Markou
  • 2,587
  • 3
  • 25
  • 32
damicolo
  • 161
  • 1
  • 7

1 Answers1

3

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.

azt
  • 2,100
  • 16
  • 25
  • I am decoding a raw live stream, so I do not have a `AVFormatContext`, so `av_seek_frame()` won't work. I, too, thought about multiple decoders in parallel, but that would be inefficient. Do you have any other ideas? Thanks.. – zahirdhada Apr 28 '15 at 09:54
  • Are you referring to [this use case](https://www.mail-archive.com/libav-user@ffmpeg.org/msg08024.html)? I would either store the whole stream and work for every path from the beginning. Or I'd try to re-encode the stream into a more friendly, seekable format, when I receive it, – azt Apr 28 '15 at 10:10