<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi all,</p>
<p><br>
</p>
<p>In my encoder application, I initialize the encoder as follows:</p>
<p><br>
</p>
<p></p>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#800000;"> param</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>x265_param_alloc();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span>x265_param_default(<span style=" color:#800000;">param</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span>x265_param_default_preset(<span style=" color:#800000;">param</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">"ultrafast"</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">"zerolatency"</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">param</span>-><span style=" color:#800000;">fpsNum</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">25</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">param</span>-><span style=" color:#800000;">fpsDenom</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">1</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">param</span>-><span style=" color:#800000;">bRepeatHeaders</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">true</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">param</span>-><span style=" color:#800000;">internalCsp</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">X265_CSP_I420</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">param</span>-><span style=" color:#800000;">sourceWidth</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>aWidth;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">param</span>-><span style=" color:#800000;">sourceHeight</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>aHeight;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">y_size</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">param</span>-><span style=" color:#800000;">sourceWidth</span><span style=" color:#c0c0c0;"> </span>*<span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">param</span>-><span style=" color:#800000;">sourceHeight</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">param</span>-><span style=" color:#800000;">logLevel</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">X265_LOG_FULL</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">encoder</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">x265_encoder_open</span>(<span style=" color:#800000;">param</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">if</span><span style=" color:#c0c0c0;"> </span>(<span style=" color:#000080;">NULL</span><span style=" color:#c0c0c0;"> </span>==<span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">encoder</span>)<span style=" color:#c0c0c0;"> </span>{</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><font color="#800000">print</font><span style="font-style: italic;">Log</span>(<span style=" color:#008000;">"[X265]</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">x265_encoder_open</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">err"</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">return</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span>}</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">param</span>-><span style=" color:#800000;">internalCsp</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">X265_CSP_I420</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">pic_in</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>x265_picture_alloc();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span>x265_picture_init(<span style=" color:#800000;">param</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">pic_in</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">pic_in</span>-><span style=" color:#800000;">planes</span>[<span style=" color:#000080;">0</span>]<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">new</span><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">char</span>[<span style=" color:#000080;">32000000</span>];</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">pic_in</span>-><span style=" color:#800000;">planes</span>[<span style=" color:#000080;">1</span>]<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">new</span><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">char</span>[<span style=" color:#000080;">32000000</span>];</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">pic_in</span>-><span style=" color:#800000;">planes</span>[<span style=" color:#000080;">2</span>]<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">new</span><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">char</span>[<span style=" color:#000080;">32000000</span>];</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">pic_in</span>-><span style=" color:#800000;">stride</span>[<span style=" color:#000080;">0</span>]<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>aWidth;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">pic_in</span>-><span style=" color:#800000;">stride</span>[<span style=" color:#000080;">1</span>]<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>aWidth;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">pic_in</span>-><span style=" color:#800000;">stride</span>[<span style=" color:#000080;">2</span>]<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>aWidth;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">pic_out</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>x265_picture_alloc();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span>x265_picture_init(<span style=" color:#800000;">param</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">pic_out</span>);</pre>
<br>
<p></p>
<p><br>
</p>
<p>Then, I apply the following function for each incoming frame:</p>
<p><br>
</p>
<p></p>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">int</span><span style=" color:#c0c0c0;"> </span>frame_size<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">0</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#800080;">x265_picture</span><span style=" color:#c0c0c0;"> </span>pic_out1;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span>frame_size<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>x265_encoder_encode(<span style=" color:#800000;">encoder</span>,<span style=" color:#c0c0c0;"> </span>&<span style=" color:#800000;">pNals</span>,<span style=" color:#c0c0c0;"> </span>&<span style=" color:#800000;">iNal</span>,<span style=" color:#c0c0c0;"> </span>pic_in,<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">NULL</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">if</span><span style=" color:#c0c0c0;"> </span>(frame_size<span style=" color:#c0c0c0;"> </span><<span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">0</span>)<span style=" color:#c0c0c0;"> </span>{</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><font color="#800000">print</font><span style="font-style: italic;">Log</span>(<span style=" color:#008000;">"[ERROR]</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">H265:</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">x265_encoder_encode</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">failed."</span>);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">return</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span>}</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">if</span><span style=" color:#c0c0c0;"> </span>(frame_size<span style=" color:#c0c0c0;"> </span>><span style=" color:#c0c0c0;"> </span><span style=" color:#000080;">0</span>)<span style=" color:#c0c0c0;"> </span>{</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span>memcpy(aFramebuffer,<span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">pNals</span>[<span style=" color:#000080;">0</span>].<span style=" color:#800000;">payload</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">pNals</span>[<span style=" color:#000080;">0</span>].<span style=" color:#800000;">sizeBytes</span>);<span style=" color:#008000;"></span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span>*aFrameBufferSize<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#800000;">pNals</span>[<span style=" color:#000080;">0</span>].<span style=" color:#800000;">sizeBytes</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;"> </span>}</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#800000;"> dumpfileEncodedData</span>.write((<span style=" color:#808000;">const</span><span style=" color:#c0c0c0;"> </span><span style=" color:#808000;">char</span><span style=" color:#c0c0c0;"> </span>*)aFramebuffer,<span style=" color:#c0c0c0;"> </span>*aFrameBufferSize);</pre><br></pre>
<br>
<p></p>
<p>Just to debug the encoded bitstream, I dump the data into a file </p>
<p><br>
</p>
</div>
</body>
</html>