简体   繁体   中英

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

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

Another suggestion (it worked just well in my case) is to call with NULL AVPacket pointer:

av_interleaved_write_frame(AVFormatContext*, NULL);

then it flushes whatever stream it has in the buffer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM