Article 5A5VS VIDIOC_G_FMT

VIDIOC_G_FMT

by
piobair
from LinuxQuestions.org on (#5A5VS)
Here is the definition: https://www.kernel.org/doc/html/v4.1...ioc-g-fmt.html
and here is an example: https://gist.github.com/h4tr3d/602e895d6027a4e48031

I am trying to write a program based on the outcome of an USB camera. My laptop (Lenovo Thinkpad) has a built in camera:
Quote:
$ v4l2-ctl --all
Driver Info:
Driver name : uvcvideo
Card type : Integrated Camera: Integrated C
Bus info : usb-0000:00:14.0-8
Driver version : 4.19.146
Capabilities : 0x84a00001
Video Capture
Metadata Capture
Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04200001
Video Capture
Streaming
Extended Pix Format
Media Driver Info:
Driver name : uvcvideo
Model : Integrated Camera: Integrated C
Serial : 6726
Bus info : usb-0000:00:14.0-8
Media version : 4.19.146
Hardware revision: 0x00006726 (26406)
Driver version : 4.19.146
Interface Info:
ID : 0x03000002
Type : V4L Video
Entity Info:
ID : 0x00000001 (1)
Name : Integrated Camera: Integrated C
Function : V4L2 I/O
Flags : default
Pad 0x01000007 : 0: Sink
Link 0x02000013: from remote pad 0x100000a of entity 'Realtek Extended Controls Unit': Data, Enabled, Immutable
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
Width/Height : 1280/720
Pixel Format : 'MJPG' (Motion-JPEG)
Field : None
Bytes per Line : 0
Size Image : 1843200
Colorspace : sRGB
Transfer Function : Default (maps to sRGB)
YCbCr/HSV Encoding: Default (maps to ITU-R 601)
Quantization : Default (maps to Full Range)
Flags :
Crop Capability Video Capture:
Bounds : Left 0, Top 0, Width 1280, Height 720
Default : Left 0, Top 0, Width 1280, Height 720
Pixel Aspect: 1/1
Selection: crop_default, Left 0, Top 0, Width 1280, Height 720, Flags:
Selection: crop_bounds, Left 0, Top 0, Width 1280, Height 720, Flags:
Streaming Parameters Video Capture:
Capabilities : timeperframe
Frames per second: 30.000 (30/1)
Read buffers : 0
brightness 0x00980900 (int) : min=0 max=255 step=1 default=128 value=128
contrast 0x00980901 (int) : min=0 max=255 step=1 default=32 value=32
saturation 0x00980902 (int) : min=0 max=100 step=1 default=64 value=64
hue 0x00980903 (int) : min=-180 max=180 step=1 default=0 value=0
white_balance_temperature_auto 0x0098090c (bool) : default=1 value=1
gamma 0x00980910 (int) : min=90 max=150 step=1 default=120 value=120
power_line_frequency 0x00980918 (menu) : min=0 max=2 default=1 value=1
white_balance_temperature 0x0098091a (int) : min=2800 max=6500 step=10 default=4600 value=4600 flags=inactive
sharpness 0x0098091b (int) : min=0 max=7 step=1 default=3 value=3
backlight_compensation 0x0098091c (int) : min=0 max=2 step=1 default=1 value=1
exposure_auto 0x009a0901 (menu) : min=0 max=3 default=3 value=3
exposure_absolute 0x009a0902 (int) : min=2 max=1250 step=1 default=156 value=156 flags=inactive
exposure_auto_priority 0x009a0903 (bool) : default=0 value=1
The example cited above does not return the width and length of the camera output. I wrote the following to try to isolate VIDIO_G_FMT :
Code:// sdl2_test.c
// gcc sdl2_test.c -lSDL2

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/videodev2.h>
#include <SDL2/SDL.h>
#include <sys/ioctl.h>
#include <errno.h>

struct v4l2_format argp;
int fc;

int xioctl(int fh, int request, void *arg){
int r;
do {
r = ioctl(fh, request, arg);
} while (-1 == r && EINTR == errno);
return r;
}

int main(){
int i;
fc = open("/dev/video0", O_RDWR | O_NONBLOCK, 0);
if(fc == -1){
printf("ERROR: Could not open /dev/video0\n");
return 1;
}
i = xioctl(fc, VIDIOC_G_FMT, &argp);
printf("i = %d\n", i);
if(i == 0){
printf("Device height = %d; width = %d\n", argp.fmt.pix.height, argp.fmt.pix.width);
}
else printf("VIDIOC_G_FMT ERROR: \n");
return 0;
}(Running Debian Stable) This program returns an error rather than height and width.

??latest?d=yIl2AUoC8zA latest?i=JANYz6DWb28:g4HRWhJ00ho:F7zBnMy latest?i=JANYz6DWb28:g4HRWhJ00ho:V_sGLiP latest?d=qj6IDK7rITs latest?i=JANYz6DWb28:g4HRWhJ00ho:gIN9vFwJANYz6DWb28
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments