<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QtMultimedia. Qt 5.1. QVideoFrame converting in another struct]]></title><description><![CDATA[<p dir="auto">Hi, all.</p>
<p dir="auto">I need to create h264 stream from camera. Unfortunately, QVideoProbe::setSource( some_QMediaRecorder ) always return false (both in Windows and Linux) and I can't get already encoded frames.<br />
I inherit QAbstractVideoSurface, make QCamera::setViewFinder for my class and now I give all QVideoFrame's from camera in YUV420P format. I need to encode its and will use x264. For encoding I should convert QVideoFrame into x264_image_t.</p>
<p dir="auto">@typedef struct<br />
{<br />
int     i_csp;       /* Colorspace <em>/<br />
int     i_plane;     /</em> Number of image planes <em>/<br />
int     i_stride[4]; /</em> Strides for each plane */<br />
uint8_t <em>plane[4];   /</em> Pointers to each plane */<br />
} x264_image_t;@</p>
<p dir="auto">Does the QVideoFrame::bits() method return pointer to plain buffer, contains all plains of picture? How I can convert it? x264 expects YUV420P and I need just copy frame.</p>
]]></description><link>https://forum.qt.io/topic/30539/qtmultimedia-qt-5-1-qvideoframe-converting-in-another-struct</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Nov 2026 02:16:47 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/30539.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 09 Aug 2013 21:13:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QtMultimedia. Qt 5.1. QVideoFrame converting in another struct on Tue, 24 Dec 2013 01:21:38 GMT]]></title><description><![CDATA[<p dir="auto">Thanks dimanx.<br />
QAbstractVideoSurface is the point.</p>
]]></description><link>https://forum.qt.io/post/200952</link><guid isPermaLink="true">https://forum.qt.io/post/200952</guid><dc:creator><![CDATA[jmimi]]></dc:creator><pubDate>Tue, 24 Dec 2013 01:21:38 GMT</pubDate></item><item><title><![CDATA[Reply to QtMultimedia. Qt 5.1. QVideoFrame converting in another struct on Tue, 24 Dec 2013 01:18:48 GMT]]></title><description><![CDATA[<p dir="auto">I create subclass of QAbstractVideoSurface and set it as a viewfinder in QCamera.<br />
MySurface have method present(QVideoFrame) which call H264Encoder::encodeFrame(...).</p>
]]></description><link>https://forum.qt.io/post/200951</link><guid isPermaLink="true">https://forum.qt.io/post/200951</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 24 Dec 2013 01:18:48 GMT</pubDate></item><item><title><![CDATA[Reply to QtMultimedia. Qt 5.1. QVideoFrame converting in another struct on Tue, 24 Dec 2013 00:19:47 GMT]]></title><description><![CDATA[<p dir="auto">Oh, thanks for code.<br />
How you trap frames to ?<br />
@void H264Encoder::encodeFrame(const QVideoFrame&amp; frame)<br />
..@</p>
]]></description><link>https://forum.qt.io/post/200950</link><guid isPermaLink="true">https://forum.qt.io/post/200950</guid><dc:creator><![CDATA[jmimi]]></dc:creator><pubDate>Tue, 24 Dec 2013 00:19:47 GMT</pubDate></item><item><title><![CDATA[Reply to QtMultimedia. Qt 5.1. QVideoFrame converting in another struct on Mon, 23 Dec 2013 23:32:32 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="jmimi" date="1387821006"]Hi<br />
I have the same problem.<br />
Do you find any solution?[/quote]</p>
<p dir="auto">Yes. I use avpicture_fill(...) for copy QVideoFrame into AVPicture and sws_scale(...) for converting this picture into x_264_picture_t with YUV420P colorspace.</p>
<p dir="auto">@void H264Encoder::encodeFrame(const QVideoFrame&amp; frame)<br />
{<br />
if (!frame.isReadable() || !frame.isMapped())<br />
return;<br />
//m_in_pixel_format = avcodec::AV_PIX_FMT_RGB32;<br />
if (m_in_pixel_format == PIX_FMT_NONE)<br />
{<br />
if ( !this-&gt;set_pix_fmt(frame) )<br />
return;<br />
}</p>
<p dir="auto">size_t in_width = frame.width();<br />
size_t in_height = frame.height();</p>
<p dir="auto">if (!m_sws_ctx)<br />
{<br />
m_sws_ctx = sws_getContext(in_width, in_height, m_in_pixel_format,<br />
m_out_width, m_out_height, m_out_pixel_format, SWS_FAST_BILINEAR, NULL, NULL, NULL);<br />
if (!m_sws_ctx)<br />
{<br />
qDebug() &lt;&lt; "libswscale: Error creating sws context!";<br />
return;<br />
}<br />
}</p>
<p dir="auto">//copy frame from QVideoFrame into m_pic_raw<br />
int bytes_copied = avpicture_fill(&amp;m_pic_raw, const_cast&lt;uint8_t*&gt;(frame.bits()),<br />
m_in_pixel_format, in_width, in_height);</p>
<p dir="auto">if (bytes_copied &lt; 0)<br />
{<br />
qDebug() &lt;&lt; "H264Encoder: error calling avpicture_fill(...)!";<br />
return;<br />
}</p>
<p dir="auto">//convert img into m_out_format and save in m_in_pic<br />
int scaled_img_height = sws_scale(m_sws_ctx, m_pic_raw.data, m_pic_raw.linesize, 0, in_height,<br />
m_in_pic-&gt;img.plane, m_in_pic-&gt;img.i_stride);</p>
<p dir="auto">if ( scaled_img_height &lt; 0 || (size_t)scaled_img_height != m_out_height )<br />
{<br />
qDebug() &lt;&lt; "Scaling failed!";<br />
return;<br />
}</p>
<p dir="auto">m_in_pic-&gt;i_pts = m_pts++;</p>
<p dir="auto">int res = x264_encoder_encode(m_encoder, &amp;m_nals, &amp;m_num_nals, m_in_pic, m_out_pic);<br />
if (res  &lt; 0)<br />
{<br />
qDebug() &lt;&lt; "x264_encode error!";<br />
return;<br />
}</p>
<p dir="auto">m_last_frame_sz = res;</p>
<pre><code>    //create frame_t for every NAL unit
</code></pre>
<p dir="auto">std::vector&lt;Frame_t&gt; result;<br />
this-&gt;get_encoded_frame(result);<br />
for (auto i = result.cbegin(); i != result.cend(); i++)<br />
{<br />
SharedEncodedFrame shared_result;<br />
shared_result &lt;&lt; *i;<br />
emit newEncodedFrame(shared_result);<br />
}<br />
}</p>
<p dir="auto">bool H264Encoder::get_encoded_frame( std::vector&lt;Frame_t&gt;&amp; buf )const<br />
{<br />
if (!m_last_frame_sz)<br />
return false;</p>
<p dir="auto">buf.clear();<br />
buf.resize(m_num_nals);</p>
<p dir="auto">for (int i = 0; i &lt; m_num_nals; i++)<br />
{<br />
std::copy((const char*)m_nals[i].p_payload + 4, (const char*)m_nals[i].p_payload +<br />
m_nals[i].i_payload, std::back_inserter(buf[i]));<br />
}</p>
<p dir="auto">return true;<br />
}<br />
@</p>
<p dir="auto">where I have next members:<br />
@x264_param_t* m_params;</p>
<p dir="auto">x264_t* m_encoder;</p>
<p dir="auto">x264_picture_t *m_in_pic, *m_out_pic;</p>
<p dir="auto">PixelFormat m_in_pixel_format;<br />
PixelFormat m_out_pixel_format;</p>
<p dir="auto">size_t m_out_height;<br />
size_t m_out_width;</p>
<p dir="auto">size_t m_fps;</p>
<p dir="auto">//input frame;<br />
AVPicture m_pic_raw;</p>
<p dir="auto">x264_nal_t* m_nals;<br />
int m_num_nals;<br />
size_t m_last_frame_sz;</p>
<p dir="auto">int m_pts;<br />
SwsContext* m_sws_ctx;@</p>
]]></description><link>https://forum.qt.io/post/200949</link><guid isPermaLink="true">https://forum.qt.io/post/200949</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Mon, 23 Dec 2013 23:32:32 GMT</pubDate></item><item><title><![CDATA[Reply to QtMultimedia. Qt 5.1. QVideoFrame converting in another struct on Mon, 23 Dec 2013 17:50:06 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
I have the same problem.<br />
Do you find any solution?</p>
]]></description><link>https://forum.qt.io/post/200948</link><guid isPermaLink="true">https://forum.qt.io/post/200948</guid><dc:creator><![CDATA[jmimi]]></dc:creator><pubDate>Mon, 23 Dec 2013 17:50:06 GMT</pubDate></item></channel></rss>