0.0.13 • Published 4 years ago

tms-koa-ffmpeg v0.0.13

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

tms-ffmpeg-rest

tms-koa插件,通过接口操作ffmpeg,增强文件服务,实现播放媒体文件。

支持将媒体文件转为RTP流播放。

安装

在使用tms-koa框架的项目中安装。参见tms-koa框架中“用 npm 包作为控制器”的相关内容。

cnpm i tms-koa-ffmpeg

运行 demo

cd demo

安装并启动

若要在本地运行,需安装 ffmpeg。

cnmp i

node demo/server


或在 docker 中运行。

docker-compose up


检查是否正常运行

curl "http://localhost:3000/ffmpeg/test"

准备媒体文件

files/upload目录下放一个mp4格式文件,例如:123.mp4。

启动 RTP 接收端

可以使用vlc播放器作为 RTP 接收端。

参照如下格式新建 sdp 文件(或使用 demo/test.sdp),音频端口为 5002,视频端口为 5004,用vlc打开。

v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
t=0 0
a=tool:libavformat 58.26.101
m=audio 5002 RTP/AVP 97
c=IN IP4 127.0.0.1
b=AS:64
a=rtpmap:97 opus/48000/2
m=video 5004 RTP/AVP 96
c=IN IP4 127.0.0.1
b=AS:200
a=rtpmap:96 H264/90000

播放文件

curl "http://localhost:3000/ffmpeg/rtp/file/play?path=123.mp4&address=127.0.0.1&aport=5002&vport=5004"

API 说明

用 RTP 包将指定媒体发送到指定接收位置。

播放测试流

curl "http://localhost:3000/ffmpeg/rtp/test/play?address=127.0.0.1&vport=5002&aport=5004&duration=10"

参数说明
address接收 rtp 包的地址
vport接收视频包的端口
vcodecH264 或 VP8
aport接收音频包的端口
duration播放持续时长(秒)。默认一直播放。
socketid传送接收推送消息的socket.io实例 id

返回命令 id

{"cid":"13592d22-9102-403b-84e6-d425431ad82c"}

音频和视频端口至少指定一个。

播放文件

curl "http://localhost:3000/ffmpeg/rtp/file/play?path=&address=&vport=&aport="

参数说明必填
socketid传送接收推送消息的socket.io实例 id
path指定媒体文件路径(参考 tms-koa 文件管理服务)
address接收 rtp 包的地址
vport接收视频包的端口
vcodecH264 或 VP8
aport接收音频包的端口
seek从指定位置开始播放

vportaport至少要指定一个。

返回命令 id

{"cid":"13592d22-9102-403b-84e6-d425431ad82c","format":"通过ffprobe获得的文件信息"}

播放图片

curl "http://localhost:3000/ffmpeg/rtp/image/play?path=&address=&vport="

参数说明
path指定图片文件路径(参考 tms-koa 文件管理服务)
address接收 rtp 包的地址
vport接收视频包的端口
vcodecH264 或 VP8
socketid传送接收推送消息的socket.io实例 id

返回命令 id

{"cid":"13592d22-9102-403b-84e6-d425431ad82c"}

停止播放

curl "http://localhost:3003/ffmpeg/rtp/image/shift?path=&cid="

参数说明
path指定图片文件路径(参考 tms-koa 文件管理服务)
cid命令 Id

停止播放

curl "http://localhost:3003/ffmpeg/rtp/test/stop?cid="

curl "http://localhost:3003/ffmpeg/rtp/file/stop?cid="

curl "http://localhost:3003/ffmpeg/rtp/image/stop?cid="

参数说明
cid命令 Id

暂停播放

curl "http://localhost:3003/ffmpeg/rtp/test/pause?cid="

curl "http://localhost:3003/ffmpeg/rtp/file/pause?cid="

参数说明
cid命令 Id

恢复播放

curl "http://localhost:3003/ffmpeg/rtp/test/resume?cid="

curl "http://localhost:3003/ffmpeg/rtp/file/resume?cid="

参数说明
cid命令 Id

事件推送

如果tms-koa框架启动了推送服务,tms-koa-ffmpeg会推送媒体流处理事件。

事件说明
start启动ffmpeg命令
end结束ffmpeg命令

参见:public/index.html

RTP 流保存为文件

描述定义
接口名/file/rtp/receive
请求方式GET

GET 参数

参数名称类型必选描述
pathString文件保存路径。不指定ext参数时有效。
extString自动生成文件的扩展名。文件命名规则参见tms-koa
sdpfileString指定获得 sdp 文件的位置。
aportInteger系统生成 sdp 文件中音频流端口。不指定sdpfile参数时生效。
aptInteger系统生成 sdp 文件中音频流 playload_type。不指定sdpfile参数时生效。
artpmapString系统生成 sdp 文件中音频流 rtpmap。不指定sdpfile参数时生效。
vportString系统生成 sdp 文件中视频流端口。不指定sdpfile参数时生效。
vptString系统生成 sdp 文件中视频流 playload_type。不指定sdpfile参数时生效。
vrtpmapString系统生成 sdp 文件中视频流 rtpmap。不指定sdpfile参数时生效。

输出参数

参数名称类型描述
cidffmpeg 命令 id。

示例

curl "http://localhost:3000/ffmpeg/file/rtp/receive?ext=mp4&aport=20000&apt=97&artpmap=opus/48000/2&vport=20002&vpt=96&vrtpmap=H264/90000"
0.0.13

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago