<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: Calibri, sans-serif;">
<div>
<div>
<div><br>
</div>
</div>
</div>
<span id="OLK_SRC_BODY_SECTION">
<div>
<div>
<div dir="ltr">
<p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif">
> I am trying to write a C program that demuxes audio from an MP4 file and write demuxed AVPacket data to a file. But the resulting dump is missing ADTS headers. Any pointers on what is the best way to add ADTS headers.</p>
<p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:15px;clear:both;color:rgb(36,39,41);font-family:arial,"helvetica neue",helvetica,sans-serif">
> I see that ffmpeg has 'adtsenc.c' file that seems to implement an ADTS muxer:</p>
<pre style="margin-top:0px;margin-bottom:1em;padding:5px;border:0px;font-size:13px;width:auto;max-height:600px;overflow:auto;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;background-color:rgb(239,240,241);word-wrap:normal;color:rgb(36,39,41)"><code style="margin:0px;padding:0px;border:0px;font-family:consolas,menlo,monaco,"lucida console","liberation mono","dejavu sans mono","bitstream vera sans mono","courier new",monospace,sans-serif;white-space:inherit">AVOutputFormat ff_adts_muxer = {
    .name              = "adts",
    .long_name         = NULL_IF_CONFIG_SMALL("ADTS AAC (Advanced Audio Coding)"),
    .mime_type         = "audio/aac",
    .extensions        = "aac,adts",
    .priv_data_size    = sizeof(ADTSContext),
    .audio_codec       = AV_CODEC_ID_AAC,
    .video_codec       = AV_CODEC_ID_NONE,
    .write_header      = adts_write_header,
    .write_packet      = adts_write_packet,
    .write_trailer     = adts_write_trailer,
    .priv_class        = &adts_muxer_class,
    .flags             = AVFMT_NOTIMESTAMPS,
};</code></pre>
<p style="margin:0px 0px 1em;padding:0px;border:0px;clear:both"><font color="#242729" face="arial,helvetica neue,helvetica,sans-serif"><span style="font-size:15px">> Can I use this muxer for my purpose? If yes, any links on how to use it?</span></font></p>
<p style="margin:0px 0px 1em;padding:0px;border:0px;clear:both"><font color="#242729" face="arial,helvetica neue,helvetica,sans-serif"><span style="font-size:15px">> Thanks in advance,</span></font></p>
<p style="margin:0px 0px 1em;padding:0px;border:0px;clear:both"><font color="#242729" face="arial,helvetica neue,helvetica,sans-serif"><span style="font-size:15px">> Malik</span></font></p>
</div>
</div>
</div>
</span>
<div>Malik – Yes, use the adtsenc encoder to add ADTS headers to AAC encoded audio.  (if that’s the output media)</div>
<div>See <a href="https://ffmpeg.org/doxygen/2.6/transcode_aac_8c-example.html">https://ffmpeg.org/doxygen/2.6/transcode_aac_8c-example.html</a></div>
<div>For the output format, you can do avformat_alloc_output_context2(&m_format_context, NULL, "adts", NULL)</div>
</body>
</html>