Write seekable AAC audio stream into MP4 file with FFMPEG
<p>I'm trying to write an AAC audio stream into an mp4 file using the FFMPEG libraries. I am using a custom IO context that writes directly to a socket so I have to set <code>ioContext-&gt;seekable = 0</code>. To make this work I had to add the "movflags" <code>empty_moov</code> and <code>frag_keyframe</code> when writing the header.</p>

<p>After writing the output to a file on the other end of the socket, I can play the file in VLC or Windows Media Player. However, seeking to a specific position in the file is not working properly in both players. WMP also does not show the total duration and VLC only flashes it shortly when reaching the end of the audio.</p>

<p>Is there a way to add more metadata when muxing so the players are able to treat the file as if it was not written as a stream? Transfer via the socket  is not interrupted abruptly, so I could write metadata at the end of the file. I also know the total duration in advance, so I could add it to the header of the file if it was possible. I cannot use the <code>faststart</code> flag because this would require output to a seekable file before writing to the socket.</p>

<p><strong>Update:</strong> I learned that I can set the duration in <code>AVFormatContext</code> and I can set <code>nb_frames</code> and <code>avg_frame_rate</code> in <code>AVStream</code>. However, it doesn't solve my problem. When I set the codecContext flag <code>AV_CODEC_FLAG_QSCALE</code>, VLC seems to be able to estimate the total time. However, seeking still doesn't work.</p>