当前位置:网站首页>使用EasyDarwin+FFmpeg实现rtsp推流
使用EasyDarwin+FFmpeg实现rtsp推流
2022-06-13 04:58:00 【日落班】
一、背景
最近在学习ffmpeg的基本操作,ffmpeg功能非常强大,可以运行音频和视频多种格式的录影、转换、流功能,包含了libavcodec——这是一个用于多个项目中音频和视频的解码器库,以及libavformat——一个音频与视频格式转换库
可以利用ffmpeg对媒体文件进行拼接,转换,录制,截图,推流等等,本次采用ffmpeg将本地视频文件推送至流媒体服务器然后进行 html拉流播放的操作,需要的配置和准备如下。
name | 备注 |
Ffmpeg | 推流工具 |
EasyDarwin | 流媒体服务 |
Centos7 | 服务器 |
二、安装EasyDarwin
EasyDarwin是一个高性能开源RTSP流媒体服务器,基于go语言研发,维护和优化RTSP推模式转发、RTSP拉模式转发、录像、检索、回放、关键帧缓存、秒开画面、RESTful接口、WEB后台管理、分布式负载均衡等方面!
媒体服务在easydarwin的官网中下载符合服务器的版本进行安装
wget https://github.com/EasyDarwin/EasyDarwin/releases/download/v8.1.0/EasyDarwin-linux-8.1.0-1901141151.tar.gz
tar -zvxf EasyDarwin-linux-8.1.0-1901141151.tar.gz
cd EasyDarwin-linux-8.1.0-1901141151/
进入安装目录后有一个easydarwin.ini 文件 需要配置服务账号和端口等。
[http]
port=3000
default_username=admin
default_password=admin
[rtsp]
port=2379
; rtsp 超时时间,包括RTSP建立连接与数据收发。
timeout=28800
; 是否使能gop cache。如果使能,服务器会缓存最后一个I帧以及其后的非I帧,以提高播放速度。但是可能在高并发的情况下带来内存压力。
gop_cache_enable=1
; 是否使能向服务器推流或者从服务器播放时验证用户名密码. [注意] 因为服务器端并不保存明文密码,所以推送或者播放时,客户端应该输入密码的md5后的值。
; password should be the hex of md5(original password)
authorization_enable=0
; 是否使能推送的同事进行本地存储,使能后则可以进行录像查询与回放。
save_stream_to_local=0
;easydarwin使用ffmpeg工具来进行存储。这里表示ffmpeg的可执行程序的路径
ffmpeg_path=/Users/ze/Downloads/ffmpeg-20180719-9cb3d8f-macos64-shared/bin/ffmpeg
;本地存储所将要保存的根目录。如果不存在,程序会尝试创建该目录。
m3u8_dir_path=/Users/ze/Downloads/EasyDarwinGoM3u8
;切片文件时长。本地存储时,将以该时间段为标准来生成ts文件(该时间+一个I帧间隔),单位秒。
;如果需要直播,这个值设小点,但是这样会产生很多ts文件;如果不需要直播,只要存储的话,可设大些。
ts_duration_second=6
;key为拉流时的自定义路径,value为ffmpeg转码格式,比如可设置为-c:v copy -c:a copy,表示copy源格式;default表示使用ffmpeg内置的输出格式,会进行转码。
/stream_265=default
对于rtsp推流测试和使用来说只需要关注http服务部分的端口号和账户,rtsp部分的端口配置。在配置的时候,需要注意服务器的端口是以及开放的。
在安装目录下直接运行.start.sh脚本就可以启动 EasyDarwin服务,由于EasyDarwin是用golang编写,因此需求服务器配置golang安装环境。
启动之后打开在浏览器打开 服务器ip:端口
在没有推流前是看不到任何信息。
三、Ffmpeg推流操作
进入FFmpeg Releases · BtbN/FFmpeg-Builds · GitHub 官网下载对应的版本,解压后bin目录内容如下。
正在上传…重新上传取消
描述 | 学习 | |
ffmpeg | FFmpeg 是领先的多媒体框架,能够解码、编码、 转码、复用、解复用、流、过滤和播放几乎所有人类和机器创建的东西 | About FFmpeg |
ffplay | FFplay 是一个使用 FFmpeg 库和 SDL 库的非常简单和便携的媒体播放器。它主要用作各种 FFmpeg API 的测试平台。 | ffplay Documentation |
ffprobe | ffprobe可以从媒体流收集媒体信息,并打印出开发人员可以读的格式,也可以把ffprobe理解为流媒体的分析工具;使用ffprobe可以查看流媒体中包含的容器,以及容器中包含的流媒体的格式和类型 | ffprobe 简介 - 简书 |
三个包的功能各不相同,其功能很强大。具体细节可以参考官网
// 推送本地媒体文件
ffmpeg.exe -re -stream_loop -1 -i 1out.mp4 -vcodec h264 -f rtsp rtsp://49.232.162.xxx:2379/test
// 录屏推流
ffmpeg -f gdigrab -i desktop -r 15 -vf scale=640:360 -rtsp_transport tcp -vcodec h264 -f rtsp rtsp://localhost/capture
// 录屏
ffmpeg -f gdigrab -i desktop -f mp4 out.mp4
使用该命令将本地的1out.mp4视频推送到推流服务器上,注意本次采用格式是 rtsp,当然你可以指定其他的格式,推送的地址注意端口为在媒体服务的指定打开的端口。
当流推成功后在EasyDarwin 的服务地址可以看见对应的推流记录。
四、拉流操作
在推流成功后就可以进行拉流操作 ,在推流列表中复制播放地址,复制出来后就可以使用VLC工具播放了
当播放正常的时候在 EasyDarwin服务的拉流列表里面就能看到对应的拉流记录
到此就实现了将本地流推送到远程推流服务并且实现拉流播放的功能。
边栏推荐
- C language exercise 1
- Clause 32: moving objects into closures using initialization capture objects
- 详解OpenCV的函数cv::add(),并附各种情况的示例代码和运行结果
- Cesium:cesiumlab makes image slices and loads slices
- Configuration used by automatic teaching evaluation script
- Kaggle 时间序列教程
- Tita: Xinrui group uses one-to-one talk to promote the success of performance change
- Analysis of scoped attribute principle and depth action selector
- UNO
- Force buckle 25 A group of K flipped linked lists
猜你喜欢
PowerShell plus domain add computer module
OpenCV中的saturate操作(饱和操作)究竟是怎么回事
Mysql8.0.13 installation tutorial (with pictures)
Embedded hardware: electronic components (1) resistance capacitance inductance
How to use redis
What is the difference between ROM, ram and flash? SRAM、DRAM、PROM、EPROM、EEPROM
Interpretation of QT keypressevent
Logical point
Section 5 - Operator details
QT client development -- driver loading problem of connecting to MySQL database
随机推荐
PowerShell: because running scripts is prohibited on this system, the solution
The differences between the four startup modes of activity and the applicable scenarios and the setting methods of the two startup modes
Shell built-in string substitution
Avantages de win8.1 et win10
Section 6 - pointers
Bomb disposal cat
Little C's Notepad
[try to hack] upload labs (temporarily write to 12)
Analysis of scoped attribute principle and depth action selector
Logical point
Configuration used by automatic teaching evaluation script
Clause 31: avoid default capture mode
Interpretation of QT keypressevent
All blog navigation
Third party comment plugin
Clause 33: decltype is used for auto & type formal parameters, with std:: forward
QT signal is automatically associated with the slot
E - Lucky Numbers
shell变量学习笔记
[LeetCode]-二分查找