linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Using v4l2 API example as-is for video capture
@ 2016-01-08  6:25 Ran Shalit
  2016-01-08 14:03 ` Ran Shalit
  2016-01-11 11:29 ` Hans Verkuil
  0 siblings, 2 replies; 4+ messages in thread
From: Ran Shalit @ 2016-01-08  6:25 UTC (permalink / raw)
  To: linux-media

Hello,

I am trying to use v4l2 example from API documentation:
inhttp://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html .
As a start, I wanted to first try uding it with vivid (virtual device driver).
I found excelent vivid documentation in the kernel, which is very helpful:
https://www.kernel.org/doc/Documentation/video4linux/vivid.txt

But on trying to use the example as-is for capturing video frames into
file, and playing the file, I encounter difficulties.
I tried the example as-is, and then tried several resolution,
pixelformat, different inputs, but it always result with video with a
sync problems ( the test bars of the video are keep moving in the
horizontal axis, or the text is changing its location for one frame to
the next).

I compiled the v4l2 API example AS-IS from:
http://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html with
minor modification in the --force part of the example (I also tried
the example as is without modifications but it did not help), so that
I choose hd input , and 1920x1080 resolution, V4L2_PIX_FMT_YUV420
(also tried V4L2_PIX_FMT_YUV422P) , progressive.

  if (force_format) {
            input = 3;  // <<-- HD input device
            if (-1==xioctl(fd,VIDIOC_S_INPUT,&input))
            {
             errno_exit("VIDIOC_S_INPUT");
            }
            fmt.fmt.pix.width       = 1920;
            fmt.fmt.pix.height      = 1080;
            fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420; // <<-
tried also V4L2_PIX_FMT_YUV422P
            fmt.fmt.pix.field       = V4L2_FIELD_NONE; // <- trying to
capture progressive

            if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt))
                    errno_exit("VIDIOC_S_FMT");

    } else {

I run the application with (the compiled code using pixelformat =
V4L2_PIX_FMT_YUV420 trial ):

./v4l2_example -f -o -c 10  > cap_yuv420p.yuv

And (the compiled code using pixelformat = V4L2_PIX_FMT_YUV422P trial )

./v4l2_example -f -o -c 10  > cap_yuv422p.yuv

I've tried to play them with:

ffplay -f rawvideo -pixel_format yuv420p -video_size 1920x1080 -i
cap_yuv420p.yuv

And

ffplay -f rawvideo -pixel_format yuv422p -video_size 1920x1080 -i
cap_yuv422p.yuv

These are the captured video files from my above trials:

https://drive.google.com/folderview?id=0B22GsWueReZTUS1tSHBraTAyZ00&usp=sharing

I probably am doing something wrong. Is there any idea what's wrong in
my configurations or how I can debug it better ?

Best Regards,
Ran

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Using v4l2 API example as-is for video capture
  2016-01-08  6:25 Using v4l2 API example as-is for video capture Ran Shalit
@ 2016-01-08 14:03 ` Ran Shalit
  2016-01-11 11:29 ` Hans Verkuil
  1 sibling, 0 replies; 4+ messages in thread
From: Ran Shalit @ 2016-01-08 14:03 UTC (permalink / raw)
  To: linux-media

On Fri, Jan 8, 2016 at 8:25 AM, Ran Shalit <ranshalit@gmail.com> wrote:
> Hello,
>
> I am trying to use v4l2 example from API documentation:
> inhttp://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html .
> As a start, I wanted to first try uding it with vivid (virtual device driver).
> I found excelent vivid documentation in the kernel, which is very helpful:
> https://www.kernel.org/doc/Documentation/video4linux/vivid.txt
>
> But on trying to use the example as-is for capturing video frames into
> file, and playing the file, I encounter difficulties.
> I tried the example as-is, and then tried several resolution,
> pixelformat, different inputs, but it always result with video with a
> sync problems ( the test bars of the video are keep moving in the
> horizontal axis, or the text is changing its location for one frame to
> the next).
>
> I compiled the v4l2 API example AS-IS from:
> http://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html with
> minor modification in the --force part of the example (I also tried
> the example as is without modifications but it did not help), so that
> I choose hd input , and 1920x1080 resolution, V4L2_PIX_FMT_YUV420
> (also tried V4L2_PIX_FMT_YUV422P) , progressive.
>
>   if (force_format) {
>             input = 3;  // <<-- HD input device
>             if (-1==xioctl(fd,VIDIOC_S_INPUT,&input))
>             {
>              errno_exit("VIDIOC_S_INPUT");
>             }
>             fmt.fmt.pix.width       = 1920;
>             fmt.fmt.pix.height      = 1080;
>             fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420; // <<-
> tried also V4L2_PIX_FMT_YUV422P
>             fmt.fmt.pix.field       = V4L2_FIELD_NONE; // <- trying to
> capture progressive
>
>             if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt))
>                     errno_exit("VIDIOC_S_FMT");
>
>     } else {
>
> I run the application with (the compiled code using pixelformat =
> V4L2_PIX_FMT_YUV420 trial ):
>
> ./v4l2_example -f -o -c 10  > cap_yuv420p.yuv
>
> And (the compiled code using pixelformat = V4L2_PIX_FMT_YUV422P trial )
>
> ./v4l2_example -f -o -c 10  > cap_yuv422p.yuv
>
> I've tried to play them with:
>
> ffplay -f rawvideo -pixel_format yuv420p -video_size 1920x1080 -i
> cap_yuv420p.yuv
>
> And
>
> ffplay -f rawvideo -pixel_format yuv422p -video_size 1920x1080 -i
> cap_yuv422p.yuv
>
> These are the captured video files from my above trials:
>
> https://drive.google.com/folderview?id=0B22GsWueReZTUS1tSHBraTAyZ00&usp=sharing
>
> I probably am doing something wrong. Is there any idea what's wrong in
> my configurations or how I can debug it better ?
>
> Best Regards,
> Ran


Hi,

I did manage to play the video with the example as-is (no code modification)
But It seems that the captured video is always the same:  422 YUYV.
I tried to change in code to other formats (in the section below force
option as I wrote in the previous post) ,
but although it gives no error (and VIDIOC_G_FMT returns the new
format) ,  and yet - the final video is always in 422, YUYV format.
Is there any hint why we can't change the format to YUV420  ?

Regards,
Ran

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Using v4l2 API example as-is for video capture
  2016-01-08  6:25 Using v4l2 API example as-is for video capture Ran Shalit
  2016-01-08 14:03 ` Ran Shalit
@ 2016-01-11 11:29 ` Hans Verkuil
  2016-01-11 11:56   ` Ran Shalit
  1 sibling, 1 reply; 4+ messages in thread
From: Hans Verkuil @ 2016-01-11 11:29 UTC (permalink / raw)
  To: Ran Shalit, linux-media

On 01/08/2016 07:25 AM, Ran Shalit wrote:
> Hello,
> 
> I am trying to use v4l2 example from API documentation:
> inhttp://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html .
> As a start, I wanted to first try uding it with vivid (virtual device driver).
> I found excelent vivid documentation in the kernel, which is very helpful:
> https://www.kernel.org/doc/Documentation/video4linux/vivid.txt
> 
> But on trying to use the example as-is for capturing video frames into
> file, and playing the file, I encounter difficulties.
> I tried the example as-is, and then tried several resolution,
> pixelformat, different inputs, but it always result with video with a
> sync problems ( the test bars of the video are keep moving in the
> horizontal axis, or the text is changing its location for one frame to
> the next).
> 
> I compiled the v4l2 API example AS-IS from:
> http://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html with
> minor modification in the --force part of the example (I also tried
> the example as is without modifications but it did not help), so that
> I choose hd input , and 1920x1080 resolution, V4L2_PIX_FMT_YUV420
> (also tried V4L2_PIX_FMT_YUV422P) , progressive.
> 
>   if (force_format) {
>             input = 3;  // <<-- HD input device
>             if (-1==xioctl(fd,VIDIOC_S_INPUT,&input))
>             {
>              errno_exit("VIDIOC_S_INPUT");
>             }
>             fmt.fmt.pix.width       = 1920;
>             fmt.fmt.pix.height      = 1080;
>             fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420; // <<-
> tried also V4L2_PIX_FMT_YUV422P
>             fmt.fmt.pix.field       = V4L2_FIELD_NONE; // <- trying to
> capture progressive
> 
>             if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt))
>                     errno_exit("VIDIOC_S_FMT");
> 
>     } else {
> 
> I run the application with (the compiled code using pixelformat =
> V4L2_PIX_FMT_YUV420 trial ):
> 
> ./v4l2_example -f -o -c 10  > cap_yuv420p.yuv

I'm not sure what you're doing, but this just works for me (I use yuv420p to
play this back).

Note: you can find the same code in v4l-utils in contrib/test. That's the code
I used (with you modifications).

Regards,

	Hans


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Using v4l2 API example as-is for video capture
  2016-01-11 11:29 ` Hans Verkuil
@ 2016-01-11 11:56   ` Ran Shalit
  0 siblings, 0 replies; 4+ messages in thread
From: Ran Shalit @ 2016-01-11 11:56 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media

On Mon, Jan 11, 2016 at 1:29 PM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
> On 01/08/2016 07:25 AM, Ran Shalit wrote:
>> Hello,
>>
>> I am trying to use v4l2 example from API documentation:
>> inhttp://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html .
>> As a start, I wanted to first try uding it with vivid (virtual device driver).
>> I found excelent vivid documentation in the kernel, which is very helpful:
>> https://www.kernel.org/doc/Documentation/video4linux/vivid.txt
>>
>> But on trying to use the example as-is for capturing video frames into
>> file, and playing the file, I encounter difficulties.
>> I tried the example as-is, and then tried several resolution,
>> pixelformat, different inputs, but it always result with video with a
>> sync problems ( the test bars of the video are keep moving in the
>> horizontal axis, or the text is changing its location for one frame to
>> the next).
>>
>> I compiled the v4l2 API example AS-IS from:
>> http://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html with
>> minor modification in the --force part of the example (I also tried
>> the example as is without modifications but it did not help), so that
>> I choose hd input , and 1920x1080 resolution, V4L2_PIX_FMT_YUV420
>> (also tried V4L2_PIX_FMT_YUV422P) , progressive.
>>
>>   if (force_format) {
>>             input = 3;  // <<-- HD input device
>>             if (-1==xioctl(fd,VIDIOC_S_INPUT,&input))
>>             {
>>              errno_exit("VIDIOC_S_INPUT");
>>             }
>>             fmt.fmt.pix.width       = 1920;
>>             fmt.fmt.pix.height      = 1080;
>>             fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420; // <<-
>> tried also V4L2_PIX_FMT_YUV422P
>>             fmt.fmt.pix.field       = V4L2_FIELD_NONE; // <- trying to
>> capture progressive
>>
>>             if (-1 == xioctl(fd, VIDIOC_S_FMT, &fmt))
>>                     errno_exit("VIDIOC_S_FMT");
>>
>>     } else {
>>
>> I run the application with (the compiled code using pixelformat =
>> V4L2_PIX_FMT_YUV420 trial ):
>>
>> ./v4l2_example -f -o -c 10  > cap_yuv420p.yuv
>
> I'm not sure what you're doing, but this just works for me (I use yuv420p to
> play this back).
>
> Note: you can find the same code in v4l-utils in contrib/test. That's the code
> I used (with you modifications).
>
> Regards,
>
>         Hans
>
Right,
It works for me. I work with Centos 7.2 which comes with kernel
3.10.0. The YUV420 format are missing there, I understood it after
delving into this issue.

Thanks you !
Ran

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-01-11 11:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-08  6:25 Using v4l2 API example as-is for video capture Ran Shalit
2016-01-08 14:03 ` Ran Shalit
2016-01-11 11:29 ` Hans Verkuil
2016-01-11 11:56   ` Ran Shalit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).