GithubHelp home page GithubHelp logo

n1ckyrush / wyzecam-hls Goto Github PK

View Code? Open in Web Editor NEW
67.0 9.0 5.0 11 KB

Converts MP4 files from WyzeCam NFS to HLS stream. Much more stable alternative to RTSP firmware.

JavaScript 100.00%
wyzecam wyze rtsp hls nfs ffmpeg cctv shinobi nvr motioneye

wyzecam-hls's Introduction

WyzeCam HLS support

This tool will allow you to convert MP4 files from WyzeCam into HLS stream. Then you can feed this stream to Shinobi, motioneye, or any other CCTV/NVR solution.

Why?

WyzeCam support RTSP streams via separate official firmware which is much outdated comparing to the latest firmware. Also, it's well-known for instability and weird glitches. That's why this repo was born.

This tool will create a live stream from your Wyze cameras without RTSP. You will need to install WyzeHacks. This "hack" will make your camera record MP4 file every minute into NFS share instead of SD card. Then the script will pick these files to create a live HLS stream. Well, it will have a delay of 60-80 seconds because camera writes a current minute file in the beginning of next minute.

You can read whole story about my misery with RTSP and WyzeCam in my personal blog post.

How to configure?

There is a file config.js with all the configuration. Just open it with any text editor and adjust settings that you need.

Essentially, you will have to add your cameras in cameras array, it's just a path to camera NFS folder.

Here is an example:

export const cameras = [
  {
    NAME: 'cam1',
    NFS_PATH: '/mnt/cams/WyzeCams/1ABC2D3456E7'
  }
]

How to run?

I would suggest using a process manager. For example, pm2.

Here is some quick example how to run it:

# install dependencies
npm install

# add your cameras to the config
vi config.js

# install pm2
npm install pm2

# run the script via pm2
pm2 start pm2.config.js

# enable automatic startup on boot
pm2 startup
pm2 save

# add logrotate to pm2
pm2 install pm2-logrotate

# check logs 
pm2 logs wyzecam-hls

NFS cleanup feature

This script can also clean old files from your NFS folder. For example, you can keep files only for past 24 hours. It will make sense because your long term archive should be maintained by Shinobi or other software which consumes an HLS stream from this script. Be default this feature is disabled, you can enable it by changing variable NFS_CLEANUP_OLD_DAYS variable in config.js.

Also, make sure that user under which you run this script has permissions in NFS folder. For example, I run this script on the same machine where I host NFS, so I've added my user into a group and added uid and gid to exports file.

$ adduser --system nfs
$ usermod -a -G nfs nfs
$ usermod -a -G nfs <MY_USER>
$ cat /etc/exports
/mnt/cams 192.168.0.0/24(rw,sync,no_subtree_check,anonuid=113,anongid=<NFS_GROUP_ID>)

Known bugs

Script is not compatible with ffmpeg3

ffmpeg3 can consume HLS stream from the script, but it throws a lot of warnings about DST timestamps, and output video has a weird FPS and basically is not playable. I've tried to fix it using different options during generating both of my playlists, but nothing helped. Maybe some day somebody will solve it... ffmpeg4 works completely fine though.

Any ideas or suggestions?

Feel free to open a pull request or create an issue.

wyzecam-hls's People

Contributors

n1ckyrush avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wyzecam-hls's Issues

Missing temporary directory causes CameraInstance to return undefined.

Hi there interesting project I am giving it a quick try.

On my initial run if the temporary directory is missing which it will always be since the program has never been run the rm command here https://github.com/n1ckyrush/wyzecam-hls/blob/master/methods/createCameraInstance.js#L39 fails and causes the camera instance to be undefined which causes issues down stream. I was able to get around this by manually creating the directory then running the app and it seems to be fine from there.

It's late so I haven't submitted a PR but I was thinking a few things here.

  1. Change it so that the command checks for existence first then deletes it.
  2. Undefined camera instance should be removed from the camera instances array.
  3. Have the app clean up it's temporary directories when it is stopped
  4. Put the temporary files in to the system temp directory

Stream ends at the minute mark

With my iPhone the stream makes it past the minute mark but with VLC on my desktop it ends at the minute mark. I added the camera in Shinobi but when I view it in the monitor it also ends at the minute mark and then I have to hit reconnect to get another minute. What am I missing here?

Says it can't find esm but esm was installed globally

As indicated it says it can't find esm. I've done both "npm install" and "npm install -g" of esm. What am I missing? (besides esm obviously)

