准备一个树莓派,一个摄像头模块
开启camera
- 执行
sudo raspi-config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| ┌─────────────────────────────┤ Raspberry Pi Software Configuration Tool (raspi-config) ├──────────────────────────────┐
│ │
│ 1 System Options Configure system settings │
│ 2 Display Options Configure display settings │
│ 3 Interface Options Configure connections to peripherals │
│ 4 Performance Options Configure performance settings │
│ 5 Localisation Options Configure language and regional settings │
│ 6 Advanced Options Configure advanced settings │
│ 8 Update Update this tool to the latest version │
│ 9 About raspi-config Information about this configuration tool │
│ │
│ │
│ │
│ │
│ │
│ <Select> <Finish> │
│ │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
- 选择 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| ┌─────────────────────────────┤ Raspberry Pi Software Configuration Tool (raspi-config) ├──────────────────────────────┐
│ │
│ P1 Camera Enable/disable connection to the Raspberry Pi Camera │
│ P2 SSH Enable/disable remote command line access using SSH │
│ P3 VNC Enable/disable graphical remote access using RealVNC │
│ P4 SPI Enable/disable automatic loading of SPI kernel module │
│ P5 I2C Enable/disable automatic loading of I2C kernel module │
│ P6 Serial Port Enable/disable shell messages on the serial connection │
│ P7 1-Wire Enable/disable one-wire interface │
│ P8 Remote GPIO Enable/disable remote access to GPIO pins │
│ │
│ │
│ │
│ │
│ │
│ <Select> <Back> │
│ │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
- 选择
P1 Camera
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| ┌──────────────────────────────────────────────────────────┐
│ │
│ Would you like the camera interface to be enabled? │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ <Yes> <No> │
│ │
└──────────────────────────────────────────────────────────┘
|
- 选择
Yes
然后重启系统
测试是否可以正常使用
执行raspistill -o image.jpg
看是否可以拍照成功
通过vlc实现http视频播放
在树莓派中安装vlc
1
2
| sudo apt update
sudo apt install vlc
|
执行以下代码
1
| raspivid -o - -t 0 -fps 30 -b 6000000 -ex auto -awb auto -vs |cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8080}' :demux=h264
|
在同一个局域网的电脑中,使用视频播放器打开url http://192.168.1.9:8080
, 不可以用浏览器打开
直播推流
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| [email protected]:~ $ cat obs-start.sh
#!/bin/sh
rtmpurl=""
rtmpval=""
if tmux has-session -t 'obs-start'; then
echo "obs is already running."
echo "To stop it use: ./obs-stop.sh"
echo "To attach to it use: tmux attach -t obs"
else
tmux new-session -s 'obs' -d
tmux send-keys 'raspivid -o - -t 0 -fps 24 -b 6000000 -ex auto | ffmpeg -re -stream_loop -1 -f h264 -i - -vcodec copy -acodec aac -b:a 192k -f flv "'$rtmpurl$rtmpval'"' 'C-m'
#tmux split-window
#tmux select-layout tiled 2>/dev/null
tmux rename-window 'obs'
echo "obs has been started in tmux session 'obs'"
echo "To attach to session, use: tmux attach -t obs"
echo "To switch between panes use Ctrl+B-ArrowKey"
echo "To deattach, press Ctrl+B-D"
echo "To stop obs, use: ./obs-stop.sh"
fi
[email protected]:~ $ cat obs-stop.sh
#!/bin/sh
if tmux has-session -t 'obs' 2>/dev/null; then
tmux kill-session -t obs 2>/dev/null
echo "obs has been stopped."
else
echo "obs is not running!"
fi
|
raspivid 部分参数解释
- fps: 设置fps值
- b: 设置码率
- -ex: 曝光模式选项,有夜拍模式的摄像头可以选择auto,会自动打开夜拍模式
1
2
| Exposure mode options :
off,auto,night,nightpreview,backlight,spotlight,sports,snow,beach,verylong,fixedfps,antishake,fireworks
|