如果有一天不知道為甚麼你需要透過 Linux / Raspberry Pi 串流 HDMI capture card 到網絡上另一個位置的話,你可以用這個 ffmpeg command:
ffmpeg -f v4l2 \
-input_format mjpeg \
-video_size 1920x1080 \
-framerate 25 \
-i /dev/video0 \
-vcodec mpeg4 \
-pix_fmt yuv420p \
-q:v 1 \
-f mpegts \
-flush_packets 1 \
-max_delay 0\
-analyzeduration 10 \
-probesize 32 \
-fflags nobuffer \
-tune zerolatency \
-listen 1 \
如果你的電腦上並沒有 v4l2,可以透過以下指令安裝並抓到 capture card 支援的輸出格式
sudo apt-get install v4l-utils
v4l2-ctl --device=/dev/video0 --all
輸出例子:
Driver Info:
Driver name : uvcvideo
Card type : usb video: usb video
Bus info : usb-0000:00:14.0-2
Driver version : 6.1.119
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 : usb video: usb video
Serial :
Bus info : usb-0000:00:14.0-2
Media version : 6.1.119
Hardware revision: 0x00002100 (8448)
Driver version : 6.1.119
Interface Info:
ID : 0x03000002
Type : V4L Video
Entity Info:
ID : 0x00000001 (1)
Name : usb video: usb video
Function : V4L2 I/O
Flags : default
Pad 0x01000007 : 0: Sink
Link 0x0200000d: from remote pad 0x100000a of entity 'Processing 2' (Video Pixel Formatter): Data, Enabled, Immutable
Priority: 2
Video input : 0 (Input 1: ok)
Format Video Capture:
Width/Height : 1920/1080
Pixel Format : 'MJPG' (Motion-JPEG)
Field : None
Bytes per Line : 0
Size Image : 4147200
Colorspace : sRGB
Transfer Function : Rec. 709
YCbCr/HSV Encoding: ITU-R 601
Quantization : Default (maps to Full Range)
Flags :
Crop Capability Video Capture:
Bounds : Left 0, Top 0, Width 1920, Height 1080
Default : Left 0, Top 0, Width 1920, Height 1080
Pixel Aspect: 1/1
Selection Video Capture: crop_default, Left 0, Top 0, Width 1920, Height 1080, Flags:
Selection Video Capture: crop_bounds, Left 0, Top 0, Width 1920, Height 1080, Flags:
Streaming Parameters Video Capture:
Capabilities : timeperframe
Frames per second: 30.000 (30/1)
Read buffers : 0
User Controls
brightness 0x00980900 (int) : min=-128 max=127 step=1 default=-11 value=-11
contrast 0x00980901 (int) : min=0 max=255 step=1 default=148 value=148
saturation 0x00980902 (int) : min=0 max=255 step=1 default=180 value=180
hue 0x00980903 (int) : min=-128 max=127 step=1 default=0 value=0
另外如果要看到完整支援的 resolution 跟 framerate 的話可以用這個 command
v4l2-ctl -D -d /dev/video0 --list-formats-ext
它會輸出很多不同的支援格式,例如說這是 UYVY422,支援例如 480×270 然後一列 fps 等等,ffmpeg 的指令也可以按支援的格式來調整。
Index : 1
Type : Video Capture
Pixel Format: 'UYVY'
Name : UYVY 4:2:2
Size: Discrete 424x240
Interval: Discrete 0.011s (90.000 fps)
Interval: Discrete 0.017s (60.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.167s (6.000 fps)
Size: Discrete 480x270
Interval: Discrete 0.011s (90.000 fps)
Interval: Discrete 0.017s (60.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.167s (6.000 fps)
Size: Discrete 640x360
Interval: Discrete 0.011s (90.000 fps)
Interval: Discrete 0.017s (60.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.067s (15.000 fps)
Interval: Discrete 0.167s (6.000 fps)
連接到串流
要連接的話可以用 VLC 或是 OBS 來觀看,以 VLC 為例:
然後在網址列輸入伺服器 / 電腦的 IP 地址即可。