diff --git a/Core/HW/MediaEngine.cpp b/Core/HW/MediaEngine.cpp index 9028c6dee6..fcb3456ae7 100644 --- a/Core/HW/MediaEngine.cpp +++ b/Core/HW/MediaEngine.cpp @@ -380,6 +380,11 @@ void MediaEngine::closeContext() #endif } m_pCodecCtxs.clear(); + // These are streams allocated from avformat_new_stream. + for (auto it : m_codecsToClose) { + avcodec_close(it); + } + m_codecsToClose.clear(); if (m_pFormatCtx) avformat_close_input(&m_pFormatCtx); sws_freeContext(m_sws_ctx); @@ -439,6 +444,8 @@ bool MediaEngine::addVideoStream(int streamNum, int streamId) { if (streamNum >= m_expectedVideoStreams) { ++m_expectedVideoStreams; } + + m_codecsToClose.push_back(stream->codec); return true; } } diff --git a/Core/HW/MediaEngine.h b/Core/HW/MediaEngine.h index aaef4ae377..e12e17e16a 100644 --- a/Core/HW/MediaEngine.h +++ b/Core/HW/MediaEngine.h @@ -144,4 +144,9 @@ public: // TODO: Very little of this below should be public. // used for audio type int m_audioType; + +private: +#ifdef USE_FFMPEG + std::vector m_codecsToClose; +#endif };