<div dir="ltr">Dear all,<div><br></div><div>I am new to libav and I am writing a video manipulation software which uses opencv as its heart. What I did is briefly as below:</div><div><br></div><div>1- read the video packet </div><div>2- decode the packet into AVFrame</div><div>3- convert the AVFrame to CV Mat</div><div>4- manipulate the Mat </div><div>5- convert the CV Mat into AVFrame </div><div>6- encode the AVFrame into AVPacket</div><div>7- write the packet </div><div>8- goto 1</div><div><br></div><div>I read dranger tutorial in <a href="http://dranger.com/ffmpeg/tutorial01.html">http://dranger.com/ffmpeg/tutorial01.html</a> and I also used decoding_encoding example. I can read the video, extract video frames and convert them to CV Mat. My problem starts from converting from cv Mat to AVFrame and encode it to AVPacket. </div><div><br></div><div>Would you please help me with this?</div><div><br></div><div>Here is my code :</div><div><br></div>
<pre style="margin-top:0px;margin-bottom:0px"><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(128,128,0)">int</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">main</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,128,0)">int</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">argc</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">char</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">**</span><span style="color:rgb(0,0,0)">argv</span><span style="color:rgb(0,0,0)">)</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)">{</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">AVOutputFormat</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">ofmt</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,128)">NULL</span><span style="color:rgb(0,0,0)">;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><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><span style="color:rgb(0,0,0)">ifmt_ctx</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,128)">NULL</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">ofmt_ctx</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,128)">NULL</span><span style="color:rgb(0,0,0)">;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">AVPacket</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">pkt</span><span style="color:rgb(0,0,0)">;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">AVCodecContext</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">pCodecCtx</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,128)">NULL</span><span style="color:rgb(0,0,0)">;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">AVCodec</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">pCodec</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,128)">NULL</span><span style="color:rgb(0,0,0)">;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">AVFrame</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">pFrame</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,128)">NULL</span><span style="color:rgb(0,0,0)">;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">AVFrame</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">pFrameRGB</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,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(128,128,0)">int</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)">videoStream</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,128)">1</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">;</span><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)">int</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">audioStream</span><span style="color:rgb(0,0,0)">=-</span><span style="color:rgb(0,0,128)">1</span><span style="color:rgb(0,0,0)">;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">int</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">frameFinished</span><span style="color:rgb(0,0,0)">;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">int</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">numBytes</span><span style="color:rgb(0,0,0)">;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">uint8_t</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">buffer</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,128)">NULL</span><span style="color:rgb(0,0,0)">;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">struct</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">SwsContext</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">sws_ctx</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,128)">NULL</span><span style="color:rgb(0,0,0)">;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">FrameManipulation</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">mal_frame</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)">const</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">char</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_filename</span><span style="color:rgb(0,0,0)">,</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_filename</span><span style="color:rgb(0,0,0)">;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">int</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ret</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(0,0,0)">;</span></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(192,192,192)"> </span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">argc</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,128)">3</span><span style="color:rgb(0,0,0)">)</span><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"><span style="color:rgb(192,192,192)"> </span>printf<span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,128,0)">"usage:</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">%s</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">input</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">output\n"</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"API</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">example</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">program</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">to</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">remux</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">a</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">media</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">file</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">with</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">libavformat</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">and</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">libavcodec.\n"</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"The</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">output</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">format</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">is</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">guessed</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">according</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">to</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">the</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">file</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">extension.\n"</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"\n"</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">argv</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">]);</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">return</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">1</span><span style="color:rgb(0,0,0)">;</span></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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">in_filename</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">= arg[1]</span><span style="color:rgb(0,0,0)">;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">out_filename</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">= arg[2]</span><span style="color:rgb(0,0,0)">;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">av_register_all</span><span style="color:rgb(0,0,0)">();</span></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(192,192,192)"> </span><span style="color:rgb(0,0,0)">((</span><span style="color:rgb(0,0,0)">ret</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_open_input</span><span style="color:rgb(0,0,0)">(&</span><span style="color:rgb(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">in_filename</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">))</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,128)">0</span><span style="color:rgb(0,0,0)">)</span><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"><span style="color:rgb(192,192,192)"> </span>fprintf<span style="color:rgb(0,0,0)">(</span>stderr<span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"Could</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">not</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">open</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">input</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">file</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">'%s'"</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">in_filename</span><span style="color:rgb(0,0,0)">);</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">goto</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,0)">end</span><span style="color:rgb(0,0,0)">;</span></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"><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(192,192,192)"> </span><span style="color:rgb(0,0,0)">((</span><span style="color:rgb(0,0,0)">ret</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_find_stream_info</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">))</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,128)">0</span><span style="color:rgb(0,0,0)">)</span><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"><span style="color:rgb(192,192,192)"> </span>fprintf<span style="color:rgb(0,0,0)">(</span>stderr<span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"Failed</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">to</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">retrieve</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">input</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">stream</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">information"</span><span style="color:rgb(0,0,0)">);</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">goto</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,0)">end</span><span style="color:rgb(0,0,0)">;</span></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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">av_dump_format</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">in_filename</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">);</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">avformat_alloc_output_context2</span><span style="color:rgb(0,0,0)">(&</span><span style="color:rgb(0,0,0)">ofmt_ctx</span><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><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><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">out_filename</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(192,192,192)"> </span><span style="color:rgb(0,0,0)">(!</span><span style="color:rgb(0,0,0)">ofmt_ctx</span><span style="color:rgb(0,0,0)">)</span><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"><span style="color:rgb(192,192,192)"> </span>fprintf<span style="color:rgb(0,0,0)">(</span>stderr<span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"Could</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">not</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">create</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">output</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">context\n"</span><span style="color:rgb(0,0,0)">);</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ret</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,128)">AVERROR_UNKNOWN</span><span style="color:rgb(0,0,0)">;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">goto</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,0)">end</span><span style="color:rgb(0,0,0)">;</span></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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ofmt</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)">ofmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">oformat</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)">for</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">i</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,128)">0</span><span style="color:rgb(0,0,0)">;</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">i</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)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">nb_streams</span><span style="color:rgb(0,0,0)">;</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(0,0,0)">++)</span><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"><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(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)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(0,0,0)">];</span></pre><pre style="margin-top:0px;margin-bottom:0px"><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(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><span style="color:rgb(0,0,0)">ofmt_ctx</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">in_stream</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">codec</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)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(0,0,0)">]-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">codec_type</span><span style="color:rgb(0,0,0)">==</span><span style="color:rgb(128,0,128)">AVMEDIA_TYPE_VIDEO</span><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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">videoStream</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,128)">0</span><span style="color:rgb(0,0,0)">)</span><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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">videoStream</span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(0,0,0)">;</span></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"><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)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(0,0,0)">]-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">codec_type</span><span style="color:rgb(0,0,0)">==</span><span style="color:rgb(128,0,128)">AVMEDIA_TYPE_AUDIO</span><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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">audioStream</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,128)">0</span><span style="color:rgb(0,0,0)">)</span><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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">audioStream</span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(0,0,0)">i</span><span style="color:rgb(0,0,0)">;</span></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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">if</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><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"><span style="color:rgb(192,192,192)"> </span>fprintf<span style="color:rgb(0,0,0)">(</span>stderr<span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"Failed</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">allocating</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">output</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">stream\n"</span><span style="color:rgb(0,0,0)">);</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ret</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,128)">AVERROR_UNKNOWN</span><span style="color:rgb(0,0,0)">;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">goto</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,0)">end</span><span style="color:rgb(0,0,0)">;</span></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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ret</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)">avcodec_copy_context</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><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">in_stream</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">);</span></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(192,192,192)"> </span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ret</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,128)">0</span><span style="color:rgb(0,0,0)">)</span><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"><span style="color:rgb(192,192,192)"> </span>fprintf<span style="color:rgb(0,0,0)">(</span>stderr<span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"Failed</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">to</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">copy</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">context</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">from</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">input</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">to</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">output</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">stream</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">codec</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">context\n"</span><span style="color:rgb(0,0,0)">);</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">goto</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,0)">end</span><span style="color:rgb(0,0,0)">;</span></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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">out_stream</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">codec_tag</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,128)">0</span><span style="color:rgb(0,0,0)">;</span></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(192,192,192)"> </span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ofmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">oformat</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">flags</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,128)">AVFMT_GLOBALHEADER</span><span style="color:rgb(0,0,0)">)</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">out_stream</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">flags</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,128)">AV_CODEC_FLAG_GLOBAL_HEADER</span><span style="color:rgb(0,0,0)">;</span></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"> <span style="font-family:arial,sans-serif;color:rgb(0,0,0)">pCodec</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)">avcodec_find_decoder</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)">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)">videoStream</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)">codec</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)">codec_id</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">);</span><br></pre><pre style="margin-top:0px;margin-bottom:0px"> <span style="font-family:arial,sans-serif;color:rgb(0,0,0)">pCodecCtx</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;color:rgb(0,0,0)">avcodec_alloc_context3</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)">pCodec</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(128,128,0)">if</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">avcodec_copy_context</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">pCodecCtx</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">videoStream</span><span style="color:rgb(0,0,0)">]-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">)</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,128)">0</span><span style="color:rgb(0,0,0)">)</span><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"><span style="color:rgb(192,192,192)"> </span>fprintf<span style="color:rgb(0,0,0)">(</span>stderr<span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"Couldn't</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">copy</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">codec</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">context"</span><span style="color:rgb(0,0,0)">);</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">return</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">-</span><span style="color:rgb(0,0,128)">1</span><span style="color:rgb(0,0,0)">;</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">//</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">Error</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">copying</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">codec</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">context</span></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"><br></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">//</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">Open</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">codec</span></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)">avcodec_open2</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">pCodecCtx</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">pCodec</span><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><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">)</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">return</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">-</span><span style="color:rgb(0,0,128)">1</span><span style="color:rgb(0,0,0)">;</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">//</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">Could</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">not</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">open</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">codec</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(0,128,0)">//</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">Allocate</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">video</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">frame</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">pFrame</span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(0,0,0)">av_frame_alloc</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(0,128,0)">//</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">Allocate</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">an</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">AVFrame</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">structure</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">pFrameRGB</span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(0,0,0)">av_frame_alloc</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(0,128,0)">//</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">Determine</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">required</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">buffer</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">size</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">and</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">allocate</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">buffer</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">numBytes</span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(0,0,0)">avpicture_get_size</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,0,128)">AV_PIX_FMT_RGB24</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">videoStream</span><span style="color:rgb(0,0,0)">]-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">width</span><span style="color:rgb(0,0,0)">,</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">videoStream</span><span style="color:rgb(0,0,0)">]-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">height</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(0,0,0)">buffer</span><span style="color:rgb(0,0,0)">=(</span><span style="color:rgb(128,0,128)">uint8_t</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*)</span><span style="color:rgb(0,0,0)">av_malloc</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">numBytes</span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(128,128,0)">sizeof</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,0,128)">uint8_t</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(0,128,0)">//</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">Assign</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">appropriate</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">parts</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">of</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">buffer</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">to</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">image</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">planes</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">in</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">pFrameRGB</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">//</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">Note</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">that</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">pFrameRGB</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">is</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">an</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">AVFrame,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">but</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">AVFrame</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">is</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">a</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">superset</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">//</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">of</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">AVPicture</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">avpicture_fill</span><span style="color:rgb(0,0,0)">((</span><span style="color:rgb(128,0,128)">AVPicture</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*)</span><span style="color:rgb(0,0,0)">pFrameRGB</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">buffer</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_PIX_FMT_BGR24</span><span style="color:rgb(0,0,0)">,</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">videoStream</span><span style="color:rgb(0,0,0)">]-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">width</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">videoStream</span><span style="color:rgb(0,0,0)">]-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">height</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(0,0,0)">av_dump_format</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ofmt_ctx</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">out_filename</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">1</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(192,192,192)"> </span><span style="color:rgb(0,0,0)">(!(</span><span style="color:rgb(0,0,0)">ofmt</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">flags</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,128)">AVFMT_NOFILE</span><span style="color:rgb(0,0,0)">))</span><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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ret</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)">avio_open</span><span style="color:rgb(0,0,0)">(&</span><span style="color:rgb(0,0,0)">ofmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">pb</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">out_filename</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">AVIO_FLAG_WRITE</span><span style="color:rgb(0,0,0)">);</span></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(192,192,192)"> </span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ret</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,128)">0</span><span style="color:rgb(0,0,0)">)</span><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"><span style="color:rgb(192,192,192)"> </span>fprintf<span style="color:rgb(0,0,0)">(</span>stderr<span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"Could</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">not</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">open</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">output</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">file</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">'%s'"</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">out_filename</span><span style="color:rgb(0,0,0)">);</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">goto</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,0)">end</span><span style="color:rgb(0,0,0)">;</span></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"><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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ret</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_write_header</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ofmt_ctx</span><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></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(192,192,192)"> </span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ret</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,128)">0</span><span style="color:rgb(0,0,0)">)</span><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"><span style="color:rgb(192,192,192)"> </span>fprintf<span style="color:rgb(0,0,0)">(</span>stderr<span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"Error</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">occurred</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">when</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">opening</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">output</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">file\n"</span><span style="color:rgb(0,0,0)">);</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">goto</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,0)">end</span><span style="color:rgb(0,0,0)">;</span></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"> <span style="font-family:arial,sans-serif;color:rgb(0,128,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,128,0)">Assign</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,128,0)">appropriate</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,128,0)">parts</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,128,0)">of</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,128,0)">buffer</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,128,0)">to</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,128,0)">image</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,128,0)">planes</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,128,0)">in</span><span style="font-family:arial,sans-serif;color:rgb(192,192,192)"> </span><span style="font-family:arial,sans-serif;color:rgb(0,128,0)">pFrameRGB</span><br></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">//</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">Note</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">that</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">pFrameRGB</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">is</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">an</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">AVFrame,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">but</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">AVFrame</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">is</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">a</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">superset</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">//</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">of</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">AVPicture</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">avpicture_fill</span><span style="color:rgb(0,0,0)">((</span><span style="color:rgb(128,0,128)">AVPicture</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*)</span><span style="color:rgb(0,0,0)">pFrameRGB</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">buffer</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_PIX_FMT_BGR24</span><span style="color:rgb(0,0,0)">,</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">videoStream</span><span style="color:rgb(0,0,0)">]-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">width</span><span style="color:rgb(0,0,0)">,</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">videoStream</span><span style="color:rgb(0,0,0)">]-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">height</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(0,128,0)">//</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">initialize</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">SWS</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">context</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">for</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">software</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">scaling</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">sws_ctx</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)">sws_getContext</span><span style="color:rgb(0,0,0)">(</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">videoStream</span><span style="color:rgb(0,0,0)">]-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">width</span><span style="color:rgb(0,0,0)">,</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">videoStream</span><span style="color:rgb(0,0,0)">]-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">height</span><span style="color:rgb(0,0,0)">,</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">videoStream</span><span style="color:rgb(0,0,0)">]-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">pix_fmt</span><span style="color:rgb(0,0,0)">,</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">videoStream</span><span style="color:rgb(0,0,0)">]-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">width</span><span style="color:rgb(0,0,0)">,</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">videoStream</span><span style="color:rgb(0,0,0)">]-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">height</span><span style="color:rgb(0,0,0)">,</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">AV_PIX_FMT_BGR24</span><span style="color:rgb(0,0,0)">,</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">SWS_BICUBIC</span><span style="color:rgb(0,0,0)">,</span></pre><pre style="margin-top:0px;margin-bottom:0px"><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></pre><pre style="margin-top:0px;margin-bottom:0px"><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></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">NULL</span></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">// Loop through packets</pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">while</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,128)">1</span><span style="color:rgb(0,0,0)">)</span><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"><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><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></pre><pre style="margin-top:0px;margin-bottom:0px"> <span style="font-family:arial,sans-serif;color:rgb(0,0,0)">ret</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;color:rgb(0,0,0)">av_read_frame</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)">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(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)">pkt</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">);</span><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)">pkt</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(128,0,0)">stream_index</span><span style="color:rgb(0,0,0)">==</span><span style="color:rgb(0,0,0)">videoStream</span><span style="color:rgb(0,0,0)">)</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">//</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">Decode</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">video</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">frame</span></pre><pre style="margin-top:0px;margin-bottom:0px"> <span style="font-family:arial,sans-serif;color:rgb(0,0,0)">avcodec_decode_video2</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)">pCodecCtx</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)">pFrame</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)">frameFinished</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)">pkt</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">);</span><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)">frameFinished</span><span style="color:rgb(0,0,0)">)</span><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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">sws_scale</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">sws_ctx</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,0,128)">uint8_t</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">const</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,128,0)">const</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*)</span><span style="color:rgb(0,0,0)">pFrame</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">data</span><span style="color:rgb(0,0,0)">,</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">pFrame</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">linesize</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">pCodecCtx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">height</span><span style="color:rgb(0,0,0)">,</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">pFrameRGB</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">data</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">pFrameRGB</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">linesize</span><span style="color:rgb(0,0,0)">);</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">cv</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(128,0,128)">Mat</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">img</span><span style="color:rgb(0,0,0)">=</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">mal_frame</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(0,0,0)">process</span><span style="color:rgb(0,0,0)">(</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)"> pFrameRGB</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">pFrame</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">width</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,0,0)">pFrame</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">height</span><span style="color:rgb(0,0,0)">);</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)">/* My problem is Here ------------*/</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)"> </span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)"> avpicture_fill</span><span style="color:rgb(0,0,0)">((</span><span style="color:rgb(128,0,128)">AVPicture</span><span style="color:rgb(0,0,0)">*)</span><span style="color:rgb(0,0,0)">pFrameRGB</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)"> img.data</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span></pre><pre style="margin-top:0px;margin-bottom:0px"> PIX_FMT_BGR24<span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)"> outStream</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">width</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)"> outStream</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">codec</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">height</span><span style="color:rgb(0,0,0)">);</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)"> pFrameRGB</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">width</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>ifmt_ctx<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)">videoStream</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)">codec</span>-><span style="font-family:arial,sans-serif;color:rgb(128,0,0)">width</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">;</span><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)">pFrameRGB</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">height</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>ifmt_ctx<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)">videoStream</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)">codec-></span>height<span style="font-family:arial,sans-serif;color:rgb(0,0,0)">;</span><br></pre><pre style="margin-top:0px;margin-bottom:0px"> </pre><pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial,sans-serif;color:rgb(0,0,0)"> avcodec_encode_video2</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">(</span>ifmt_ctx<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)">videoStream</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)">codec</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></pre><pre style="margin-top:0px;margin-bottom:0px"><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)">pkt</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;color:rgb(0,0,0)">pFrameRGB</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;color:rgb(0,0,0)">&</span><span style="font-family:arial,sans-serif">gotPacket</span><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">);</span><br></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial,sans-serif;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)">I get this error</span></pre><pre style="margin-top:0px;margin-bottom:0px"><font color="#000000" face="arial, sans-serif">[swscaler @ 0x14b58a0] bad src image pointers
[swscaler @ 0x14b58a0] bad src image pointers</font><span style="font-family:arial,sans-serif;color:rgb(0,0,0)">
</span></pre><div><span style="color:rgb(0,0,0);font-family:arial,sans-serif">*/</span><br></div><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"><span style="color:rgb(0,0,0)">/* My Problem Ends here ---------- */</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span></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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">if</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ret</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,128)">0</span><span style="color:rgb(0,0,0)">)</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">break</span><span style="color:rgb(0,0,0)">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </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(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">pkt</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(128,0,0)">stream_index</span><span style="color:rgb(0,0,0)">];</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><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)">ofmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">streams</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,0,0)">pkt</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(128,0,0)">stream_index</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(0,128,0)">//log_packet(ifmt_ctx,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">&pkt,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"in");</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">/*</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">copy</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">packet</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">*/</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">pkt</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(128,0,0)">pts</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_rescale_q_rnd</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">pkt</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(128,0,0)">pts</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">in_stream</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">time_base</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">out_stream</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">time_base</span><span style="color:rgb(0,0,0)">,</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">AV_ROUND_NEAR_INF</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(0,0,0)">pkt</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(128,0,0)">dts</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_rescale_q_rnd</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">pkt</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(128,0,0)">dts</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">in_stream</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">time_base</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">out_stream</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">time_base</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_ROUND_NEAR_INF</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">pkt</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(128,0,0)">duration</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_rescale_q</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">pkt</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(128,0,0)">duration</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">in_stream</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">time_base</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">out_stream</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">time_base</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">pkt</span><span style="color:rgb(0,0,0)">.</span><span style="color:rgb(128,0,0)">pos</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)">-</span><span style="color:rgb(0,0,128)">1</span><span style="color:rgb(0,0,0)">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">log_packet</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ofmt_ctx</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">&</span><span style="color:rgb(0,0,0)">pkt</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"out"</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">ret</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_interleaved_write_frame</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ofmt_ctx</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">&</span><span style="color:rgb(0,0,0)">pkt</span><span style="color:rgb(0,0,0)">);</span></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(192,192,192)"> </span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ret</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,128)">0</span><span style="color:rgb(0,0,0)">)</span><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"><span style="color:rgb(192,192,192)"> </span>fprintf<span style="color:rgb(0,0,0)">(</span>stderr<span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"Error</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">muxing</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">packet\n"</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">break</span><span style="color:rgb(0,0,0)">;</span></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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">av_free_packet</span><span style="color:rgb(0,0,0)">(&</span><span style="color:rgb(0,0,0)">pkt</span><span style="color:rgb(0,0,0)">);</span></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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">av_write_trailer</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ofmt_ctx</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(128,0,0)">end</span><span style="color:rgb(0,0,0)">:</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">avformat_close_input</span><span style="color:rgb(0,0,0)">(&</span><span style="color:rgb(0,0,0)">ifmt_ctx</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">/*</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">close</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">output</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">*/</span></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(192,192,192)"> </span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ofmt_ctx</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)">!(</span><span style="color:rgb(0,0,0)">ofmt</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">flags</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,128)">AVFMT_NOFILE</span><span style="color:rgb(0,0,0)">))</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">avio_closep</span><span style="color:rgb(0,0,0)">(&</span><span style="color:rgb(0,0,0)">ofmt_ctx</span><span style="color:rgb(0,0,0)">-></span><span style="color:rgb(128,0,0)">pb</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">avformat_free_context</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ofmt_ctx</span><span style="color:rgb(0,0,0)">);</span></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(192,192,192)"> </span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">ret</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,128)">0</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)">ret</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,128)">AVERROR_EOF</span><span style="color:rgb(0,0,0)">)</span><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"><span style="color:rgb(0,128,0)">//</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">fprintf(stderr,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"Error</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">occurred:</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">%s\n",</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">av_err2str(ret));</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">return</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">1</span><span style="color:rgb(0,0,0)">;</span></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"><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">return</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)">}</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre></pre><div><br clear="all"><div><div class="gmail-m_5237542216664519017gmail_signature"><div dir="ltr"><div dir="ltr">______________________________<wbr>________________________<div><br></div><div>Davood Falahati,</div><div><br></div></div></div></div></div>
</div></div>