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 ioContext->seekable = 0
. To make this work I had to add the "movflags" empty_moov
and frag_keyframe
when writing the header.
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.
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 faststart
flag because this would require output to a seekable file before writing to the socket.
Update: I learned that I can set the duration in AVFormatContext
and I can set nb_frames
and avg_frame_rate
in AVStream
. However, it doesn't solve my problem. When I set the codecContext flag AV_CODEC_FLAG_QSCALE
, VLC seems to be able to estimate the total time. However, seeking still doesn't work.