<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Linux Forum &mdash; Video4Linux2. Вывод нескольких буферов.]]></title>
		<link>https://linuxforum.ru/viewtopic.php?id=26489</link>
		<atom:link href="https://linuxforum.ru/extern.php?action=feed&amp;tid=26489&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «Video4Linux2. Вывод нескольких буферов.».]]></description>
		<lastBuildDate>Tue, 12 Feb 2013 04:58:28 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Video4Linux2. Вывод нескольких буферов.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=326780#p326780</link>
			<description><![CDATA[<div class="quotebox"><cite>Fat-Zer пишет:</cite><blockquote><p>если выводишь во фреймбуфер, то там порядок байт BGRA (то же, что и BGR32)</p></blockquote></div><p>Тут все просто, конвертит все внутри себя v4l2 я ему сказал что формат изображение YUV420 на входе и на выходе, а далее он сам разбирается как это ему выводить, все что я сделал это собрал картинку в нужном порядке в буфере выдеовыхода (output_buffers).</p>]]></description>
			<author><![CDATA[null@example.com (mibin)]]></author>
			<pubDate>Tue, 12 Feb 2013 04:58:28 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=326780#p326780</guid>
		</item>
		<item>
			<title><![CDATA[Re: Video4Linux2. Вывод нескольких буферов.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=326779#p326779</link>
			<description><![CDATA[<div class="quotebox"><blockquote><p>а то что всё синее тебя не смущает?</p></blockquote></div><p>Нет, цвет вполне реалистичный, это просто цветопередача на камере мобилки так сработала.</p>]]></description>
			<author><![CDATA[null@example.com (mibin)]]></author>
			<pubDate>Tue, 12 Feb 2013 04:56:54 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=326779#p326779</guid>
		</item>
		<item>
			<title><![CDATA[Re: Video4Linux2. Вывод нескольких буферов.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=326768#p326768</link>
			<description><![CDATA[<div class="quotebox"><cite>mibin пишет:</cite><blockquote><p>Вот конечный результат, который я получил на своем агрегате:</p></blockquote></div><p>а то что всё синее тебя не смущает?<br /></p><div class="quotebox"><cite>Fat-Zer пишет:</cite><blockquote><p>если выводишь во фреймбуфер, то там порядок байт BGRA (то же, что и BGR32)</p></blockquote></div>]]></description>
			<author><![CDATA[null@example.com (Fat-Zer)]]></author>
			<pubDate>Mon, 11 Feb 2013 22:36:26 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=326768#p326768</guid>
		</item>
		<item>
			<title><![CDATA[Re: Video4Linux2. Вывод нескольких буферов.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=326714#p326714</link>
			<description><![CDATA[<p>Наконец-то я смог завершить свою эпопею, прошу прощения, что так долго не отвечал.<br />В общем, данный код выводит 4 изображения&nbsp; на экран, в общем имея 4 разных буфера можно выкидывать изображение 4 различных изображения.</p><p>Запускать надо следующим образом на платах с ARM (ну это в моем случае, в Вашем может потребоваться небольшая доработка, какая зависит от конкретного случая):<br /></p><div class="codebox"><pre><code>./memcpy -ow 640 -oh 480 -ol 0 -ot 0 -f YUV12 </code></pre></div><p>Вот сам код:<br /></p><div class="codebox"><pre><code>/*
 * Copyright 2007-2011 Freescale Semiconductor, Inc. All rights reserved.
 */

/*
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 */

/*
 * @file mxc_v4l2_tvin.c
 *
 * @brief Mxc TVIN For Linux 2 driver test application
 *
 */

#ifdef __cplusplus
extern &quot;C&quot;{
#endif

/*=======================================================================
                                        INCLUDE FILES
=======================================================================*/
/* Standard Include Files */
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;errno.h&gt;

/* Verification Test Environment Include Files */
#include &lt;sys/types.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;sys/ioctl.h&gt;
#include &lt;unistd.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;asm/types.h&gt;
#include &lt;linux/videodev.h&gt;
#include &lt;linux/videodev2.h&gt;
#include &lt;linux/fb.h&gt;
#include &lt;sys/mman.h&gt;
#include &lt;math.h&gt;
#include &lt;string.h&gt;
#include &lt;malloc.h&gt;

#include &lt;linux/mxcfb.h&gt;

#define TFAIL -1
#define TPASS 0

char v4l_capture_dev[100] = &quot;/dev/video0&quot;;
char v4l_output_dev[100] = &quot;/dev/video16&quot;;
int fd_capture_v4l = 0;
int fd_output_v4l = 0;
int g_cap_mode = 0;
int g_input = 1;
int g_fmt = V4L2_PIX_FMT_UYVY;
int g_fmt2 = V4L2_PIX_FMT_YUV420;
int g_rotate = 0;
int g_motion = 0;
int g_tb = 0;
int g_output = 3;
int g_output_num_buffers = 4;
int g_capture_num_buffers = 3;
int g_in_width = 0;
int g_in_height = 0;
int g_display_width = 0;
int g_display_height = 0;
int g_display_top = 0;
int g_display_left = 0;
int g_frame_size;
int g_frame_period = 33333;
v4l2_std_id g_current_std = V4L2_STD_PAL;

struct testbuffer
{
        unsigned char *start;
        size_t offset;
        unsigned int length;
};

struct testbuffer output_buffers[4];
struct testbuffer capture_buffers[3];

int start_capturing(void)
{
        unsigned int i;
        struct v4l2_buffer buf;
        enum v4l2_buf_type type;

        for (i = 0; i &lt; g_capture_num_buffers; i++)
        {
                memset(&amp;buf, 0, sizeof (buf));
                buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                buf.index = i;
                if (ioctl(fd_capture_v4l, VIDIOC_QUERYBUF, &amp;buf) &lt; 0)
                {
                        printf(&quot;VIDIOC_QUERYBUF error\n&quot;);
                        return TFAIL;
                }

                capture_buffers[i].length = buf.length;
                capture_buffers[i].offset = (size_t) buf.m.offset;
                capture_buffers[i].start = mmap (NULL, capture_buffers[i].length,
                    PROT_READ | PROT_WRITE, MAP_SHARED,
                    fd_capture_v4l, capture_buffers[i].offset);
        memset(capture_buffers[i].start, 0xFF, capture_buffers[i].length);
        }

        for (i = 0; i &lt; g_capture_num_buffers; i++)
        {
                memset(&amp;buf, 0, sizeof (buf));
                buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                buf.memory = V4L2_MEMORY_MMAP;
                buf.index = i;
        buf.m.offset = capture_buffers[i].offset;
                if (ioctl (fd_capture_v4l, VIDIOC_QBUF, &amp;buf) &lt; 0) {
                        printf(&quot;VIDIOC_QBUF error\n&quot;);
                        return TFAIL;
                }
        }

        type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        if (ioctl (fd_capture_v4l, VIDIOC_STREAMON, &amp;type) &lt; 0) {
                printf(&quot;VIDIOC_STREAMON error\n&quot;);
                return TFAIL;
        }
        return 0;
}

int prepare_output(void)
{
    int i;
        struct v4l2_buffer output_buf;

        for (i = 0; i &lt; g_output_num_buffers; i++)
        {
                memset(&amp;output_buf, 0, sizeof(output_buf));
                output_buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
                output_buf.memory = V4L2_MEMORY_MMAP;
                output_buf.index = i;
                if (ioctl(fd_output_v4l, VIDIOC_QUERYBUF, &amp;output_buf) &lt; 0)
                {
                        printf(&quot;VIDIOC_QUERYBUF error\n&quot;);
            return TFAIL;
                }

                output_buffers[i].length = output_buf.length;
                output_buffers[i].offset = (size_t) output_buf.m.offset;
                output_buffers[i].start = mmap (NULL, output_buffers[i].length,
                                         PROT_READ | PROT_WRITE, MAP_SHARED,
                                         fd_output_v4l, output_buffers[i].offset);
                if (output_buffers[i].start == NULL) {
                        printf(&quot;v4l2 tvin test: output mmap failed\n&quot;);
            return TFAIL;
                }
        }
    return 0;
}

int v4l_capture_setup(void)
{
    struct v4l2_dbg_chip_ident chip;
    struct v4l2_format fmt;
    struct v4l2_streamparm parm;
        struct v4l2_requestbuffers req;
    v4l2_std_id id;

    if (ioctl(fd_capture_v4l, VIDIOC_DBG_G_CHIP_IDENT, &amp;chip))
    {
                printf(&quot;VIDIOC_DBG_G_CHIP_IDENT failed.\n&quot;);
        close(fd_capture_v4l);
                return TFAIL;
    }
    printf(&quot;TV decoder chip is %s\n&quot;, chip.match.name);

    if (ioctl(fd_capture_v4l, VIDIOC_S_INPUT, &amp;g_input) &lt; 0)
    {
        printf(&quot;VIDIOC_S_INPUT failed\n&quot;);
        close(fd_capture_v4l);
        return TFAIL;
    }

    if (ioctl(fd_capture_v4l, VIDIOC_G_STD, &amp;id) &lt; 0)
    {
        printf(&quot;VIDIOC_G_STD failed\n&quot;);
        close(fd_capture_v4l);
        return TFAIL;
    }
    g_current_std = id;

    if (ioctl(fd_capture_v4l, VIDIOC_S_STD, &amp;id) &lt; 0)
    {
        printf(&quot;VIDIOC_S_STD failed\n&quot;);
        close(fd_capture_v4l);
        return TFAIL;
    }

    parm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    parm.parm.capture.timeperframe.numerator = 1;
    parm.parm.capture.timeperframe.denominator = 0;
    parm.parm.capture.capturemode = 0;
    if (ioctl(fd_capture_v4l, VIDIOC_S_PARM, &amp;parm) &lt; 0)
    {
        printf(&quot;VIDIOC_S_PARM failed\n&quot;);
        close(fd_capture_v4l);
        return TFAIL;
    }

    memset(&amp;fmt, 0, sizeof(fmt));
    fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    fmt.fmt.pix.pixelformat = g_fmt2;
    fmt.fmt.pix.width = 0;
    fmt.fmt.pix.height = 0;
    if (ioctl(fd_capture_v4l, VIDIOC_S_FMT, &amp;fmt) &lt; 0)
    {
        printf(&quot;VIDIOC_S_FMT failed\n&quot;);
        close(fd_capture_v4l);
        return TFAIL;
    }

    if (ioctl(fd_capture_v4l, VIDIOC_G_FMT, &amp;fmt) &lt; 0)
    {
        printf(&quot;VIDIOC_G_FMT failed\n&quot;);
        close(fd_capture_v4l);
        return TFAIL;
    }

    g_in_width = fmt.fmt.pix.width;
    g_in_height = fmt.fmt.pix.height;

        memset(&amp;req, 0, sizeof (req));
        req.count = g_capture_num_buffers;
        req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        req.memory = V4L2_MEMORY_MMAP;
        if (ioctl(fd_capture_v4l, VIDIOC_REQBUFS, &amp;req) &lt; 0)
        {
                printf(&quot;VIDIOC_REQBUFS failed\n&quot;);
        close(fd_capture_v4l);
                return TFAIL;
        }

        return 0;
}

int v4l_output_setup(void)
{
    struct v4l2_control ctrl;
    struct v4l2_format fmt;
    struct v4l2_framebuffer fb;
    struct v4l2_cropcap cropcap;
    struct v4l2_crop crop;
    struct v4l2_requestbuffers buf_req;

        if (ioctl(fd_output_v4l, VIDIOC_S_OUTPUT, &amp;g_output) &lt; 0)
        {
                printf(&quot;set output failed\n&quot;);
                return TFAIL;
        }

        memset(&amp;cropcap, 0, sizeof(cropcap));
        cropcap.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
        if (ioctl(fd_output_v4l, VIDIOC_CROPCAP, &amp;cropcap) &lt; 0)
        {
                printf(&quot;get crop capability failed\n&quot;);
                return TFAIL;
        }

        crop.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
        crop.c.top = g_display_top;
        crop.c.left = g_display_left;
        crop.c.width = g_display_width;
        crop.c.height = g_display_height;
        if (ioctl(fd_output_v4l, VIDIOC_S_CROP, &amp;crop) &lt; 0)
        {
                printf(&quot;set crop failed\n&quot;);
                return TFAIL;
        }

        ctrl.id = V4L2_CID_PRIVATE_BASE;
        ctrl.value = g_rotate;
        if (ioctl(fd_output_v4l, VIDIOC_S_CTRL, &amp;ctrl) &lt; 0)
        {
                printf(&quot;set ctrl failed\n&quot;);
        return TFAIL;
        }

    ctrl.id = V4L2_CID_PRIVATE_BASE + 3;
        ctrl.value = g_motion;
        if (ioctl(fd_output_v4l, VIDIOC_S_CTRL, &amp;ctrl) &lt; 0)
        {
                printf(&quot;set ctrl failed\n&quot;);
        return TFAIL;
        }

    fb.flags = V4L2_FBUF_FLAG_OVERLAY;
    ioctl(fd_output_v4l, VIDIOC_S_FBUF, &amp;fb);

    memset(&amp;fmt, 0, sizeof(fmt));
    fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
    fmt.fmt.pix.width= g_in_width*2;
    fmt.fmt.pix.height= g_in_height*2;
    fmt.fmt.pix.pixelformat = g_fmt2;
    fmt.fmt.pix.bytesperline = g_in_width*2;
    fmt.fmt.pix.priv = 0;
    fmt.fmt.pix.sizeimage = 0;
    if (g_tb)
        fmt.fmt.pix.field = V4L2_FIELD_INTERLACED_TB;
    else
        fmt.fmt.pix.field = V4L2_FIELD_INTERLACED_BT;
        if (ioctl(fd_output_v4l, VIDIOC_S_FMT, &amp;fmt) &lt; 0)
        {
                printf(&quot;set format failed\n&quot;);
                return TFAIL;
        }

        if (ioctl(fd_output_v4l, VIDIOC_G_FMT, &amp;fmt) &lt; 0)
        {
                printf(&quot;get format failed\n&quot;);
                return TFAIL;
        }
        g_frame_size = fmt.fmt.pix.sizeimage;

        memset(&amp;buf_req, 0, sizeof(buf_req));
        buf_req.count = g_output_num_buffers;
        buf_req.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
        buf_req.memory = V4L2_MEMORY_MMAP;
        if (ioctl(fd_output_v4l, VIDIOC_REQBUFS, &amp;buf_req) &lt; 0)
        {
                printf(&quot;request buffers failed\n&quot;);
                return TFAIL;
        }

    return 0;
}

int
mxc_v4l_tvin_test(void)
{
        struct v4l2_buffer capture_buf, output_buf;
    v4l2_std_id id;
        int i, j;
    enum v4l2_buf_type type;
        int total_time;
        struct timeval tv_start, tv_current;

    if (prepare_output() &lt; 0)
    {
        printf(&quot;prepare_output failed\n&quot;);
        return TFAIL;
    }

    if (start_capturing() &lt; 0)
    {
        printf(&quot;start_capturing failed\n&quot;);
        return TFAIL;
    }

    gettimeofday(&amp;tv_start, 0);
    printf(&quot;start time = %d s, %d us\n&quot;, tv_start.tv_sec, tv_start.tv_usec);

    for (i = 0; ; i++) {
begin:
        if (ioctl(fd_capture_v4l, VIDIOC_G_STD, &amp;id)) {
                        printf(&quot;VIDIOC_G_STD failed.\n&quot;);
            return TFAIL;
        }

        if (id == g_current_std)
            goto next;
        else if (id == V4L2_STD_PAL || id == V4L2_STD_NTSC) {
            type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
            ioctl(fd_output_v4l, VIDIOC_STREAMOFF, &amp;type);

            type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
            ioctl(fd_capture_v4l, VIDIOC_STREAMOFF, &amp;type);

            for (j = 0; j &lt; g_output_num_buffers; j++)
            {
                munmap(output_buffers[j].start, output_buffers[j].length);
            }
            for (j = 0; j &lt; g_capture_num_buffers; j++)
            {
                munmap(capture_buffers[j].start, capture_buffers[j].length);
            }

            if (v4l_capture_setup() &lt; 0) {
                printf(&quot;Setup v4l capture failed.\n&quot;);
                return TFAIL;
            }

            if (v4l_output_setup() &lt; 0) {
                printf(&quot;Setup v4l output failed.\n&quot;);
                return TFAIL;
            }

            if (prepare_output() &lt; 0)
            {
                printf(&quot;prepare_output failed\n&quot;);
                return TFAIL;
            }

            if (start_capturing() &lt; 0)
            {
                printf(&quot;start_capturing failed\n&quot;);
                return TFAIL;
            }
            i = 0;
            printf(&quot;TV standard changed\n&quot;);
        } else {
            sleep(1);
            /* Try again */
            if (ioctl(fd_capture_v4l, VIDIOC_G_STD, &amp;id)) {
                printf(&quot;VIDIOC_G_STD failed.\n&quot;);
                return TFAIL;
            }

            if (id != V4L2_STD_ALL)
                goto begin;

            printf(&quot;Cannot detect TV standard\n&quot;);
            return 0;
        }
next:
                memset(&amp;capture_buf, 0, sizeof(capture_buf));
                capture_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                capture_buf.memory = V4L2_MEMORY_MMAP;
                if (ioctl(fd_capture_v4l, VIDIOC_DQBUF, &amp;capture_buf) &lt; 0)    {
                        printf(&quot;VIDIOC_DQBUF failed.\n&quot;);
            return TFAIL;
                }

                memset(&amp;output_buf, 0, sizeof(output_buf));
                output_buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
                output_buf.memory = V4L2_MEMORY_MMAP;
                if (i &lt; g_output_num_buffers) {
                        output_buf.index = i;
                        if (ioctl(fd_output_v4l, VIDIOC_QUERYBUF, &amp;output_buf) &lt; 0)
                        {
                                printf(&quot;VIDIOC_QUERYBUF failed\n&quot;);
                return TFAIL;
                        }
                } else {
                        output_buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
                        output_buf.memory = V4L2_MEMORY_MMAP;
                        if (ioctl(fd_output_v4l, VIDIOC_DQBUF, &amp;output_buf) &lt; 0)
                        {
                                printf(&quot;VIDIOC_DQBUF failed\n&quot;);
                return TFAIL;
                        }
                }
        printf(&quot;Prepare copy buf.\n&quot;);

        memset(output_buffers[output_buf.index].start, 0, sizeof(output_buffers[output_buf.index].length));
        int p;
        int k = 0;

        for (p=0; p&lt;g_in_height; p++) {
            memcpy(output_buffers[output_buf.index].start + k*g_in_width,              capture_buffers[capture_buf.index].start + p*g_in_width, g_in_width);
            memcpy(output_buffers[output_buf.index].start + k*g_in_width + g_in_width, capture_buffers[capture_buf.index].start + p*g_in_width, g_in_width);

            memcpy(output_buffers[output_buf.index].start + k*g_in_width              + 2*g_in_width*g_in_height,  capture_buffers[capture_buf.index].start + p*g_in_width, g_in_width);
            memcpy(output_buffers[output_buf.index].start + k*g_in_width + g_in_width + 2*g_in_width*g_in_height,  capture_buffers[capture_buf.index].start + p*g_in_width, g_in_width);
            k+=2;
        }

        for (p=0; p&lt;g_in_height/2; p++) {
            memcpy(output_buffers[output_buf.index].start + 4*g_in_width*g_in_height + k*(g_in_width/2),                capture_buffers[capture_buf.index].start + (g_in_width*g_in_height + p*(g_in_width/2)), g_in_width/2);
            memcpy(output_buffers[output_buf.index].start + 4*g_in_width*g_in_height + k*(g_in_width/2) + g_in_width/2, capture_buffers[capture_buf.index].start + (g_in_width*g_in_height + p*(g_in_width/2)), g_in_width/2);

            memcpy(output_buffers[output_buf.index].start + 4*g_in_width*g_in_height + k*(g_in_width/2) + (g_in_width*g_in_height)/2,                capture_buffers[capture_buf.index].start + (g_in_width*g_in_height + p*(g_in_width/2)), g_in_width/2);
            memcpy(output_buffers[output_buf.index].start + 4*g_in_width*g_in_height + k*(g_in_width/2) + g_in_width/2 + (g_in_width*g_in_height)/2, capture_buffers[capture_buf.index].start + (g_in_width*g_in_height + p*(g_in_width/2)), g_in_width/2);

            k+=2;
        }
        k = 0;
        for (p=g_in_height/2; p&lt;g_in_height; p++) {
            memcpy(output_buffers[output_buf.index].start + 4*g_in_width*g_in_height + k*(g_in_width/2),                capture_buffers[capture_buf.index].start + (g_in_width*g_in_height + p*(g_in_width/2)), g_in_width/2);
            memcpy(output_buffers[output_buf.index].start + 4*g_in_width*g_in_height + k*(g_in_width/2) + g_in_width/2, capture_buffers[capture_buf.index].start + (g_in_width*g_in_height + p*(g_in_width/2)), g_in_width/2);

            memcpy(output_buffers[output_buf.index].start + 4*g_in_width*g_in_height + k*(g_in_width/2) + (g_in_width*g_in_height)/2,                capture_buffers[capture_buf.index].start + (g_in_width*g_in_height + p*(g_in_width/2)), g_in_width/2);
            memcpy(output_buffers[output_buf.index].start + 4*g_in_width*g_in_height + k*(g_in_width/2) + g_in_width/2 + (g_in_width*g_in_height)/2, capture_buffers[capture_buf.index].start + (g_in_width*g_in_height + p*(g_in_width/2)), g_in_width/2);

            k+=2;
        }

        if (ioctl(fd_capture_v4l, VIDIOC_QBUF, &amp;capture_buf) &lt; 0) {
            printf(&quot;VIDIOC_QBUF failed\n&quot;);
            return TFAIL;
        }

        output_buf.timestamp.tv_sec = tv_start.tv_sec;
        output_buf.timestamp.tv_usec = tv_start.tv_usec + (g_frame_period * i);
                if (ioctl(fd_output_v4l, VIDIOC_QBUF, &amp;output_buf) &lt; 0)
                {
                        printf(&quot;VIDIOC_QBUF failed\n&quot;);
            return TFAIL;
                }

                if (i == 1) {
                    type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
                    if (ioctl(fd_output_v4l, VIDIOC_STREAMON, &amp;type) &lt; 0) {
                        printf(&quot;Could not start stream\n&quot;);
                        return TFAIL;
                    }
                }
    }

        gettimeofday(&amp;tv_current, 0);
        total_time = (tv_current.tv_sec - tv_start.tv_sec) * 1000000L;
        total_time += tv_current.tv_usec - tv_start.tv_usec;
        printf(&quot;total time for %u frames = %u us =  %lld fps\n&quot;, i, total_time, (i * 1000000ULL) / total_time);

    return 0;
}

int process_cmdline(int argc, char **argv)
{
        int i;

        for (i = 1; i &lt; argc; i++) {
        if (strcmp(argv[i], &quot;-ow&quot;) == 0) {
            g_display_width = atoi(argv[++i]);
        }
        else if (strcmp(argv[i], &quot;-oh&quot;) == 0) {
            g_display_height = atoi(argv[++i]);
        }
        else if (strcmp(argv[i], &quot;-ot&quot;) == 0) {
            g_display_top = atoi(argv[++i]);
        }
        else if (strcmp(argv[i], &quot;-ol&quot;) == 0) {
            g_display_left = atoi(argv[++i]);
        }
                else if (strcmp(argv[i], &quot;-r&quot;) == 0) {
                        g_rotate = atoi(argv[++i]);
                }
                else if (strcmp(argv[i], &quot;-f&quot;) == 0) {
                        i++;
                        g_fmt = v4l2_fourcc(argv[i][0], argv[i][1],argv[i][2],argv[i][3]);

            if ((g_fmt != V4L2_PIX_FMT_NV12) &amp;&amp;
                (g_fmt != V4L2_PIX_FMT_UYVY) &amp;&amp;
                (g_fmt != V4L2_PIX_FMT_YUYV) &amp;&amp;
                            (g_fmt != V4L2_PIX_FMT_YUV420))
                        {
                printf(&quot;Default format is used: UYVY\n&quot;);
                        }
                }
                else if (strcmp(argv[i], &quot;-m&quot;) == 0) {
                        g_motion = atoi(argv[++i]);
                }
                else if (strcmp(argv[i], &quot;-tb&quot;) == 0) {
                        g_tb = 1;
                }
                else if (strcmp(argv[i], &quot;-help&quot;) == 0) {
                        printf(&quot;MXC Video4Linux TVin Test\n\n&quot; \
                   &quot;Syntax: mxc_v4l2_tvin.out\n&quot; \
                   &quot; -ow &lt;capture display width&gt;\n&quot; \
                   &quot; -oh &lt;capture display height&gt;\n&quot; \
                   &quot; -ot &lt;display top&gt;\n&quot; \
                   &quot; -ol &lt;display left&gt;\n&quot; \
                               &quot; -r &lt;rotation&gt; -c &lt;capture counter&gt; \n&quot;
                   &quot; -m &lt;motion&gt; 0:medium 1:low 2:high, 0-default\n&quot;
                   &quot; -tb top field first, bottom field first-default\n&quot;
                   &quot; -f &lt;format, only YU12, YUYV, UYVY and NV12 are supported&gt; \n&quot;);
                        return TFAIL;
               }
        }

        if ((g_display_width == 0) || (g_display_height == 0)) {
        printf(&quot;Zero display width or height\n&quot;);
                return TFAIL;
    }

        return 0;
}

int
main(int argc, char **argv)
{
        char fb_device[100] = &quot;/dev/fb0&quot;;
        int fd_fb = 0, i;
        struct mxcfb_gbl_alpha alpha;
    enum v4l2_buf_type type;

        if (process_cmdline(argc, argv) &lt; 0) {
                return TFAIL;
        }

        if ((fd_capture_v4l = open(v4l_capture_dev, O_RDWR, 0)) &lt; 0)
        {
                printf(&quot;Unable to open %s\n&quot;, v4l_capture_dev);
                return TFAIL;
        }

    if ((fd_output_v4l = open(v4l_output_dev, O_RDWR, 0)) &lt; 0)
    {
        printf(&quot;Unable to open %s\n&quot;, v4l_output_dev);
        return TFAIL;
    }

        if (v4l_capture_setup() &lt; 0) {
                printf(&quot;Setup v4l capture failed.\n&quot;);
                return TFAIL;
    }

        if (v4l_output_setup() &lt; 0) {
                printf(&quot;Setup v4l output failed.\n&quot;);
        close(fd_capture_v4l);
                return TFAIL;
    }

        if ((fd_fb = open(fb_device, O_RDWR )) &lt; 0)    {
        printf(&quot;Unable to open frame buffer\n&quot;);
        close(fd_capture_v4l);
        close(fd_output_v4l);
                return TFAIL;
        }

        /* Overlay setting */
        alpha.alpha = 0;
    alpha.enable = 1;
    if (ioctl(fd_fb, MXCFB_SET_GBL_ALPHA, &amp;alpha) &lt; 0) {
        printf(&quot;Set global alpha failed\n&quot;);
        close(fd_fb);
        close(fd_capture_v4l);
        close(fd_output_v4l);
        return TFAIL;
    }

    mxc_v4l_tvin_test();

        type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
        ioctl(fd_output_v4l, VIDIOC_STREAMOFF, &amp;type);

        type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        ioctl(fd_capture_v4l, VIDIOC_STREAMOFF, &amp;type);

        for (i = 0; i &lt; g_output_num_buffers; i++)
        {
                munmap(output_buffers[i].start, output_buffers[i].length);
        }
        for (i = 0; i &lt; g_capture_num_buffers; i++)
        {
                munmap(capture_buffers[i].start, capture_buffers[i].length);
        }

    close(fd_capture_v4l);
    close(fd_output_v4l);
    close(fd_fb);
    return 0;
}</code></pre></div><p>В общем-то все просто, буфер видевыхода больше в 4 раза буфера видеовхода что и позволило запихнуть картинку 4 раза в него.</p><p>Вот ссылка на формат, там его описание и как именно хранятся данные в нем:<br /><a href="http://linuxtv.org/downloads/v4l-dvb-apis/re23.html">http://linuxtv.org/downloads/v4l-dvb-apis/re23.html</a></p><p>Вот конечный результат, который я получил на своем агрегате:<br /><span class="postimg"><img src="http://s019.radikal.ru/i633/1302/43/9699fa476c94.jpg" alt="http://s019.radikal.ru/i633/1302/43/9699fa476c94.jpg" /></span></p><p>К сожаления, на этом приключения не заканчиваются, я чуток позже я создам новый топик по доработке драйвера устройства, надеюсь на такую же активную поддержку, отныне постараюсь и сам внести свой вклад в развитие нации на форуме... ВСЕМ ОГРОМНОЕ СПАСИБО!!!</p>]]></description>
			<author><![CDATA[null@example.com (mibin)]]></author>
			<pubDate>Mon, 11 Feb 2013 17:29:58 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=326714#p326714</guid>
		</item>
		<item>
			<title><![CDATA[Re: Video4Linux2. Вывод нескольких буферов.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=325700#p325700</link>
			<description><![CDATA[<div class="quotebox"><cite>mibin пишет:</cite><blockquote><p>1 - Драйвер етить его поддерживает формат RGB32, RGB24 (а так же их синонимы BGR)и еще какой-то RGB из всего перечисленного списка в документации к v4l2. Более того он не просто поддерживает ОН! картинку выводит ровно прям именно так как надо (правда только с форматом RGB32), одна засада - стоит какая-то голубая дымка, ничего похоже не наблюдается при использовании форматов YUV.</p></blockquote></div><p>если выводишь во фреймбуфер, то там порядок байт BGRA (то же, что и BGR32)<br /></p><div class="quotebox"><cite>mibin пишет:</cite><blockquote><p>2 - Мой мозг и я решительно задолбались кодить формат UYVY, поэтому я стал использовать для захвата изображения форма YUV420</p></blockquote></div><p>вот зачем изобретать велосипед... есть же готовый код в исходниках libv4l...</p>]]></description>
			<author><![CDATA[null@example.com (Fat-Zer)]]></author>
			<pubDate>Wed, 06 Feb 2013 17:28:14 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=325700#p325700</guid>
		</item>
		<item>
			<title><![CDATA[Re: Video4Linux2. Вывод нескольких буферов.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=325578#p325578</link>
			<description><![CDATA[<p>Достаточно интересный пример.<br />Попробую разобраться в нем. С ничем похожим я пока в инете не встречался, когда искал доку и примеры по v4l2. Хотя может у меня интернет особенный <img src="https://linuxforum.ru/img/smilies/ab.gif" alt="ab" /></p><p>Однако одна бессонная ночь дала результаты. Есть две новости:<br />1 - Драйвер етить его поддерживает формат RGB32, RGB24 (а так же их синонимы BGR)и еще какой-то RGB из всего перечисленного списка в документации к v4l2. Более того он не просто поддерживает ОН! картинку выводит ровно прям именно так как надо (правда только с форматом RGB32), одна засада - стоит какая-то голубая дымка, ничего похоже не наблюдается при использовании форматов YUV.<br />2 - Мой мозг и я решительно задолбались кодить формат UYVY, поэтому я стал использовать для захвата изображения форма YUV420 и конвертил его в RGB следующим кодом:<br /></p><div class="codebox"><pre><code>char clamp (int x) {
    if (x&gt;255) return 255;
    if (x&lt;0) return 0;
    return x;
}

void showFrame(const void *p, size_t length)
{
    printf (&quot;show frame called\n&quot;);
       
        // -------- working with display --------------------

    printf (&quot;image received, length=%d\n&quot;, length);
    char s[4096];  
    sprintf (s,&quot;&quot;);

    printf (&quot;now displaying...\n&quot;);
       
   
    int width=g_in_width;
    int height=g_in_heigth;
    
    long size = width*height;
 
// pixel format = 24bit
    char i420[length];
 
    typedef struct {
            char y, u, v;
            } Tyuv ;
            
    typedef struct  {
            char r;
            char g;
            char b;
            }  Trgb;
            
    Tyuv yuv[size];
    Trgb rgb[size];  
    printf (&quot;copying buffer to i420 array\n&quot;);
   int i;
 
    for(i = 0; i &lt; length; i++ ) {
        i420[i] = *(char *)p++;
    }
    printf (&quot;copying Y\n&quot;);
 
    for(i = 0; i &lt; width*height; i++ ) {
        yuv[i].y = i420[i];
    }
    
    int Counter = 0;
 
    printf (&quot;copying U and V\n&quot;);
    for(i = 0; i &lt; width*height/4; i++ )
    {
       yuv[Counter].u                  =
       yuv[Counter + 1].u              =
       yuv[Counter + width].u     =
       yuv[Counter + width + 1].u = i420[width*height + i];
 
       yuv[Counter].v                  =
       yuv[Counter + 1].v              =
       yuv[Counter + width].v     =
       yuv[Counter + width + 1].v = i420[width*height + i + width*height/4];
 
       Counter += 2;
       if( Counter%width == 0 )
           if( (Counter/width)%2 != 0 )
                Counter += width;
  }
 

    printf (&quot;converting yuv to rgb\n&quot;);
 
    for( i = 0; i &lt; size; i++ ) {
        int C,D,E;
        int Y= yuv[i].y;
        int U= yuv[i].u;  
        int V= yuv[i].v;  
        C = Y - 16;
        D = U - 128;
        E = V - 128;
   
 
       char R = clamp((int) ( 298 * C + 409 * E + 128) &gt;&gt; 8);
       char G = clamp((int) ( 298 * C - 100 * D - 208 * E + 128) &gt;&gt; 8);
       char B = clamp((int) ( 298 * C + 516 * D + 128) &gt;&gt; 8);        
       rgb[i].r = R;
       rgb[i].g = G;
       rgb[i].b = B;
    }
    int c=0;
    int x,y;
    printf (&quot;displaying rgb to screen\n&quot;);
         
    int screenwidth=800;
    int screenheight = 480;
 
    for( y = 0; y &lt; screenheight; y++ )
    {      
        for(x = 0; x &lt; screenwidth; x++)
        {
            if ( (x&lt;width) &amp;&amp; (y&lt;height) ) {
                    ((__u8*)fb)[c++] = rgb[y*width + x].b;       // Blue
                    ((__u8*)fb)[c++] = rgb[y*width + x].g;       // Green
                    ((__u8*)fb)[c++] = rgb[y*width + x].r;       // Red
            }
            else c+=3;
        }
    }  
    return ;
}</code></pre></div><p>код этот принадлежит не мне и его еще стоит оптимизировать, но как видно формат YUV420 гораздо проще поддается обработке.</p><p>Вроде бы получил даже картинку...что в итоге получилось выложу вечером, следующий этап это вывод двух картинок, что на самом деле с таким кодом не должно представлять большого труда, ну а потом попробую освоить функцию конвертации форматов от v4l2.</p>]]></description>
			<author><![CDATA[null@example.com (mibin)]]></author>
			<pubDate>Wed, 06 Feb 2013 05:31:29 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=325578#p325578</guid>
		</item>
		<item>
			<title><![CDATA[Re: Video4Linux2. Вывод нескольких буферов.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=325567#p325567</link>
			<description><![CDATA[<div class="codebox"><pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;errno.h&gt;
#include &lt;string.h&gt;
#include &lt;stdint.h&gt;
#include &lt;malloc.h&gt;

#include &lt;sys/types.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;sys/mman.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;sys/ioctl.h&gt;
#include &lt;unistd.h&gt;

#include &lt;linux/videodev2.h&gt;
#include &lt;linux/fb.h&gt;
#include &lt;libv4l2.h&gt;

void fprint_fb_screeninfo(FILE* fs, struct fb_fix_screeninfo *si) {
    fprintf(fs, &quot;id:            %s  \n&quot;, si-&gt;id);
    fprintf(fs, &quot;smem_start:    %p  \n&quot;, (void*)si-&gt;smem_start);
    fprintf(fs, &quot;smem_len:      %u  \n&quot;, si-&gt;smem_len);
    fprintf(fs, &quot;type:          %#0x\n&quot;, si-&gt;type);
    fprintf(fs, &quot;type_aux:      %#0x\n&quot;, si-&gt;type_aux);
    fprintf(fs, &quot;visual:        %#0x\n&quot;, si-&gt;visual);
    fprintf(fs, &quot;xpanstep:      %u  \n&quot;, si-&gt;xpanstep);
    fprintf(fs, &quot;ypanstep:      %u  \n&quot;, si-&gt;ypanstep);
    fprintf(fs, &quot;ywrapstep:     %u  \n&quot;, si-&gt;ywrapstep);
    fprintf(fs, &quot;line_length:   %u  \n&quot;, si-&gt;line_length);
    fprintf(fs, &quot;mmio_start:    %p  \n&quot;, (void*)si-&gt;mmio_start);
    fprintf(fs, &quot;mmio_len:      %u  \n&quot;, si-&gt;mmio_len);
    fprintf(fs, &quot;accel:         %u  \n&quot;, si-&gt;accel);
    fprintf(fs, &quot;capabilities:  %#0x\n&quot;, si-&gt;capabilities);
}

#define CASE_V4L2_FORMAT_TYPE_STR(type_str,type) case type: (type_str)=#type
#define UNSUPPORTED_CASE_V4L2_FORMAT_TYPE_STR(fs, type) case type: \
    fprintf(fs, &quot;type: %s \nUNSUPPORTED\n&quot;, #type); \
    break;

void fprint_v4l2_format(FILE* fs, struct v4l2_format *fmt) {
    const char* type_str=&quot;&quot;;

    switch(fmt-&gt;type) {
    CASE_V4L2_FORMAT_TYPE_STR(type_str, V4L2_BUF_TYPE_VIDEO_CAPTURE      );
        fprintf(fs, &quot;type:          %s\n&quot;, type_str);
        fprintf(fs, &quot;width:         %u\n&quot;, fmt-&gt;fmt.pix.width);
        fprintf(fs, &quot;height:        %u\n&quot;, fmt-&gt;fmt.pix.height);
        fprintf(fs, &quot;pixelformat:   %#0x(%c%c%c%c)\n&quot;, fmt-&gt;fmt.pix.pixelformat, 
                (fmt-&gt;fmt.pix.pixelformat &gt;&gt;  0) &amp; 0xFF,
                (fmt-&gt;fmt.pix.pixelformat &gt;&gt;  8) &amp; 0xFF,
                (fmt-&gt;fmt.pix.pixelformat &gt;&gt; 16) &amp; 0xFF,
                (fmt-&gt;fmt.pix.pixelformat &gt;&gt; 24) &amp; 0xFF);
        fprintf(fs, &quot;field:         %u\n&quot;, fmt-&gt;fmt.pix.field);
        fprintf(fs, &quot;bytesperline:  %u\n&quot;, fmt-&gt;fmt.pix.bytesperline);
        fprintf(fs, &quot;sizeimage:     %u\n&quot;, fmt-&gt;fmt.pix.sizeimage);
        fprintf(fs, &quot;colorspace:    %u\n&quot;, fmt-&gt;fmt.pix.colorspace);
        break;
    UNSUPPORTED_CASE_V4L2_FORMAT_TYPE_STR(fs, V4L2_BUF_TYPE_VIDEO_OUTPUT       );
    UNSUPPORTED_CASE_V4L2_FORMAT_TYPE_STR(fs, V4L2_BUF_TYPE_VIDEO_OVERLAY      );
    UNSUPPORTED_CASE_V4L2_FORMAT_TYPE_STR(fs, V4L2_BUF_TYPE_VBI_CAPTURE        );
    UNSUPPORTED_CASE_V4L2_FORMAT_TYPE_STR(fs, V4L2_BUF_TYPE_VBI_OUTPUT         );
    UNSUPPORTED_CASE_V4L2_FORMAT_TYPE_STR(fs, V4L2_BUF_TYPE_SLICED_VBI_CAPTURE );
    UNSUPPORTED_CASE_V4L2_FORMAT_TYPE_STR(fs, V4L2_BUF_TYPE_SLICED_VBI_OUTPUT  );
    UNSUPPORTED_CASE_V4L2_FORMAT_TYPE_STR(fs, V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY );
    UNSUPPORTED_CASE_V4L2_FORMAT_TYPE_STR(fs, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE );
    UNSUPPORTED_CASE_V4L2_FORMAT_TYPE_STR(fs, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE  );
    UNSUPPORTED_CASE_V4L2_FORMAT_TYPE_STR(fs, V4L2_BUF_TYPE_PRIVATE              );    
    }
}

int main(int argc, char** argv) {
    int rc;
    int i,j;

    char *dev_name;
    int dev_fd;
    uint8_t* dev_buf;
    struct v4l2_format fmt;

    const char *fb_name=&quot;/dev/fb0&quot;;
    int fb_fd;
    struct fb_fix_screeninfo fb_si;
    uint8_t* fb_buf;


    if(argc != 2) {
        fprintf(stderr, &quot;Usage: %s /dev/videoX\n&quot;, argv[0]);
        return EXIT_FAILURE;
    }
    
    dev_name = argv[1];

    dev_fd = v4l2_open(dev_name, O_RDWR);
    if( dev_fd == -1 ) {
        fprintf(stderr, &quot;open %s failed: %s\n&quot;, dev_name, strerror(errno));
        return EXIT_FAILURE;
    }

    fb_fd = open(fb_name, O_RDWR);
    if( fb_fd == -1 ) {
        fprintf(stderr, &quot;open %s failed: %s\n&quot;, fb_name, strerror(errno));
        return EXIT_FAILURE;
    }

    memset( &amp;fb_si, 0, sizeof(fb_si));
    rc = ioctl( fb_fd, FBIOGET_FSCREENINFO, &amp;fb_si);
    if(rc &lt; 0) {
        fprintf(stderr, &quot;FBIOGET_FSCREENINFO failed: %s\n&quot;, strerror(errno));
        return EXIT_FAILURE;
    }

#if 0 // print framebuffer info
    printf(&quot;===== %s ======\n&quot;, fb_name);
    fprint_fb_screeninfo(stdout, &amp;fb_si);
#endif // 0 

    fb_buf=mmap(0, fb_si.smem_len, PROT_WRITE|PROT_READ,
                       MAP_SHARED, fb_fd, 0);
    if(fb_buf == (void*) -1) {
        fprintf(stderr, &quot;mmap %d(%s) failed: %s\n&quot;, fb_fd, fb_name, strerror(errno));
        return EXIT_FAILURE;
    }

#if 0 // try to draw garbage on framebuffer
    int i=0,j=0;
    for(i=0; i&lt;100*4;i++) {
        for(j=0; j&lt;100;j++) {
            fb_buf[i+j*fb_si.line_length]=rand() % 256;
        }
    }
    
    sleep(10);
#endif

#if 0 // print current v4l2 format
    memset(&amp;fmt, 0, sizeof(struct v4l2_format));
    fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    rc = v4l2_ioctl(dev_fd, VIDIOC_G_FMT, &amp;fmt);
    if(rc &lt; 0) {
        fprintf(stderr, &quot;ioctl VIDIOC_G_FMT on %s failed: %s\n&quot;, dev_name, strerror(errno));
        return EXIT_FAILURE;
    }

    printf(&quot;===== %s: format =====\n&quot;, dev_name);
    fprint_v4l2_format(stdout, &amp;fmt);
#endif // 0 

#if 1 // enumerate all supported image formats by the !device! not v4l
    struct v4l2_fmtdesc fmtdsc;
    for(i=0; ;i++) {
        fmtdsc.index = i;
        fmtdsc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        rc = ioctl(dev_fd, VIDIOC_ENUM_FMT, &amp;fmtdsc);
        // NOTE: you can compare this to the output of v4l2_ioctl
        if( rc&lt;0 ) {
            if(errno==EINVAL) {
                errno=0;
                break;
            } else {
                fprintf(stderr, &quot;ioctl VIDIOC_ENUM_FMT on %s failed: %s\n&quot;, dev_name, strerror(errno));
                return EXIT_FAILURE;
            }
        }

        printf(&quot;%3d| %c%c%c%c| %32s| %s%s\n&quot;, 
                fmtdsc.index, 
                (fmtdsc.pixelformat &gt;&gt;  0) &amp; 0xFF,
                (fmtdsc.pixelformat &gt;&gt;  8) &amp; 0xFF,
                (fmtdsc.pixelformat &gt;&gt; 16) &amp; 0xFF,
                (fmtdsc.pixelformat &gt;&gt; 24) &amp; 0xFF,
                fmtdsc.description,
                fmtdsc.flags &amp; V4L2_FMT_FLAG_COMPRESSED ? &quot; Comressed&quot; : &quot;&quot;,
                fmtdsc.flags &amp; V4L2_FMT_FLAG_EMULATED   ? &quot; Emulated&quot; : &quot;&quot;);
    }
#endif
    
    memset(&amp;fmt, 0, sizeof(struct v4l2_format));
    fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    fmt.fmt.pix.width  = 400;
    fmt.fmt.pix.height = 300;
    fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_BGR24;

    rc = v4l2_ioctl(dev_fd, VIDIOC_S_FMT, &amp;fmt);
    if(rc &lt; 0) {
        fprintf(stderr, &quot;ioctl VIDIOC_S_FMT on %s failed: %s\n&quot;, dev_name, strerror(errno));
        return EXIT_FAILURE;
    }
    printf(&quot;===== %s: format =====\n&quot;, dev_name);
    fprint_v4l2_format(stdout, &amp;fmt);
    
    for(i=0; i&lt;9000; i++) {
        size_t sz, buf_sz = fmt.fmt.pix.width * fmt.fmt.pix.height * 3;
        dev_buf = malloc(buf_sz);
        sz = v4l2_read(dev_fd, dev_buf, buf_sz);
        if(sz != buf_sz) {
            fprintf(stderr, &quot;%s: readed %lu instead of %lu bytes. error %d: %s\n&quot;, 
                        dev_name, sz, buf_sz, errno, strerror(errno));
            return EXIT_FAILURE;
        }
        for(i=0; i&lt;fmt.fmt.pix.height; i++) {
            for(j=0; j&lt;fmt.fmt.pix.width; j++) {
                fb_buf[i*fb_si.line_length + j * 4    ] = dev_buf[(i*fmt.fmt.pix.width + j)*3    ];
                fb_buf[i*fb_si.line_length + j * 4 + 1] = dev_buf[(i*fmt.fmt.pix.width + j)*3 + 1];
                fb_buf[i*fb_si.line_length + j * 4 + 2] = dev_buf[(i*fmt.fmt.pix.width + j)*3 + 2];
                
#if 0 // print the second frame right under the first one
    // NOTE: if image is larger than the framebuffer, this can cause SIGFAULT
                fb_buf[i*fb_si.line_length + j * 4     + fb_si.line_length * fmt.fmt.pix.height] = 
                        dev_buf[(i*fmt.fmt.pix.width + j)*3    ];
                fb_buf[i*fb_si.line_length + j * 4 + 1 + fb_si.line_length * fmt.fmt.pix.height] = 
                        dev_buf[(i*fmt.fmt.pix.width + j)*3 + 1];
                fb_buf[i*fb_si.line_length + j * 4 + 2 + fb_si.line_length * fmt.fmt.pix.height] = 
                        dev_buf[(i*fmt.fmt.pix.width + j)*3 + 2];
#endif
            }
        }
        usleep(1000/30);
    }
    
    free(dev_buf);
    munmap(fb_buf, fb_si.smem_len);
    v4l2_close(dev_fd);
    close(fb_fd);
    return EXIT_SUCCESS;
}</code></pre></div><p>накидал тут небольшой пример, выводящий с помощью libv4l2 в фреймбуфер... <br />в ifdef&#039;ах парочка дополнительных возможностей, которые можно включить или выключить...<br />прелесть в том, что от обычного v4l2-Фзш почти не отличается, зато есть несколько форматов, в которые всё конвертируется налету...</p>]]></description>
			<author><![CDATA[null@example.com (Fat-Zer)]]></author>
			<pubDate>Tue, 05 Feb 2013 22:32:07 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=325567#p325567</guid>
		</item>
		<item>
			<title><![CDATA[Re: Video4Linux2. Вывод нескольких буферов.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=325291#p325291</link>
			<description><![CDATA[<p>БЛИН...ВО ТУПАНУЛ!!! ГОЛОВА БОЛИТ ПРОШУ ПРОЩЕНИЯ!! СЕЙЧАС ИСПРАВЛЮ <img src="https://linuxforum.ru/img/smilies/ab.gif" alt="ab" /></p>]]></description>
			<author><![CDATA[null@example.com (mibin)]]></author>
			<pubDate>Mon, 04 Feb 2013 18:14:03 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=325291#p325291</guid>
		</item>
		<item>
			<title><![CDATA[Re: Video4Linux2. Вывод нескольких буферов.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=325287#p325287</link>
			<description><![CDATA[<p>Я вот могу согласиться,что вот тут нужно использовать не capture_buffers[0].length в качестве размера<br /></p><div class="codebox"><pre><code>tyuv yuv[capture_buffers[0].length];
trgb rgb[capture_buffers[0].length];</code></pre></div><p>а ширину * высоту<br /></p><div class="codebox"><pre><code>tyuv yuv[width*height];
trgb rgb[width*height];</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (mibin)]]></author>
			<pubDate>Mon, 04 Feb 2013 18:10:38 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=325287#p325287</guid>
		</item>
		<item>
			<title><![CDATA[Re: Video4Linux2. Вывод нескольких буферов.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=325276#p325276</link>
			<description><![CDATA[<p>Cb00&nbsp; &nbsp; Y&#039;00&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;Cr00 &nbsp; &nbsp; Y&#039;01&nbsp; &nbsp;&nbsp; &nbsp; Cb01&nbsp; &nbsp; Y&#039;02&nbsp; &nbsp;&nbsp; &nbsp; Cr01&nbsp; &nbsp; Y&#039;03<br />Cb10&nbsp; &nbsp; Y&#039;10&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;Cr10 &nbsp; &nbsp; Y&#039;11&nbsp; &nbsp;&nbsp; &nbsp; Cb11&nbsp; &nbsp; Y&#039;12&nbsp; &nbsp; &nbsp;Cr11&nbsp; &nbsp; Y&#039;13<br />Cb20&nbsp; &nbsp; Y&#039;20&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;Cr20&nbsp; &nbsp; Y&#039;21&nbsp; &nbsp; &nbsp;Cb21&nbsp; &nbsp; Y&#039;22&nbsp; &nbsp;&nbsp; &nbsp; Cr21&nbsp; &nbsp; Y&#039;23<br />Cb30&nbsp; &nbsp; Y&#039;30&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;Cr30&nbsp; &nbsp; Y&#039;31&nbsp; &nbsp; &nbsp;Cb31&nbsp; &nbsp; Y&#039;32&nbsp; &nbsp;&nbsp; &nbsp; Cr31&nbsp; &nbsp; Y&#039;33</p><p>Почему околесица...вроде бы биты все подряд посчитал...<br />Блин хреново без платки-то...так бы сразу проверял бы че написал...</p>]]></description>
			<author><![CDATA[null@example.com (mibin)]]></author>
			<pubDate>Mon, 04 Feb 2013 17:45:49 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=325276#p325276</guid>
		</item>
		<item>
			<title><![CDATA[Re: Video4Linux2. Вывод нескольких буферов.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=325269#p325269</link>
			<description><![CDATA[<div class="quotebox"><cite>mibin пишет:</cite><blockquote><p>for (p = 1; p &lt; capture_buffers[capture_buf.index].length; p += 2) {<br />&nbsp; &nbsp; yuv[p].y = yuv((char *)capture_buffers[capture_buf.index].start)[p];<br />}<br />for (p = 0; p &lt; capture_buffers[capture_buf.index].length-2; p+=4) {<br />&nbsp; yuv[p].u = yuv((char *)capture_buffers[capture_buf.index].start)[p];<br />&nbsp; yuv[p].v = yuv((char *)capture_buffers[capture_buf.index].start)[p+2];<br />}</p></blockquote></div><p>околесица какая-то... тем более, если формат именно V4L2_PIX_FMT_UYVY... даже если libv4l не хочешь использовать, то код конвертации уместно из него взять...</p>]]></description>
			<author><![CDATA[null@example.com (Fat-Zer)]]></author>
			<pubDate>Mon, 04 Feb 2013 17:27:47 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=325269#p325269</guid>
		</item>
		<item>
			<title><![CDATA[Re: Video4Linux2. Вывод нескольких буферов.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=325263#p325263</link>
			<description><![CDATA[<p>При переезде забыл кабеля...блин все тесты смогу выложить не раньше чем завтра.<br />НО я не могу откладывать разработку проекта поэтому дабы поддержать историзм выкладываю часть кода которой я собираюсь преобразовывать набор данных в картинку.<br />Вот этот код я буду использовать для преобразования массива данных в структуру YUV<br />Смысл данного кода прост, я беру сплошной набор данных и структурирую его согласно форма YUV на соответствующие составляющие, это нам понадобиться для дальнейшего преобразования картинки в RGB формат.<br />Ссыка на спецификацию данного формата: <a href="http://linuxtv.org/downloads/v4l-dvb-apis/V4L2-PIX-FMT-UYVY.html">http://linuxtv.org/downloads/v4l-dvb-ap … -UYVY.html</a><br /></p><div class="codebox"><pre><code>// Format UYVY
struct tyuv { 
    char y,
    char u,
    char v
};
struct trgb { 
    char r,
    char g,
    char b
}
int p;
tyuv yuv[capture_buffers[0].length];
trgb rgb[capture_buffers[0].length];

// ************************************************
for (p = 1; p &lt; capture_buffers[capture_buf.index].length; p += 2) {
    yuv[p].y = yuv((char *)capture_buffers[capture_buf.index].start)[p];
}
for (p = 0; p &lt; capture_buffers[capture_buf.index].length-2; p+=4) {
  yuv[p].u = yuv((char *)capture_buffers[capture_buf.index].start)[p];
  yuv[p].v = yuv((char *)capture_buffers[capture_buf.index].start)[p+2];
}
// *************************************************

// ******* YUV to RGB ******************************
for (p = 1; p &lt; capture_buffers[capture_buf.index].length; p += 2) {
    rgb[p].r = yuv[p].y + 1.140*yuv[p].v
    rgb[p].g = yuv[p].y - 0.395*yuv[p].u - 0.581*yuv[p].v
    rgb[p].b = yuv[p].y + 2.032*yuv[p].u
}
// *************************************************</code></pre></div><p>Наверное некоторые меня спросят почему я не использовал функцию кодирования из библиотеки v4l2lib, ведь скорее всего там все функции перекодировки оптимизированы и будут работать полюбому быстрее.<br />Дело в том, что с данной функциональностью я не знаком и хочу реализовать ХОТЬ КАК-НИБУДЬ, для начала создадим проект функционирующий, а дальше имея что-то за душой сможем развивать его, оптимизировать дополнять и т.д.</p>]]></description>
			<author><![CDATA[null@example.com (mibin)]]></author>
			<pubDate>Mon, 04 Feb 2013 17:10:45 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=325263#p325263</guid>
		</item>
		<item>
			<title><![CDATA[Re: Video4Linux2. Вывод нескольких буферов.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=325147#p325147</link>
			<description><![CDATA[<p>Да вот поддерживаемый форматы только четыре и все они YUV <img src="https://linuxforum.ru/img/smilies/ab.gif" alt="ab" /> так что кочебениться будет 100%<br />А по этому поводу сейчас почитаю посмотрю что такое libv4l</p>]]></description>
			<author><![CDATA[null@example.com (mibin)]]></author>
			<pubDate>Mon, 04 Feb 2013 07:56:34 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=325147#p325147</guid>
		</item>
		<item>
			<title><![CDATA[Re: Video4Linux2. Вывод нескольких буферов.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=325144#p325144</link>
			<description><![CDATA[<div class="quotebox"><cite>mibin пишет:</cite><blockquote><p>Слудующие действия будут такие...кодировка формата в RGB</p></blockquote></div><p>просто используй V4L2_PIX_FMT_RGB24 или 32.<br />если драйвер девайса будет кочебенится, то для этого вроде и есть libv4l из v4l-utils... документации у неё почти нет, но большая часть функций понятна по названиям...</p>]]></description>
			<author><![CDATA[null@example.com (Fat-Zer)]]></author>
			<pubDate>Mon, 04 Feb 2013 07:48:27 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=325144#p325144</guid>
		</item>
		<item>
			<title><![CDATA[Re: Video4Linux2. Вывод нескольких буферов.]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=325136#p325136</link>
			<description><![CDATA[<p>Путем расспросов смог выяснить что в буфере храниться информация только об изображении и никаких других данных там нет.<br />То в каком формате храниться изображение определяется методом которым мы указали открывать <br />Вот это будет наш тестовый случай (именно в таком формате возвращает данные ADV7180):<br />fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY.</p><p>Слудующие действия будут такие...кодировка формата в RGB и вывод его через буфер /dev/fb0.<br />Частично готовый вариант выложу вечером.</p>]]></description>
			<author><![CDATA[null@example.com (mibin)]]></author>
			<pubDate>Mon, 04 Feb 2013 07:11:57 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=325136#p325136</guid>
		</item>
	</channel>
</rss>
