Fix warning about frames left in queue.

Example:
- [libmp3lame @ 0x55b9e7248300] 4 frames left in the queue on closing
This commit is contained in:
Edênis Freindorfer Azevedo 2019-08-07 20:11:45 -03:00 committed by Rafael Kitover
parent f5b19475c9
commit 6b18c1f9b8
2 changed files with 17 additions and 0 deletions

View File

@ -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);
}

View File

@ -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();
};
}