Error: Cannot find module 'esm'
Require stack:

  • internal/preload
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:997:19)
    at Module._preloadModules (node:internal/modules/cjs/loader:1267:12)
    at loadPreloadModules (node:internal/bootstrap/pre_execution:455:5)
    at prepareMainThreadExecution (node:internal/bootstrap/pre_execution:74:3)
    at node:internal/main/run_main_module:7:1 {
    code: 'MODULE_NOT_FOUND',
    requireStack: [ 'internal/preload' ]
    }
    /root/wyzecam-hls/config.js:68
    {
    ^

SyntaxError: Invalid or unexpected token
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
/root/wyzecam-hls/config.js:68
{
^

SyntaxError: Invalid or unexpected token
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
/root/wyzecam-hls/config.js:68
{
^

SyntaxError: Invalid or unexpected token
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)

Need Help to set this up please

Hi,
I have set a Wyze Cam V3 and i seve the Records on my Synology Nas
"volume1/video/WyzeCams/xxx"
I copy the wyzecam-hls Folder to "volume1/video/wyzecam-hls"
in the Config File, i have :

HOST: '192.168.196.156',
PORT: 9001,
xxx
NFS_PATH: 'volume1/video',
xxx
NAME: 'Cam1',
xxx
{
NAME: 'cam1',
NFS_PATH: '/volume1/video/WyzeCams/7C78B22992A1'
}

Now i have a "latest.m3u8" file in the tmp/cam1 Folder. But i can not play this File in VLC, and i have no idea how to set this up in Shinobi. "http://192.168.196.156:9001/cam1/hls.m3u8" does nothing.

Can someone point me in the right direktion?

Here is the log:

/var/services/homes/frank/.pm2/logs/wyzecam-hls-out.log last 15 lines:
0|wyzecam- | NFS_CLEANUP_FOLDERS: [ 'alarm', 'photo', 'time_lapse', 'record' ],
0|wyzecam- | NFS_CLEANUP_OLD_DAYS: 2,
0|wyzecam- | NFS_CLEANUP_PERIOD_SEC: 300,
0|wyzecam- | TMP_CLEANUP_OLD_SEC: 180,
0|wyzecam- | TMP_CLEANUP_PERIOD_SEC: 180,
0|wyzecam- | CHECK_NEW_VIDEO_FILE_PERIOD_SEC: 3,
0|wyzecam- | DEBUG_MODE: 0,
0|wyzecam- | TMP_PATH: '/volume1/video/wyzecam-hls/tmp/cam1'
0|wyzecam- | }
0|wyzecam- | ]
0|wyzecam- | 2021-04-17T07:57:49.308Z [1] [cam1][cleanupNfs] stats: {"total":3,"deleted":0}
0|wyzecam- | 2021-04-17T07:57:49.310Z [1] [cam1][cleanupTmpFiles] stats: {"total":0,"deleted":0}
0|wyzecam- | 2021-04-17T07:57:49.423Z [1] [cam1][stats] stream delay: -s, segments in queue: 0, latest file: 20210417/09/56.mp4, errors: 0, warnings: 0
0|wyzecam- | 2021-04-17T07:57:49.423Z creating server on 192.168.196.156:9001
0|wyzecam- | 2021-04-17T07:57:49.423Z [1] [cam1] HLS URL: http://192.168.196.156:9001/cam1/hls.m3u8

0|wyzecam-hls | 2021-04-17T07:58:19.423Z [1] [cam1][stats] stream delay: -s, segments in queue: 0, latest file: 20210417/09/57.mp4, errors: 0, warnings: 0
0|wyzecam-hls | 2021-04-17T07:58:49.425Z [1] [cam1][stats] stream delay: -s, segments in queue: 0, latest file: 20210417/09/57.mp4, errors: 0, warnings: 0
0|wyzecam-hls | 2021-04-17T07:59:19.425Z [1] [cam1][stats] stream delay: -s, segments in queue: 0, latest file: 20210417/09/58.mp4, errors: 0, warnings: 0
0|wyzecam-hls | 2021-04-17T07:59:49.424Z [1] [cam1][stats] stream delay: -s, segments in queue: 0, latest file: 20210417/09/58.mp4, errors: 0, warnings: 0
0|wyzecam-hls | 2021-04-17T08:00:19.425Z [1] [cam1][stats] stream delay: -s, segments in queue: 0, latest file: 20210417/09/59.mp4, errors: 0, warnings: 0
0|wyzecam-hls | 2021-04-17T08:00:49.313Z [1] [cam1][cleanupTmpFiles] stats: {"total":4,"deleted":0}
0|wyzecam-hls | 2021-04-17T08:00:49.425Z [1] [cam1][stats] stream delay: -s, segments in queue: 0, latest file: 20210417/09/59.mp4, errors: 0, warnings: 0
0|wyzecam-hls | 2021-04-17T08:01:19.424Z [1] [cam1][stats] stream delay: -s, segments in queue: 0, latest file: 20210417/10/00.mp4, errors: 0, warnings: 0
0|wyzecam-hls | 2021-04-17T08:01:49.426Z [1] [cam1][stats] stream delay: -s, segments in queue: 0, latest file: 20210417/10/00.mp4, errors: 0, warnings: 0
0|wyzecam-hls | 2021-04-17T08:02:19.425Z [1] [cam1][stats] stream delay: -s, segments in queue: 0, latest file: 20210417/10/01.mp4, errors: 0, warnings: 0
0|wyzecam-hls | 2021-04-17T08:02:49.310Z [1] [cam1][cleanupNfs] stats: {"total":3,"deleted":0}
0|wyzecam-hls | 2021-04-17T08:02:49.426Z [1] [cam1][stats] stream delay: -s, segments in queue: 0, latest file: 20210417/10/01.mp4, errors: 0, warnings: 0
0|wyzecam-hls | 2021-04-17T08:03:19.426Z [1] [cam1][stats] stream delay: -s, segments in queue: 0, latest file: 20210417/10/02.mp4, errors: 0, warnings: 0
0|wyzecam-hls | 2021-04-17T08:03:49.316Z [1] [cam1][cleanupTmpFiles] stats: {"total":7,"deleted":4}

