[Libav-user] decoding a duplicated packet in another process
Michael R. Hines
michael at hinespot.com
Mon Dec 24 20:54:56 CET 2012
My task is to send AVPackets over the network (to another process)
that does not have access to the original video for transcoding
purposes. To do this, I need to duplicate the packet data and the
AVPacket struct, like this:
Pseudocode (in a 2nd C program talking TCP/IP):
1. Allocate AVCodec with avcodec_find_decoder(mpeg2)
2. Allocate AVCodecContext with avcodec_alloc_context3()
3. Open the codec with avcodec_open2()
4. av_malloc() some space to get the duplicate packet data from network
No problems so far....
(Note: there's no AVFormatContext or AVStream here because I want to
copy the packet rather than read it from the original stream).
Then, I proceed to read in a copy of the AVPacket structure from the
network, along with the data portion of the packet that was pulled
previously from the original video stream. (side_data_elems == 0,
so I just ignored that part of the packet).
This all works fine -- all the AVPacket values are there, the
data is assigned to the AVPacket successfully.
But, then I try to decode the packet, with
avcodec_decode_video2(duplicated packet), and I get:
[mpeg2video @ 0xa9f3420] mpeg_decode_postinit() failure
I even ran GDB and found out that the failure comes from here:
function static int mpeg_decode_postinit(AVCodecContext *avctx)
line 1277: if ((s->width == 0) || (s->height == 0))
Ok, that makes sense - so the decoder is missing some information....
Which means I'm probably not performing steps #1, 2, 3 properly.
Are there are additional parameters (like width and height) in the
AVCodecContext or AVCodec structures that I'm supposed to change before
opening the codec for decoding before the MPEG2 code can start doing its
What am I missing?
- Michael R. Hines
More information about the Libav-user