在 Linux 系統使用 USB 攝影機錄製視頻,需核心支援 Video4Linux (V4L2) 相關驅動。本文記錄從核心升級、配置 V4L2 驅動、編譯安裝 SDL 庫與測試程式 (servfox、spcaview) 的完整流程。
linux-2.6.32.59.tar.bz2tar jxvf linux-2.6.32.59.tar.bz2cd linux-2.6.32.59
cp /boot/config-2.6.18-238.el5 .config
make menuconfig 啟用以下選項:M (模組化)MMMMM → ZC3XX USB Camera Driver → MYmake
make modules_install
make install
ls /dev/video0 存在。wget https://www.libsdl.org/release/SDL-1.2.14.tar.gz
tar zxvf SDL-1.2.14.tar.gz
cd SDL-1.2.14/test
./configure && make
cd servfox-R1_1_3
mv Makefile.i386 Makefile
make
cd spcaview-20061208
make
./servfox -g -w 127.0.0.1:7070 -d /dev/video0
./spcaview -g -w 127.0.0.1:7070
此時應可在視窗中看到攝影機畫面,支援網路遠端檢視。
apt install v4l-utils ffmpeg guvcview cheese
# v4l2-ctl --list-devices # 列出裝置
# v4l2-ctl --device=/dev/video0 --all # 查看支援格式
# ffmpeg -f v4l2 -i /dev/video0 -c:v libx264 output.mp4 # 錄影
# guvcview / cheese # 圖形化預覽與錄製
getUserMedia API 使用攝影機。