npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rtsp-downloader

v1.0.8

Published

rtsp stream downloader

Downloads

27

Readme

rtsp-downloader

用 ffmpeg 来给指定的 rtsp/http 视频流录像,存储到本地。基于 Docker 安装,用在 openwrt 里。

Docker 构建和部署

准备工作,构建和安装 docker 包,先把本机的 Docker 启动:

  • 本地打包:npm run docker:build
  • 给arm的软路由打包:npm run docker:build_arm
  • 本地调试启动:npm run start
  • 导出tar包到本地:docker save -o rtsp-downloader.tar rtsp-downloader
  • openwrt 安装包:docker load < rtsp-downloader.tar

把 tar 拷贝到 openwrt 里,启动容器:

docker run --init -d --restart=unless-stopped -v /mnt/usb7-2/Camera:/app/videos -v /root/Configs/rtsp-downloader:/app/config -e TZ=Asia/Shanghai --publish 3000:3000 --name rtsp-downloader rtsp-downloader /app/bin/recorder.js

Mount 两个目录:

  • 配置目录:映射到/app/config
  • 录像目录:映射到/app/videos

配置目录中存放一个 config.json 文件:

{
  "url": "http://47.51.131.147/-wvhttp-01-/GetOneShot?image_size=1280x720&frame_count=1000000000",
  "timeLimit": 15,
  "folderSizeLimit" : 5,
  "name": "cam1",
}
  • url: 视频流地址
  • timeLimit: 视频文件时长,默认 15 分钟
  • folderSizeLimit: 文件夹大小限制,默认 5 GB
  • name: 摄像头名称,默认 cam1

openwrt 启动容器报错:“[FATAL tini (7)] exec /app/bin.js failed: No such file or directory”

这个是 openwrt 的 bug,别用他的后台 GUI 导入镜像文件,要手动拷贝进 openwrt 然后手动执行docker load ...命令

ps:

docker 国内能用的源:https://docker.udayun.com

源码开发和调试

引用方法:

npm i --save rtsp-downloader

仓库源码调试方法:

代码调用方式参照:../example/home.js 或者执行 npm run dev

使用方式:

const Recorder = require('rtsp-downloader').Recorder
const FileHandler = require('rtsp-downloader').FileHandler;

例子:

const Recorder = require('rtsp-downloader').Recorder

var rec = new Recorder({
  url: 'rtsp://192.168.1.12:8554/unicast',
  timeLimit: 60, // time in seconds for each segmented video file
  folder: '/Users/tmp/videos',
  folderSizeLimit : 10, // 10 G
  name: 'cam1',
})
// Starts Recording
rec.startRecording();

记录音频的例子:

const Recorder = require('rtsp-downloader').Recorder

var rec = new Recorder({
  url: 'rtsp://192.168.1.12:8554/unicast',
  timeLimit: 60, // time in seconds for each segmented video file
  folder: '/Users/tmp/videos',
  name: 'cam1',
  type: 'audio',
})

rec.startRecording();

// stop recording
setTimeout(() => {
  console.log('Stopping Recording')
  rec.stopRecording()
  rec = null
}, 125000)

截图的例子:

const Recorder = require('rtsp-downloader').Recorder

var rec = new Recorder({
  url: 'rtsp://192.168.1.12:8554/unicast',
  folder: '/Users/tmp/imgs/',
  name: 'cam1',
  type: 'image',
})

rec.captureImage(() => {
  console.log('Image Captured')
})

管理资源目录:

const FileHandler = require('rtsp-downloader').FileHandler;
const fh = new FileHandler()

// RETURNS DIRECTORY SIZE
fh.getDirectorySize('/Users/tmp/videos/', (err, value) => {
  if (err) {
    console.log('Error Occured')
    console.log(err)
    return true
  }
  console.log('Folder Size is ' + value)
})

// REMOVES ALL MEDIA FILES
fh.removeDirectory('/Users/tmp/videos/*', () => {
  console.log('Done')re
});

自定义目录格式

const Recorder = require('rtsp-downloader').Recorder

var rec = new Recorder({
  url: 'rtsp://192.168.1.12:8554/unicast',
  timeLimit: 60, // time in seconds for each segmented video file
  folder: '/Users/tmp/videos',
  name: 'cam1',
  directoryPathFormat: 'MMM-D-YYYY',
  fileNameFormat: 'M-D-h-mm-ss',
});

// Default directoryPathFormat : MMM-Do-YY
// Default fileNameFormat : YYYY-M-D-h-mm-ss
// Refer to https://momentjscom.readthedocs.io/en/latest/moment/04-displaying/01-format/
//  for custom formats.
// Starts Recording
rec.startRecording();

判断是否正在录像:

const Recorder = require('rtsp-downloader').Recorder

var rec = new Recorder({...});

// check if recoder is running?
rec.isRecoding(); // return true or false