Compare commits
No commits in common. "c2c23ba19862597223f612f7125951d1d421ee36" and "3f8acb100d3d437ea3bd8def16160dad74aba5a6" have entirely different histories.
c2c23ba198
...
3f8acb100d
|
|
@ -1,20 +1,132 @@
|
||||||
# See https://help.github.com/ignore-files/ for more about ignoring files.
|
# ---> Node
|
||||||
|
# Logs
|
||||||
# dependencies
|
logs
|
||||||
/node_modules
|
*.log
|
||||||
|
|
||||||
# production
|
|
||||||
/build
|
|
||||||
/dist
|
|
||||||
|
|
||||||
# misc
|
|
||||||
.idea/
|
|
||||||
.happypack
|
|
||||||
.DS_Store
|
|
||||||
.ice
|
|
||||||
.vscode
|
|
||||||
yarn.lock
|
|
||||||
|
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|
||||||
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
|
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
*.lcov
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# Snowpack dependency directory (https://snowpack.dev/)
|
||||||
|
web_modules/
|
||||||
|
|
||||||
|
# TypeScript cache
|
||||||
|
*.tsbuildinfo
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional stylelint cache
|
||||||
|
.stylelintcache
|
||||||
|
|
||||||
|
# Microbundle cache
|
||||||
|
.rpt2_cache/
|
||||||
|
.rts2_cache_cjs/
|
||||||
|
.rts2_cache_es/
|
||||||
|
.rts2_cache_umd/
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variable files
|
||||||
|
.env
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
.env.local
|
||||||
|
|
||||||
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
|
.cache
|
||||||
|
.parcel-cache
|
||||||
|
|
||||||
|
# Next.js build output
|
||||||
|
.next
|
||||||
|
out
|
||||||
|
|
||||||
|
# Nuxt.js build / generate output
|
||||||
|
.nuxt
|
||||||
|
dist
|
||||||
|
|
||||||
|
# Gatsby files
|
||||||
|
.cache/
|
||||||
|
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||||
|
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||||
|
# public
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# vuepress v2.x temp and cache directory
|
||||||
|
.temp
|
||||||
|
.cache
|
||||||
|
|
||||||
|
# Docusaurus cache and generated files
|
||||||
|
.docusaurus
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
.serverless/
|
||||||
|
|
||||||
|
# FuseBox cache
|
||||||
|
.fusebox/
|
||||||
|
|
||||||
|
# DynamoDB Local files
|
||||||
|
.dynamodb/
|
||||||
|
|
||||||
|
# TernJS port file
|
||||||
|
.tern-port
|
||||||
|
|
||||||
|
# Stores VSCode versions used for testing VSCode extensions
|
||||||
|
.vscode-test
|
||||||
|
|
||||||
|
# yarn v2
|
||||||
|
.yarn/cache
|
||||||
|
.yarn/unplugged
|
||||||
|
.yarn/build-state.yml
|
||||||
|
.yarn/install-state.gz
|
||||||
|
.pnp.*
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,3 @@
|
||||||
# rtsp-to-flv-node
|
# rtsp-to-flv-node
|
||||||
利用node.js + ffmpeg + websokect + flv.js 实现 浏览器播放rtsp流媒体视频
|
|
||||||
|
|
||||||
# 安装前端包
|
rtsp转flv,websocket模式
|
||||||
执行yarn 或者 npm install
|
|
||||||
|
|
||||||
# 启动
|
|
||||||
|
|
||||||
- node server.js (开发调试时使用)
|
|
||||||
- nohup node server.js & (部署服务器上使用,该命令可以保持node服务在持续运行)
|
|
||||||
File diff suppressed because it is too large
Load Diff
13
package.json
13
package.json
|
|
@ -1,13 +0,0 @@
|
||||||
{
|
|
||||||
"name": "rtsp-transform-node",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"main": "index.js",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"@ffmpeg-installer/ffmpeg": "^1.1.0",
|
|
||||||
"express": "^4.17.2",
|
|
||||||
"express-ws": "^5.0.2",
|
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
|
||||||
"websocket-stream": "^5.5.2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
87
server.js
87
server.js
|
|
@ -1,87 +0,0 @@
|
||||||
const ffmpegPath = require('@ffmpeg-installer/ffmpeg'); // 自动为当前node服务所在的系统安装ffmpeg
|
|
||||||
const ffmpeg = require('fluent-ffmpeg');
|
|
||||||
const express = require('express');
|
|
||||||
const webSocketStream = require('websocket-stream/stream');
|
|
||||||
const expressWebSocket = require('express-ws');
|
|
||||||
|
|
||||||
ffmpeg.setFfmpegPath(ffmpegPath.path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建一个后端服务
|
|
||||||
*/
|
|
||||||
function createServer() {
|
|
||||||
const app = express();
|
|
||||||
app.use(express.static(__dirname));
|
|
||||||
expressWebSocket(app, null, {
|
|
||||||
perMessageDeflate: true
|
|
||||||
});
|
|
||||||
app.ws('/rtsp', rtspToFlvHandle);
|
|
||||||
|
|
||||||
app.get('/', (req, response) => {
|
|
||||||
response.send('当你看到这个页面的时候说明rtsp流媒体服务正常启动中......');
|
|
||||||
});
|
|
||||||
|
|
||||||
app.listen(8100, () => {
|
|
||||||
console.log('转换rtsp流媒体服务启动了,服务端口号为8100');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* rtsp 转换 flv 的处理函数
|
|
||||||
* @param ws
|
|
||||||
* @param req
|
|
||||||
*/
|
|
||||||
function rtspToFlvHandle(ws, req) {
|
|
||||||
const stream = webSocketStream(ws, {
|
|
||||||
binary: true,
|
|
||||||
browserBufferTimeout: 1000000
|
|
||||||
}, {
|
|
||||||
browserBufferTimeout: 1000000
|
|
||||||
});
|
|
||||||
// const url = req.query.url;
|
|
||||||
|
|
||||||
const url = Buffer.from(req.query.url, 'base64').toString();
|
|
||||||
console.log('rtsp url:', url);
|
|
||||||
try {
|
|
||||||
ffmpeg(url)
|
|
||||||
.addInputOption(
|
|
||||||
'-rtsp_transport', 'tcp',
|
|
||||||
'-buffer_size', '102400'
|
|
||||||
)
|
|
||||||
.on('start', (commandLine) => {
|
|
||||||
// commandLine 是完整的ffmpeg命令
|
|
||||||
console.log(commandLine, '转码 开始');
|
|
||||||
})
|
|
||||||
.on('codecData', function (data) {
|
|
||||||
console.log(data, '转码中......');
|
|
||||||
})
|
|
||||||
.on('progress', function (progress) {
|
|
||||||
// console.log(progress,'转码进度')
|
|
||||||
})
|
|
||||||
.on('error', function (err, a, b) {
|
|
||||||
console.log(url, '转码 错误: ', err.message);
|
|
||||||
console.log('输入错误', a);
|
|
||||||
console.log('输出错误', b);
|
|
||||||
})
|
|
||||||
.on('end', function () {
|
|
||||||
console.log(url, '转码 结束!');
|
|
||||||
})
|
|
||||||
.addOutputOption(
|
|
||||||
'-threads', '4', // 一些降低延迟的配置参数
|
|
||||||
'-tune', 'zerolatency',
|
|
||||||
'-preset', 'superfast'
|
|
||||||
)
|
|
||||||
.outputFormat('flv') // 转换为flv格式
|
|
||||||
.videoCodec('libx264') // ffmpeg无法直接将h265转换为flv的,故需要先将h265转换为h264,然后再转换为flv
|
|
||||||
// .withSize('50%') // 转换之后的视频分辨率原来的50%, 如果转换出来的视频仍然延迟高,可按照文档上面的描述,自行降低分辨率
|
|
||||||
.noAudio() // 去除声音
|
|
||||||
.pipe(stream);
|
|
||||||
} catch (error) {
|
|
||||||
console.log('抛出异常', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
createServer();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue