问题
我正试图将来自浏览器网络摄像头的HTML5MediaStream
传递到Socket.IO命名空间,该命名空间是缓冲的,FFMPEG可以通过HTTP端点以HTTP部分/范围请求的形式访问该命名空间。尽管如此,它在Firefox/Chrome上运行非常完美。
在这里,我包装了一个样本,并将其推送到GitHub repo
环境
- FireFox或Chrome(但不是Safari(
- 节点&NPM
安装
- 项目目录中的
npm i
运行
npm start
:启动express服务器- 在Firefox或Chrome中打开
http://localhost:3000
,并接受网络摄像头访问对话框 npm run ffmpeg -i http://localhost:3000/view output.webm
:TODO:这不会输出完整的流http://localhost:3000/view
在Firefox/Chrome中打开后将可见,他们将一直请求,直到流结束或服务器关闭- 注意,
npm run ffmpeg ...
只是ffmpeg可执行依赖项的快捷方式,应该在启动时安装在node_modules/@ffmpeg-installer/linux-x64/ffmpeg
中(根据操作系统的不同,可能会有所不同(
FFMPEG日志
运行ffmpeg -v trace -i http://localhost:3000/view -y tmp.mp4
:后我得到了什么
Reading option '-v' ... matched as option 'v' (set logging level) with argument 'trace'.
Reading option '-i' ... matched as input url with argument 'http://localhost:3000/view'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option 'tmp.mp4' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument trace.
Applying option y (overwrite output files) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url http://localhost:3000/view.
Successfully parsed a group of options.
Opening an input file: http://localhost:3000/view.
[NULL @ 0x65f1c40] Opening 'http://localhost:3000/view' for reading
[http @ 0x65f2540] Setting default whitelist 'http,https,tls,rtp,tcp,udp,crypto,httpproxy'
[tcp @ 0x65f4000] Original list of addresses:
[tcp @ 0x65f4000] Address 127.0.0.1 port 3000
[tcp @ 0x65f4000] Interleaved list of addresses:
[tcp @ 0x65f4000] Address 127.0.0.1 port 3000
[tcp @ 0x65f4000] Starting connection attempt to 127.0.0.1 port 3000
[tcp @ 0x65f4000] Successfully connected to 127.0.0.1 port 3000
[http @ 0x65f2540] request: GET /view HTTP/1.1
User-Agent: Lavf/58.18.104
Accept: */*
Range: bytes=0-
Connection: close
Host: localhost:3000
Icy-MetaData: 1
[http @ 0x65f2540] header='HTTP/1.1 206 Partial Content'
[http @ 0x65f2540] http_code=206
[http @ 0x65f2540] header='X-Powered-By: Express'
[http @ 0x65f2540] header='Access-Control-Allow-Origin: *'
[http @ 0x65f2540] header='Content-Range: bytes 0-1391616/1073741824'
[http @ 0x65f2540] header='Accept-Ranges: bytes'
[http @ 0x65f2540] header='Content-Length: 1391616'
[http @ 0x65f2540] header='Connection: close'
[http @ 0x65f2540] header='Content-Type: video/webm'
[http @ 0x65f2540] header='Date: Mon, 17 Dec 2018 10:15:14 GMT'
[http @ 0x65f2540] header=''
Probing matroska,webm score:100 size:2048
Probing mp3 score:1 size:2048
[matroska,webm @ 0x65f1c40] Format matroska,webm probed with size=2048 and score=100
st:0 removing common factor 1000000 from timebase
st:1 removing common factor 1000000 from timebase
[matroska,webm @ 0x65f1c40] Before avformat_find_stream_info() pos: 317 bytes read:3837 seeks:0 nb_streams:2
[matroska,webm @ 0x65f1c40] All info found
[matroska,webm @ 0x65f1c40] rfps: 29.750000 0.016025
[matroska,webm @ 0x65f1c40] rfps: 29.833333 0.013167
[matroska,webm @ 0x65f1c40] rfps: 29.916667 0.012378
[matroska,webm @ 0x65f1c40] rfps: 30.000000 0.013659
[matroska,webm @ 0x65f1c40] rfps: 29.970030 0.012960
[matroska,webm @ 0x65f1c40] stream 0: start_time: 0.000 duration: -9223372036854776.000
[matroska,webm @ 0x65f1c40] stream 1: start_time: -0.001 duration: -9223372036854776.000
[matroska,webm @ 0x65f1c40] format: start_time: -0.001 duration: -9223372036854.775 bitrate=0 kb/s
[matroska,webm @ 0x65f1c40] After avformat_find_stream_info() pos: 467388 bytes read:469955 seeks:0 frames:115
Input #0, matroska,webm, from 'http://localhost:3000/view':
Metadata:
encoder : QTmuxingAppLibWebM-0.0.1
Duration: N/A, start: -0.001000, bitrate: N/A
Stream #0:0(eng), 41, 1/1000: Video: vp8, 1 reference frame, yuv420p(progressive), 640x480, 0/1, SAR 1:1 DAR 4:3, 1k tbr, 1k tbn, 1k tbc (default)
Stream #0:1(eng), 74, 1/1000: Audio: opus, 48000 Hz, stereo, fltp, delay 312 (default)
Successfully opened the file.
Parsing a group of options: output url tmp.mp4.
与其用范围进行响应,不如继续发送数据。没有必要对此进行范围请求。FFmpeg会很好地等待下一个块。