Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Hardware
User Name
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?


  Search this Thread
Old 01-06-2006, 06:30 AM   #1
Senior Member
Registered: Apr 2004
Location: Potchefstroom, South Africa
Distribution: Fedora 17 - 3.3.4-5.fc17.x86_64
Posts: 1,542

Rep: Reputation: 101Reputation: 101
XAWTV works, videodog works, motion works but how to code my own?

Hi all

All the above apps work in displaying output from my camera in color, everything ok.

I need to write a program that can display frames from the device myself though. I have tried to use the code of sdlcap-v4l.c to write my own framegrabber, but no matter what I do (even when cutting and pasting line by line from sdlcap-v4l) I keep getting

ioctl VIDIOCMCAPTURE: Invalid argument

with the following code when I try to run it:

int device_idx = 0, video_buf_size = 0;
struct video_capability video_capabilities;
struct video_picture video_pic;
struct video_mmap video_buf_mmap;
struct video_channel video_dev_channel;
struct video_mbuf video_mbuf_info;

unsigned char *video_buf_data;

void grab_frame(int x, int y)
Currently grabs one frame from the video device on channel 0 direct to disk in .PNM format.
Prints video device capabilities to stderr.
device_idx = open("/dev/video0",O_RDWR);

if (device_idx == -1)
printf("Cannot open video device.\n");

perror("open videodev");
}//if (device_idx == -1)


if (ioctl(device_idx,VIDIOCGCAP,&video_capabilities) == -1)
printf("Cannot get video device capabilites.\n");
}//if (ioctl(device_idx,VIDIOCGCAP,&video_capabilities) == -1)


printf("Device Identity: %s\n",;
printf("Device Type: %d\n",video_capabilities.type);
printf("Channels: %d\n",video_capabilities.channels);
printf("Audio Channels: %d\n",video_capabilities.audios);
printf("Max Capture Width: %d\n",video_capabilities.maxwidth);
printf("Max Capture Height: %d\n",video_capabilities.maxheight);
printf("Min Capture Width: %d\n",video_capabilities.minwidth);
printf("Min Capture Height: %d\n",video_capabilities.minheight);

memset(&video_pic,0,sizeof(struct video_picture));

if (ioctl(device_idx,VIDIOCGPICT,&video_pic) == -1)
printf("Cannot get picture information.\n");
}//if (ioctl(device_idx,VIDIOCGPICT,&video_pic) == -1)


printf("Brightness: %d\n",video_pic.brightness);
printf("Hue: %d\n",video_pic.hue);
printf("Colour: %d\n",video_pic.colour);
printf("Contrast: %d\n",video_pic.contrast);
printf("Whiteness: %d\n",video_pic.whiteness);
printf("Depth: %d\n",video_pic.depth);
printf("Palette: %d\n",video_pic.palette);

video_buf_mmap.format = VIDEO_PALETTE_RGB24;
video_buf_mmap.frame = 0;
video_buf_mmap.width = x;
video_buf_mmap.height = y;
video_buf_size = x * y * VIDEO_PALETTE_RGB24_BYTE_DEPTH;

video_buf_data = mmap(0,video_buf_size,PROT_READ|PROT_WRITE,MAP_SHARED,device_idx,0);

if (ioctl(device_idx,VIDIOCSPICT,&video_pic) == -1)
printf("Cannot set picture information.\n");
}//if (ioctl(device_idx,VIDIOCSPICT,&video_pic) == -1)


if (ioctl(device_idx,VIDIOCGCHAN,&video_dev_channel) == -1)
printf("Cannot get video channel information.\n");
}//if (ioctl(device_idx,VIDIOCGCHAN,&video_dev_channel) == -1)


printf("Channel: %d\n",;
printf("Name: %s\n",;
printf("Flags: %d\n",video_dev_channel.flags);
printf("Type: %d\n",video_dev_channel.type);
printf("Norm: %d\n",video_dev_channel.norm);

if (ioctl(device_idx,VIDIOCGMBUF,&video_mbuf_info) == -1)
printf("Cannot get number of video buffers available.\n");
}//if (ioctl(device_idx,VIDIOCGMBUF,&video_mbuf_info) == -1)


printf("Buffers Size: %d\n",video_mbuf_info.size);
printf("Frames: %d\n",video_mbuf_info.frames);

if (ioctl(device_idx,VIDIOCMCAPTURE,&video_buf_mmap) == -1)
printf("Cannot capture frame.\n");
perror("ioctl VIDIOCMCAPTURE");


}//if (ioctl(device_idx,VIDIOCGMBUF,&video_mbuf_info) == -1)
}//if (ioctl(device_idx,VIDIOCGCHAN,&video_dev_channel) == -1)
}//if (ioctl(device_idx,VIDIOCSPICT,&video_pic) == -1)
}//if (ioctl(device_idx,VIDIOCGPICT,&video_pic) == -1)
}//if (ioctl(device_idx,VIDIOCGCAP,&video_capabilities) == -1)
}//if (device_idx == -1)

Everything works fine, right up to the point where I try to execute ioctl VIDIOCMCAPTURE - it keeps on returning the invalud argument error message.

Any ideas...? I've tried to isolate the relevant code in KDETV and XAWTV as well, but they all seem to do much the same and they all give the same error... besides any obvious errors above (please tell me where!) why do the other apps work but mine does not? Anybody see anything especially wrong with my code above?

I also worked throught the "programming-v4l" pdf that comes with videodog, but using one of the two example programs just keep giving the same error in the same place as all my other attempts based on XAWTV, KDETV, motion and videodog itself.
What am I doing wrong?

Any help desperately appreciated!


Last edited by rylan76; 01-06-2006 at 06:34 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mounting works, playing music works, reading tags doesn't Celettu Linux - Newbie 7 08-23-2006 12:27 PM
Trying To Create Stop Motion Animation Using JPEG2YUV...sorta works bluefire Linux - General 1 08-16-2005 11:29 PM
apache works, website works, but not from outside? kahn Linux - Software 7 08-05-2005 02:38 AM
Strange USB problems - it works AND it works not Nightfrost Linux - Hardware 2 10-07-2004 06:07 PM
xawtv works, but messes up other programs rebelcan Linux - Software 2 09-06-2003 04:09 AM > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 06:09 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration