<div dir="ltr">Dear all,<div><br></div><div>I am using ffmpeg transcoing example. In setting up the output file, I want to copy the DISPLAY_MATRIX side data attached to the video stream. This is what I do:</div><div><br></div><div><font size="1">       <span style="color:rgb(192,192,192)">    </span><span style="color:rgb(128,0,128)">AVStream</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">out_stream</span><span style="color:rgb(0,0,0)">;</span></font></div>

<pre style="margin-top:0px;margin-bottom:0px"><font size="1"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(128,0,128)">AVStream</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">in_stream</span><span style="color:rgb(0,0,0)">;</span></font></pre><pre style="margin-top:0px;margin-bottom:0px"><font size="1"><span style="color:rgb(0,0,0)">    </span>static<span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(128,0,128)">AVFormatContext</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">*</span><span style="font-family:arial,sans-serif">ifmt_ctx</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">;</span></font></pre>

<pre style="margin-top:0px;margin-bottom:0px"><font size="1"><span style="color:rgb(128,128,0)">    static</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">AVFormatContext</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span>ofmt_ctx<span style="color:rgb(0,0,0)">;</span></font></pre><pre style="margin-top:0px;margin-bottom:0px"><font size="1">    .....</font></pre><pre style="margin-top:0px;margin-bottom:0px"><font size="1">    .....</font></pre><pre style="margin-top:0px;margin-bottom:0px"><font size="1">    .....</font></pre><div>
<pre style="margin-top:0px;margin-bottom:0px"><font size="1"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(0,0,0)">out_stream</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">avformat_new_stream</span><span style="color:rgb(0,0,0)">(</span>ofmt_ctx<span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">NULL</span><span style="color:rgb(0,0,0)">);</span></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font size="1"><span style="color:rgb(192,192,192)">    </span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">in_stream</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">=</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif">ifmt_ctx</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">-></span><span style="font-family:arial,sans-serif;color:rgb(128,0,0)">streams</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">[</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">i</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">];</span></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font size="1"><br></font></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="font-size:x-small;color:rgb(192,192,192)">    </span><span style="color:rgb(128,0,128)">uint8_t</span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">resp</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">av_stream_get_side_data</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">in_stream</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">AV_PKT_DATA_DISPLAYMATRIX</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">sd_size</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(128,128,0)">if</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">resp</span><span style="color:rgb(0,0,0)">!=</span><span style="color:rgb(0,0,128)">NULL</span><span style="color:rgb(0,0,0)">){</span></pre>
<pre style="margin-top:0px;margin-bottom:0px">        <span style="font-family:arial,sans-serif;color:rgb(0,0,0)">av_stream_add_side_data</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">(</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">out_stream</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">,</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(128,0,128)">AV_PKT_DATA_DISPLAYMATRIX</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">,</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">resp</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">,</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">*</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">sd_size</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">);</span><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(0,0,0)">}</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><font size="1">    .....</font></pre><pre style="margin-top:0px;margin-bottom:0px"><font size="1">    .....</font></pre><pre style="margin-top:0px;margin-bottom:0px"><font size="1">    ......</font></pre><pre style="margin-top:0px;margin-bottom:0px"><font size="1">    </font><b>avformat_free_context<span style="font-family:arial,sans-serif;color:rgb(0,0,0)">(</span><span style="font-family:arial,sans-serif">ofmt_ctx</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">); //problem happens here</span></b></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial,sans-serif;color:rgb(0,0,0)"><br></span></pre>
<pre style="margin-top:0px;margin-bottom:0px">everything goes well until I want to free ofmt_ctx. I receive the attached error.</pre><pre style="margin-top:0px;margin-bottom:0px">Can you help me what is the problem and how should I resolve it?</pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">Best,</pre><pre style="margin-top:0px;margin-bottom:0px">Davood Falahati</pre></div></div>