V4L2 & Streaming Video with VLC [RTSP & HTTP]
V4L2
v4l2-ctl --get-fmt-video:
$ v4l2-ctl --get-fmt-video
Format Video Capture:
Width/Height : 1600/1200
Pixel Format : 'YUYV'
Field : None
Bytes per Line: 3200
Size Image : 3840000
Colorspace : Unknown (00000000)
Custom Info : feedcafe
v4l2-ctl --all:
$ v4l2-ctl --all
Driver Info (not using libv4l2):
Driver name : uvcvideo
Card type : TEDCAM
Bus info : usb-0000:00:14.0-5.2
Driver version: 4.4.24
Capabilities : 0x84200001
Video Capture
Streaming
Device Capabilities
Device Caps : 0x04200001
Video Capture
Streaming
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
Width/Height : 1600/1200
Pixel Format : 'YUYV'
Field : None
Bytes per Line: 3200
Size Image : 3840000
Colorspace : Unknown (00000000)
Custom Info : feedcafe
Crop Capability Video Capture:
Bounds : Left 0, Top 0, Width 1600, Height 1200
Default : Left 0, Top 0, Width 1600, Height 1200
Pixel Aspect: 1/1
Selection: crop_default, Left 0, Top 0, Width 1600, Height 1200
Selection: crop_bounds, Left 0, Top 0, Width 1600, Height 1200
Streaming Parameters Video Capture:
Capabilities : timeperframe
Frames per second: 30.000 (30/1)
Read buffers : 0
gain (int) : min=0 max=2047 step=1 default=46 value=32
With an LG HD720 webcam v4l2-ctl --all:
Driver Info (not using libv4l2):
Driver name : uvcvideo
Card type : UVC Camera (046d:0825)
Bus info : usb-0000:00:14.0-9.4
Driver version: 4.4.24
Capabilities : 0x84200001
Video Capture
Streaming
Device Capabilities
Device Caps : 0x04200001
Video Capture
Streaming
Priority: 2
Video input : 0 (Camera 1: ok)
Format Video Capture:
Width/Height : 640/480
Pixel Format : 'YUYV'
Field : None
Bytes per Line: 1280
Size Image : 614400
Colorspace : SRGB
Custom Info : feedcafe
Crop Capability Video Capture:
Bounds : Left 0, Top 0, Width 640, Height 480
Default : Left 0, Top 0, Width 640, Height 480
Pixel Aspect: 1/1
Selection: crop_default, Left 0, Top 0, Width 640, Height 480
Selection: crop_bounds, Left 0, Top 0, Width 640, Height 480
Streaming Parameters Video Capture:
Capabilities : timeperframe
Frames per second: 30.000 (30/1)
Read buffers : 0
brightness (int) : min=0 max=255 step=1 default=128 value=128
contrast (int) : min=0 max=255 step=1 default=32 value=32
saturation (int) : min=0 max=255 step=1 default=32 value=32
white_balance_temperature_auto (bool) : default=1 value=1
gain (int) : min=0 max=255 step=1 default=0 value=0
power_line_frequency (menu) : min=0 max=2 default=2 value=2
white_balance_temperature (int) : min=0 max=10000 step=10 default=4000 value=4000 flags=inactive
sharpness (int) : min=0 max=255 step=1 default=24 value=24
backlight_compensation (int) : min=0 max=1 step=1 default=1 value=1
exposure_auto (menu) : min=0 max=3 default=3 value=3
exposure_absolute (int) : min=1 max=10000 step=1 default=166 value=166 flags=inactive
exposure_auto_priority (bool) : default=0 value=1
Set parameters and get an image:
$ v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=0
$ v4l2-ctl --device /dev/video0 --stream-mmap --stream-to=frame.yuv --stream-count=1
To use convert and display applications, you have to install imageMagick package (Convert doesn't work correctly):
$ display -size 1280x720 -depth 8 -sampling-factor 4:2:2 -colorspace YUV yuv:frame.yuv
$ convert -size 1280x720 -depth 8 -format YUV -sampling-factor 4:2:2 -colorspace rgb yuv:frame.yuv png:frame.png
$ ffmpeg -f rawvideo -s 1280x720 -pix_fmt yuyv422 -i frame.yuv frame.png
$ display -size 1280x720 -depth 8 png:frame.png
$ convert -size 1280x720 -depth 8 -sampling-factor 4:2:2 yuv:frame.yuv -separate yuvimage_%d.png (It didn't work)
To use ffmpeg and display applications, you have to install imageMagick and ffmpeg package (Ffmpeg works correctly):
$ display -size 1280x720 -depth 8 -sampling-factor 4:2:2 -colorspace YUV yuv:frame.yuv
$ ffmpeg -f rawvideo -s 1280x720 -pix_fmt yuyv422 -i frame.yuv frame.png
$ display -size 1280x720 -depth 8 png:frame.png
FFMPEG CONVERSION FROM YUYV2 TO MP4 AND VICEVERSA
Source: http://stackoverflow.com/questions/15778774/using-ffmpeg-to-losslessly-convert-yuv-to-another-format-for-editing-in-adobe-pr
yuyv422 -> mp4:
$ ffmpeg -f rawvideo -vcodec rawvideo -s 1280x720 -r 30 -pix_fmt yuyv422 -i frame_video.yuv -c:v libx264 -preset ultrafast -qp 0 output.mp4
mp4 -> yuyv422:
$ ffmpeg -i output.mp4 -f rawvideo -vcodec rawvideo -pix_fmt yuyv422 -s 1280x720 -r 30 output_invert.yuv
Streaming Video with VLC [RTSP & HTTP] using video for linux [v4l2]
Load module v4l2:
$ sudo modprobe bcm2835-v4l2
Enable/disable viewfinder:
$ v4l2-ctl --overlay=1 # enable viewfinder
$ v4l2-ctl --overlay=0 # disable viewfinder
List supported formats:
$ v4l2-ctl --list-formats
Capture a jpeg file:
$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
$ v4l2-ctl --set-ctrl horizontal_flip=1,vertical_flip=1
$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg
HTTP MJPEG Streaming:
v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=5
v4l2-ctl -c compression_quality=100,sharpness=30
#v4l2-ctl -p 10
cvlc --no-audio \
v4l2:///dev/video0 \
--v4l2-width 1920 \
--v4l2-height 1080 \
--v4l2-chroma MJPG \
--v4l2-hflip 1 \
--v4l2-vflip 1 \
--sout '#standard{access=http{mime=multipart/x-mixed-replace;boundary=--7b3cc56e5f51db803f790dad720ed50a},mux=mpjpeg,dst=:8554/}' \
-I dummy
RTSP MJPEG Streaming:
v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=5
v4l2-ctl -c compression_quality=100,sharpness=30
v4l2-ctl -p 10
cvlc --no-audio \
v4l2:///dev/video0 \
--v4l2-width 1920 \
--v4l2-height 1080 \
--v4l2-chroma MJPG \
--v4l2-hflip 1 \
--v4l2-vflip 1 \
--sout '#rtp{sdp=rtsp://:8554/}' \
-I dummy
HTTP H.264 Streaming:
v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=4
v4l2-ctl -c sharpness=30,compression_quality=100,video_bitrate_mode=1,video_bitrate=25000000
cvlc --no-audio \
v4l2:///dev/video0 \
--v4l2-width 1920 \
--v4l2-height 1080 \
--v4l2-chroma h264 \
--v4l2-fps 30 \
--v4l2-hflip 1 \
--v4l2-vflip 1 \
--sout '#standard{access=http,mux=ts,dst=:8554/}' \
-I dummy
Streaming Video with VLC [RTSP & HTTP] using raspivid
This is a guideline to streaming video on a Raspberry Pi 2 with raspivid and VLC.
1. Install vlc:
$ sudo apt-get install vlc
2. Enter the following command to start the streaming:
$ raspivid -o - -t 0 -n -vf | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264
raspivid is used to capture the video.
"-o -" causes the output to be written to stdout.
"-t 0" sets the timeout to disabled.
"-n" stops the video being previewed (remove if you want to see the video on the HDMI output).
"-vf" vertical flip.
cvlc is the console vlc player.
"-vvv" and its argument specifies where to get the stream from.
"-sout" and its argument specifies where to output it to.
Options Specifying the camera resolution
RTSP VGA:
$ raspivid -o - -t 0 -n -vf -w 640 -h 480 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264
RTSP CIF:
$ raspivid -o - -t 0 -n -vf -w 352 -h 288 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264
HTTP VGA:
$ raspivid -o - -t 0 -n -vf -w 640 -h 480 | cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8554}' :demux=h264
HTTP CIF:
$ raspivid -o - -t 0 -n -vf -w 352 -h 288 | cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8554}' :demux=h264
-w Width available range: 64 to 1920.
-h Height available range: 64 to 1080.
-fps Frames per second: 2 to 30 (may change in the future). Seems to be this parameter doesn't work fine so don't use it.
Viewing The RTSP or HTTP Stream Over The Network
You need a player which supports RTSP or HTTP, for instance VLC, Quicktime, etc.
RTSP: Open a network stream using rtsp://###.###.###.###:8554/
HTTP: Open a network stream using http://###.###.###.###:8554/
where ###.###.###.### is the IP address of the RPi.