<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>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`</div><div><br></div><div><a href="https://www.ffmpeg.org/doxygen/2.7/group__lavc__decoding.html#ga99ee61b6dcffb7817a275d39da58cc74">The documentation</a> [1] says to pass "the input AVPacket containing the input buffer."</div><div><br></div><div>But what should be in the input buffer?</div><div><br></div><div>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?</div><div><br></div><div><span style="color: rgb(36, 39, 41); font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 16.9px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">Or do I strip the PES header and pass the ES starting at the start code?</span></div><div><br></div><div>This <a href="https://fossies.org/linux/ffmpeg/doc/examples/decoding_encoding.c">Sample Code</a> [2] mentions:</div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><i>BUT some other codecs (msmpeg4, mpeg4) are inherently frame based, so</i></div><div><i>you must call them with all the data for one frame exactly. You must</i></div><div><i>also initialize 'width' and 'height' before initializing them. </i></div></blockquote><div><br></div><div>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?</div><div><br></div><div>Passing a fragment of a TS packet payload is not working:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>AVPacket avDecPkt;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>av_init_packet(&avDecPkt);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>avDecPkt.data = inbuf_ptr;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>avDecPkt.size = esBufSize;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>len = avcodec_decode_video2(mpDecoderContext, mpFrameDec, &got_picture, &avDecPkt);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>if (len < 0)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>printf(" TS PKT #%.0f. Error decoding frame #%04d [rc=%d '%s']\n",</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>tsPacket.pktNum, mDecodedFrameNum, len, av_make_error_string(errMsg, 128, len));</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>return;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div><b>OUTPUT</b></div><div><br></div><div> [h264 @ 0x81cd2a0] no frame!</div><div> TS PKT #2973. Error decoding frame #0001 [rc=-1094995529 'Invalid data found when processing input']</div><div><br></div><div>And I get lots and lots of these errors!</div><div><br></div><div> [1]: <a href="https://www.ffmpeg.org/doxygen/2.7/group__lavc__decoding.html#ga99ee61b6dcffb7817a275d39da58cc74">https://www.ffmpeg.org/doxygen/2.7/group__lavc__decoding.html#ga99ee61b6dcffb7817a275d39da58cc74</a></div><div> [2]: <a href="https://fossies.org/linux/ffmpeg/doc/examples/decoding_encoding.c">https://fossies.org/linux/ffmpeg/doc/examples/decoding_encoding.c</a></div></body></html>