问题
我正在尝试将MediaStream
来自浏览器的网络摄像头的 HTML5 传递到Socket.IO命名空间,该命名空间被缓冲,FFMPEG 可以通过 HTTP 端点以HTTP 部分/范围请求的形式访问。虽然,它在 Firefox/Chrome 上完美运行。
在这里,我打包了一个示例并将其推送到GitHub 存储库
环境
- FireFox 或 Chrome(但不是 Safari)
- 节点和 NPM
安装
npm i
从项目目录
跑
npm start
:启动快递服务器- 在 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.