[Libav-user] What to pass to avcodec_decode_video2 for H.264 Transport Stream?
danny at klarity.tv
Fri Nov 25 03:46:38 EET 2016
I want to decode H.264 video from a collection of MPEG-2 Transport Stream packets but I am not clear what to pass to `avcodec_decode_video2`
The documentation  says to pass "the input AVPacket containing the input buffer."
But what should be in the input buffer?
A PES packet will be spread across the payload portion of several TS packets, with NALU(s) inside the PES. So pass a TS fragment? The entire PES? PES payload only?
Or do I strip the PES header and pass the ES starting at the start code?
This Sample Code  mentions:
BUT some other codecs (msmpeg4, mpeg4) are inherently frame based, so
you must call them with all the data for one frame exactly. You must
also initialize 'width' and 'height' before initializing them.
But I can find no info on what "all the data" means... I'm using AV_CODEC_ID_H264. How do I know if that codec can decode in chunks or do I need to reassemble?
Passing a fragment of a TS packet payload is not working:
avDecPkt.data = inbuf_ptr;
avDecPkt.size = esBufSize;
len = avcodec_decode_video2(mpDecoderContext, mpFrameDec, &got_picture, &avDecPkt);
if (len < 0)
printf(" TS PKT #%.0f. Error decoding frame #%04d [rc=%d '%s']\n",
tsPacket.pktNum, mDecodedFrameNum, len, av_make_error_string(errMsg, 128, len));
[h264 @ 0x81cd2a0] no frame!
TS PKT #2973. Error decoding frame #0001 [rc=-1094995529 'Invalid data found when processing input']
And I get lots and lots of these errors!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libav-user