and this is everything whats in the m3u8 file is inside
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:2
#EXT-X-MEDIA-SEQUENCE:23

hundreds of errors in ffmpeg 4 on rpi 4?

I'd like to know what pi and version of ffmpeg you are using because although the nfs shares and files are stable the hls stream generated is NOT. It gets hundreds of errors in the error log with multi minute gaps resulting in a jerky mess within shinobi. This is probably why motioneye wouldn't even accept the stream. It mentions Possible bad wifi but the nfs share has each minute mp4 and the hls is being generated on the same rpi that owns the share.

I'm on a rpi 4 8Gb running dietpi 64bit based on debian buster. ffmpeg version 4.1.6-1deb10u1+rpt1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 8 (Debian 8.3.0-6)
configuration: --prefix=/usr --extra-version='1
deb10u1+rpt1' --toolchain=hardened --incdir=/usr/include/aarch64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --libdir=/usr/lib/aarch64-linux-gnu --arch=arm64 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared

wyzecam-hls-error__2021-01-04_00-00-00.log
wyzecam-hls-error.log
wyzecam-hls-out__2021-01-04_00-00-00.log
wyzecam-hls-out.log

image

Stream may work in Shinobi but it doesn't work in motioneye.

It's running and has given me 4 urls for 4 camera's but putting them into motioneye and trying to add a cam does not work...what process should be followed? Example address is http://127.0.0.1:9001/Back_Yard/hls.m3u8 Both wyzecam-hls and motioneye are on the same raspberry pi so 127.0.01 should be fine.

image

The log file says the streams are available:

I see this error over and over in error log:
021-01-02T14:58:17.290Z [0] [Back_Yard][checkPlaylistFile] playlist file error TypeError: Cannot read property 'filename' of undefined
at checkPlaylistFile (/root/wyzecam-hls/methods/checkPlaylistFile.js:46:244)
2021-01-02T14:58:21.295Z [0] [Front_Yard][checkPlaylistFile] playlist file error TypeError: Cannot read property 'filename' of undefined
at checkPlaylistFile (/root/wyzecam-hls/methods/checkPlaylistFile.js:46:244)
2021-01-02T14:58:29.310Z [0] [Front_Yard][checkPlaylistFile] playlist file error TypeError: Cannot read property 'filename' of undefined
at checkPlaylistFile (/root/wyzecam-hls/methods/checkPlaylistFile.js:46:244)

The out log shows:

2021-01-02T14:22:42.003Z [1] [Back_Yard][stats] stream delay: 62s, segments in queue: 6, latest file: 20210102/09/21.mp4, errors: 6412, warnings: 0
2021-01-02T14:22:42.004Z [1] [Front_Yard][stats] stream delay: 62s, segments in queue: 8, latest file: 20210102/09/21.mp4, errors: 6412, warnings: 0
2021-01-02T14:22:42.006Z [1] [Garage_Cam][stats] stream delay: 80s, segments in queue: 30, latest file: 20210102/09/21.mp4, errors: 384, warnings: 0
2021-01-02T14:22:42.135Z [1] [Shed][stats] stream delay: 63s, segments in queue: 8, latest file: 20210102/09/21.mp4, errors: 1283, warnings: 0

Adding ftp download capability

Hi,
I had lots of NFS incompatibility related camera reboots so ended up adding a custom script to the camera and downloading files via an ftp server that is started from the sd card. On my Blueiris recorder pc, I have a python script downloading the camera files via ftp end then I have your script running to create the HLS stream for BlueIris from the downloaded files. This is rock solid now (unlike NFS was). But, it is too cluttered and not knowing much about js scripting I was wondering if you would be willing to incorporate optional ftp client capability directly to your script to make things a little more user friendly.
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.