7

Why I am not able to read this file. I tried reading this file with cat as :

cat /dev/video0 

But it says

cat: /dev/video0 : invalid arguments

Similarly, if I try to use dd as :

dd if=/dev/video0 ~/vid

It still is not able to read it.

Note that video0 is the device file for my webcam.

pranavk
  • 1,774
  • 3
  • 17
  • 25
  • 1
    maybe the output of *dmesg* can be useful – Federico Mar 22 '13 at 13:35
  • @Federico dmesg gives no output on executing cat /dev/video0 – pranavk Mar 22 '13 at 19:25
  • Insufficient privileges? IME shell-tools don't always give the error messages you might expect. Try `strace` and see precisely what happens when the `read()` sys-call fails. – marko Mar 22 '13 at 20:44
  • This device file is used to configure the underlying webcam, camera or sensor driver i.e. configuring resolution (width, height and bpp), color modes(RGB, YUV) etc.. I think we can't read any information from this device file. Most of the configurations are done using ioctl calls. – Gautham Kantharaju Mar 23 '13 at 07:51

3 Answers3

7

In such cases, one way to find out more is to run the command in strace

strace cat /dev/video0

which will show more details of the point of failure:

....
open("/dev/video0", O_RDONLY)           = 3
fstat(3, {st_mode=S_IFCHR|0660, st_rdev=makedev(81, 0), ...}) = 0
fadvise64(3, 0, 0, POSIX_FADV_SEQUENTIAL) = 0
read(3, 0x2379000, 65536)               = -1 EINVAL (Invalid argument)
....

which in my case seems to be saying that my /dev/video0 device does not support the required operation: so in this case, 'cat' is trying to read 64k bytes from the device.

However, I found that using nc (netcat) instead of cat did work for this purpose:

nc -l 1234 </dev/video0

With a corresponding:

nc 127.0.0.1 1234 | mplayer tv://device=/dev/stdin

to display locally; an SSH tunnel port would also work here.

MikeW
  • 5,504
  • 1
  • 34
  • 29
  • nc -l -p 1234 ? – moof2k Apr 05 '19 at 19:41
  • No @moof2k, read the man page: https://linux.die.net/man/1/nc >>> -p source_port Specifies the source port nc should use, subject to privilege restrictions and availability. It is an error to use this option in conjunction with the -l option. – MikeW Apr 09 '19 at 08:06
2

I use:

dd if=/dev/video0 of=~/movie.mpg

Then

vlc movie.mpg

But I'm using a PVRUSB2 mpg encoder/decoder as the source.

In your dd invocation you might consider a redirect, ">", of using the "of" construct.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Brian
  • 21
  • 2
1

I think that the show function for the device node "video0" you created in your driver might be wrong.

Give an example in below.

static DEVICE_ATTR(video0, S_IRUGO|S_IWUSR|S_IWGRP|S_IWOTH, video0_show, video0_store);

static ssize_t video0_show(struct device *dev, struct device_attribute *attr, char *buf);

static ssize_t video0_store(struct device *dev, struct device_attribute *attr, char *buf, size_t count);

When you cat the device node "video0" at runtime, it calls the "video0_show" function to print something. The error message "cat: /dev/video0 : invalid arguments" means that the arguments for the video0_show function is wrong. You should debug the driver.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Tomas
  • 116
  • 6