处理冲突
commit
c2c23ba198
|
|
@ -1,132 +1,20 @@
|
|||
# ---> Node
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
# See https://help.github.com/ignore-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
|
||||
# production
|
||||
/build
|
||||
/dist
|
||||
|
||||
# misc
|
||||
.idea/
|
||||
.happypack
|
||||
.DS_Store
|
||||
.ice
|
||||
.vscode
|
||||
yarn.lock
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.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,3 +1,10 @@
|
|||
# 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
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
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