diff --git a/src/common/ffmpeg.cpp b/src/common/ffmpeg.cpp index 608edbb8..97524279 100644 --- a/src/common/ffmpeg.cpp +++ b/src/common/ffmpeg.cpp @@ -450,6 +450,7 @@ void recording::MediaRecorder::Stop() npts = 0; if (oc) { + flush_frames(); // close the output file if (!(fmt->flags & AVFMT_NOFILE)) { @@ -623,3 +624,16 @@ recording::MediaRet recording::MediaRecorder::AddFrame(const uint16_t *aud, int } return MRET_OK; } + +// flush last frames to avoid +// "X frames left in the queue on closing" +void recording::MediaRecorder::flush_frames() +{ + AVPacket pkt; + av_init_packet(&pkt); + pkt.data = NULL; + pkt.size = 0; + // flush last audio frames + while (avcodec_receive_packet(aenc, &pkt) >= 0) + avcodec_send_frame(aenc, NULL); +} diff --git a/src/common/ffmpeg.h b/src/common/ffmpeg.h index cc6094b4..8bb42968 100644 --- a/src/common/ffmpeg.h +++ b/src/common/ffmpeg.h @@ -111,6 +111,9 @@ class MediaRecorder MediaRet setup_video_stream(int width, int height); MediaRet setup_audio_stream(); MediaRet finish_setup(const char *fname); + // flush last frames to avoid + // "X frames left in the queue on closing" + void flush_frames(); }; }