Search code examples
c++ffmpegh.264mp4flush

How to flush buffer data to disk when using FFmpeg to write a mp4 file?


I am using FFmpeg to write a mp4 file, I grab bitmap images from remote IP camera and encode it by h.264, the media container is mp4 file, no problem to generate the MP4 file if I only record several minutes, the problem is FFmpeg never flushs buffer data to disk when I call method av_interleaved_write_frame(all encoded data in memory, never free them), only when I call method avio_close(oc->pb);, it will flush all encoded data to disk, I tried to call method avcodec_flush_buffers every time after calling av_interleaved_write_frame, but no effect. I am newbie to FFmpeg, if you are familiar with FFmpeg, please help me.

thanks in advance.

Sean


Solution

  • I got the problem, that was caused by I never write audio frame, so if just want to encode several bmps to a video file, please note:

    1) don't add audio stream(add_stream). 2) don't open audio stream(open_audio).

    hope this also helps others.

    Sean