|
|
(11 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | [[Category:Engineering]] | + | [[Category: Engineering]] |
| + | [[Category: Imaging]] |
| | | |
| = V4L2 -- Video For Linux Version Two = | | = V4L2 -- Video For Linux Version Two = |
Line 12: |
Line 13: |
| == Gstreamer == | | == Gstreamer == |
| | | |
− | Gstreamer is my favorite command-line tool for handling video.
| + | See [[gstreamer]]. |
− | | |
− | This will display the camera view in a window:
| |
− | <pre>
| |
− | gst-launch v4l2src ! ffmpegcolorspace ! xvimagesink
| |
− | </pre>
| |
− | | |
− | This will display the camera view in a window with a specified size (320x240):
| |
− | <pre>
| |
− | gst-launch v4l2src ! video/x-raw-yuv,width=320,height=240 ! ffmpegcolorspace ! xvimagesink
| |
− | </pre>
| |
− | | |
− | Record video stream to a file using Motion JPEG encoding (MJPEG):
| |
− | <pre>
| |
− | gst-launch --eos-on-shutdown v4l2src ! ffmpegcolorspace ! jpegenc ! avimux ! filesink location=video.avi
| |
− | </pre>
| |
− | | |
− | 1920x1080: This will have a low frame-rate since it will essentially max-out the USB bandwidth. It's useful for capturing individual frames without compression.
| |
− | <pre>
| |
− | gst-launch v4l2src device=/dev/video0 ! 'video/x-raw-yuv,width=1920,height=1080' ! xvimagesink
| |
− | </pre>
| |
− | | |
− | This will capture at a higher framerate, but it will undersample the pixels so you will get an effective 320x240 resolution.
| |
− | <pre>
| |
− | gst-launch v4l2src device=/dev/video0 ! 'video/x-raw-yuv,width=640,height=480,framerate=60/1' ! xvimagesink
| |
− | </pre>
| |
− | | |
− | Record video and display the stream at the same time requires '''tee''' to split the stream. Notice how the '''name''' parameter of '''tee''' refers to a label defined at the end of the command-line. Also notice how '''queue''' is necessary so that '''xvimagesink''' will run in parallel with the '''filesink'''. Without this you would record video but you would see a window with a single frozen frame of video.
| |
− | <pre>
| |
− | gst-launch --eos-on-shutdown v4l2src ! ffmpegcolorspace ! tee name=my_videosink ! jpegenc ! avimux ! filesink location=video.avi my_videosink. ! queue ! xvimagesink
| |
− | </pre>
| |
− | | |
− | Video test pattern:
| |
− | <pre>
| |
− | gst-launch videotestsrc ! ffmpegcolorspace ! xvimagesink
| |
− | </pre>
| |
− | | |
− | === record two video cameras into side-by-side stereo video ===
| |
− | | |
− | <pre>
| |
− | gst-launch v4l2src device=/dev/video1 ! videoscale ! ffmpegcolorspace ! video/x-raw-yuv, width=320, height=240 ! videobox border-alpha=0 left=-320 ! videomixer name=mixme ! ffmpegcolorspace ! jpegenc ! avimux ! filesink location=sbs-3d-video.mov v4l2src device=/dev/video2 ! videoscale ! ffmpegcolorspace ! video/x-raw-yuv, width=320, height=240 ! videobox right=-320 ! mixme.
| |
− | </pre>
| |
− | | |
− | === record video frames into separate files ===
| |
− | | |
− | <pre>
| |
− | gst-launch --eos-on-shutdown v4l2src device=/dev/video1 ! video/x-raw-yuv,format=\(fourcc\)YUY2,width=640,height=480,framerate=30/1 ! ffmpegcolorspace ! videorate ! video/x-raw-rgb,framerate=30/1 ! ffmpegcolorspace ! pngenc snapshot=false ! multifilesink location="frame%05d.png"
| |
− | </pre>
| |
− | | |
− | === playback separate files as a video (slideshow) ===
| |
− | | |
− | <pre>
| |
− | gst-launch multifilesrc location=frame%05d.png ! image/png,framerate=5/1 ! pngdec ! videorate ! video/x-raw-rgb,framerate=5/1 ! ffmpegcolorspace ! xvimagesink
| |
− | </pre>
| |
− | | |
− | === mix two video sources into one (side-by-side) ===
| |
− | | |
− | <pre>
| |
− | gst-launch v4l2src device=/dev/video1 ! videoscale ! ffmpegcolorspace ! video/x-raw-yuv, width=320, height=240 ! videobox border-alpha=0 left=-320 ! videomixer name=mix ! ffmpegcolorspace ! xvimagesink v4l2src device=/dev/video2 ! videoscale ! ffmpegcolorspace ! video/x-raw-yuv, width=320, height=240 ! videobox right=-320 ! mix.
| |
− | </pre>
| |
− | | |
− | === date and time stamps ===
| |
− | | |
− | The '''timeoverlay''' filter adds the frame buffer time to each video frame. The '''clockoverlay''' filter adds the date and time to each video frame.
| |
− | <pre>
| |
− | gst-launch -e v4l2src device=/dev/video1 ! video/x-raw-yuv,format=\(fourcc\)YUY2,width=640,height=480,framerate=30/1 ! ffmpegcolorspace ! timeoverlay shadow=false halignment=right valignment=bottom font-desc="sanserif 10" ypad=5 xpad=5 ! clockoverlay shadow=false halignment=left valignment=bottom time-format="%Y-%m-%d %H:%M:%S" font-desc="sanserif 10" ypad=5 xpad=5 ! videorate ! video/x-raw-rgb,framerate=30/1 ! ffmpegcolorspace ! xvimagesink
| |
− | </pre>
| |
− | | |
− | === interesting filters ===
| |
− | | |
− | <pre>
| |
− | fpsdisplaysink
| |
− | </pre>
| |
− | | |
− | === gstreamer plugin documentation ===
| |
− | | |
− | Many Gstreamer plugins lack good documentation. You can find internal descriptions of plugins and their properties by using '''gst-inspect'''. For examples:
| |
− | <pre>
| |
− | gst-inspect timeoverlay
| |
− | gst-inspect clockoverlay
| |
− | </pre>
| |
− | | |
− | === gstreamer flip video ===
| |
− | | |
− | This is handy if the camera is mounted upside-down or sideways.
| |
− | Upside-down:
| |
− | <pre>
| |
− | gst-launch v4l2src device=/dev/video0 ! video/x-raw-yuv,width=320,height=240,framerate=30/1 ! videoflip method=clockwise ! xvimagesink
| |
− | </pre>
| |
− | Sideways:
| |
− | <pre>
| |
− | gst-launch v4l2src device=/dev/video1 ! video/x-raw-yuv,width=320,height=240,framerate=30/1 ! videoflip method=clockwise ! xvimagesink
| |
− | # or
| |
− | gst-launch v4l2src device=/dev/video1 ! video/x-raw-yuv,width=320,height=240,framerate=30/1 ! videoflip method=counterclockwise ! xvimagesink
| |
− | </pre>
| |
− | | |
− | === gstreamer fbdevsink "ERROR: Pipeline doesn't want to pause." ===
| |
− | | |
− | If you are trying to use the framebuffer device for video playback then you may get an error like the one below. This is a permissions problem. Try adding '''sudo''' in front of the pipeline, or run the command as root.
| |
− | | |
− | <pre>
| |
− | $ gst-launch videotestsrc ! ffmpegcolorspace ! fbdevsink
| |
− | Setting pipeline to PAUSED ...
| |
− | ERROR: Pipeline doesn't want to pause.
| |
− | Setting pipeline to NULL ...
| |
− | Freeing pipeline ...
| |
− | </pre>
| |
− | | |
− | === gstreamer xvimagesink "ERROR: ... Could not initialize Xv output" ===
| |
− | | |
− | This happens if your X11 installation does not support '''Xv'''. This is a common problem when working with a virtual machine. Try using '''ximagesink''' instead of '''xvimagesink'''.
| |
− | | |
− | === playback video on framebuffer (/dev/fbdev0) ===
| |
− | | |
− | <pre>
| |
− | sudo gst-launch uridecodebin uri=file:///home/noah/Videos/ct_scan_sample.flv ! ffmpegcolorspace ! fbdevsink
| |
− | </pre>
| |
− | | |
− | You can also use '''mplayer''' to play video on a framebuffer device. Be sure to specify '''fbdev2''' if you want color.
| |
− | <pre>
| |
− | sudo mplayer -vo fbdev2 ct_scan_sample.flv
| |
− | </pre>
| |
| | | |
| == Capture video and modify settings at the same time == | | == Capture video and modify settings at the same time == |
V4L2 -- Video For Linux Version Two
UVC
For a list of cameras that support UVC see the official Linux UVC site.
Full UVC support in Linux:
I have been using a Logitech HD Pro Webcam C910, USB Device ID: 046d:0821, for my tests.
Gstreamer
See gstreamer.
Capture video and modify settings at the same time
Start `guvcview` with the --control_only option to display a GUI dialog to edit camera settings. This will work while another video display or capture application is already running.
guvcview --control_only --device=/dev/video0
fswebcam
`fswebcam` is a small and simple tool for grabbing still images from a camera. The world needs more apps like this. It can grab a single image or grab sequences of images in a loop. It can save images to a file or pipe them to stdout.
fswebcam --png --save fswebcam-test.png
Common UVC patterns with `uvcdynctrl`
apt-get install uvcdynctrl
uvcdynctrl --device=/dev/video1 --clist
uvcdynctrl --device=/dev/video1 --get='Focus, Auto'
uvcdynctrl --device=/dev/video1 --set='Focus, Auto' 0
uvcdynctrl --device=/dev/video1 --set='Focus (absolute)' 20
See also