update
This commit is contained in:
106
公众号/ffmpeg直播推流.md
Normal file
106
公众号/ffmpeg直播推流.md
Normal file
@@ -0,0 +1,106 @@
|
||||
## ffmpeg实现直播推流
|
||||
|
||||
<img src="https://hackrobot-1258475618.cos.ap-shenzhen-fsi.myqcloud.com/202305022018231.png" title="" alt="" width="153">
|
||||
|
||||
> 使用树莓派4B (raspberry pi)
|
||||
|
||||
直播推流,可以使用开源的`OBS`软件,跨平台,体验好,功能强大
|
||||
|
||||
<img src="https://hackrobot-1258475618.cos.ap-shenzhen-fsi.myqcloud.com/202305022013241.jpg" title="" alt="" width="320">
|
||||
|
||||
|
||||
|
||||
也可以使用低功耗的arm开发板,用`ffmpeg`进行rtmp推流
|
||||
|
||||
这里使用的硬件
|
||||
|
||||
- 1.树莓派4B
|
||||
|
||||
- 2.usb免驱摄像头
|
||||
|
||||
使用usb摄像头是因为线材足够长,而`csi摄像头`长度有限制,且需要对应的兼容模块
|
||||
|
||||
---
|
||||
|
||||
## usb_camera测试
|
||||
|
||||
> 使用cheese和Video4linux
|
||||
|
||||
在使用ffmpeg之前,先确定摄像图能否驱动和实际效果
|
||||
|
||||
启动cheese
|
||||
|
||||
<img src="https://hackrobot-1258475618.cos.ap-shenzhen-fsi.myqcloud.com/202305022013670.png" title="" alt="" width="377">
|
||||
|
||||
使用`Video4Linux2`
|
||||
|
||||
```
|
||||
$ ffmpeg -i /dev/video0 -c:v rawvideo -pix_fmt yuv420p -f sdl "SDL output"
|
||||
```
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## 获取推流地址
|
||||
|
||||
> 主要是url和密匙
|
||||
|
||||
以油管为例子
|
||||
|
||||
<img src="https://hackrobot-1258475618.cos.ap-shenzhen-fsi.myqcloud.com/202305022014851.png" title="" alt="" width="369">
|
||||
|
||||
|
||||
|
||||
ffmpeg最佳参数
|
||||
|
||||
```
|
||||
$ ffmpeg -f v4l2 -i /dev/video0 \
|
||||
-f alsa -i hw:0,0 \
|
||||
-c:v libx264 -pix_fmt yuv420p -framerate 15 -g 30 -b:v 500k \
|
||||
-c:a aac -b:a 128k -ar 44100 -ac 2 \
|
||||
-preset ultrafast -tune zerolatency \
|
||||
-f flv rtmp://a.rtmp.youtube.com/live2/a8rx-y9t2-vrxh-cy6p-a5v6
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 注意事项
|
||||
|
||||
> 油管推流,必须有音频
|
||||
|
||||
由于购买的usb摄像头,并没有麦克风
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
所以在使用ffmpeg进行live 推流的时候,需要设置音频配置项为`静音`
|
||||
|
||||
核心参数
|
||||
|
||||
```
|
||||
-f lavfi -i anullsrc
|
||||
```
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
## 最后
|
||||
|
||||
> 个人微信: `hackrobot`
|
||||
|
||||
创建了一个`微信群`供交流,欢迎加入
|
||||
|
||||
添加好友后,回复关键词: 加群
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
本文参数以及引用:
|
||||
|
||||
[How to Stream Video From Webcam to Network Using FFmpeg | Baeldung on Linux](https://www.baeldung.com/linux/ffmpeg-webcam-stream-video)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user