ffmpeg c++ API encode mpegts with KLV data stream
<p>I need to encode an mpegts video using the ffmpeg C++ API. The output video shall have two streams: the first one shall be of type AVMEDIA_TYPE_VIDEO; the second one shall be of type AVMEDIA_TYPE_DATA and shall contain a set of KLV data.</p>

<p>I have written my own KLV library to manage the KLV format.</p>

<p>However I'm not able to create "from scratch" a new video by combining the two streams. Following the implementation as in <a href="https://stackoverflow.com/questions/28727772/ffmpeg-c-api-h-264-encoding-mpeg2-ts-streaming-problems">FFMPEG C api h.264 encoding / MPEG2 ts streaming problems</a> I can successfully encode a mpegts video with a single video stream.</p>

<p>However I'm not able to add a new AVMEDIA_TYPE_DATA stream to the output video since, as soon as I add a new data stream using methods like avformat_new_stream(...) the output video is empty: neither the data stream nor the video one are produced and the output file is empty.</p>

<p>Can anyone suggest me a tutorial page or a sample on how to properly add a data stream to my output video in mpegts format?</p>

<p>Thanks a lot!</p>