<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hello,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I am using the qsv_h264 encoder, and on certain resolutions I get memory leaks.  This issue seems to be the same as
<a href="https://trac.ffmpeg.org/ticket/8445">https://trac.ffmpeg.org/ticket/8445</a>, but that was closed with “I figured it out”.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I create an AVFrame and use av_buffer_create() to wrap an existing buffer.  I provide a custom callback for freeing the data, but this callback is never called, which is were the memory leak is happening.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The leak only happens on certain resolutions, which makes sense stepping through the code.  In libavcodec/qsvenc.c submit_frame(), if ffmpeg makes a copy by calling av_frame_copy() on line 1518, everything is fine.  If ffmpeg doesn’t need
 to copy, and calls av_frame_ref() on line 1524, then we run into the memory leak.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">What I can’t find is where ffmpeg is calling av_frame_unref to remove the reference it added on line 1524.  It seems like this should be happening in clear_unused_frames(), were av_frame_unref() is indeed called, but only for frames with
 format AV_PIX_FMT_QSV.  Removing that check on line 1430 does fix the memory leak.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Where is the AVBufferRef that is created in libavcodec/qsvenc.c submit_frame() on line 1524 freed?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Mark Samuelson<o:p></o:p></p>
</div>
</body>
</html>