我正在尝试将来自浏览器网络摄像头的HTML5 MediaStream
传递到Socket.IO命名空间,该命名空间经过缓冲,可以通过HTTP端点以HTTP partial/range requests的形式被FFMPEG访问。虽然,它可以在Firefox / Chrome上完美运行。
在这里,我已经包装好一个样本并将其放入GitHub repo
npm i
来自项目目录npm start
:启动快递服务器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 -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.
答案 0 :(得分:1)
无需继续响应范围,而只需继续发送数据即可。不需要为此提供范围请求。 FFmpeg将等待下一个块。