Rewrite in go
This release supports the same features as 2.0.0, however the tool is now written in Go and as a result the tool is faster and smaller.
This release supports audio, and if FFmpeg is available then it will create MP4 files. Currently it will create one MP4 for each partition of a multi-partition .ubv, naming the files based on the date+time the video starts.
Audio muxing should account for audio/video synchronisation, however this has not been extensively tested (I don't have any camera samples where AV sync is particularly obvious). If you're experiencing issues and can supply a .ubv for me to examine please raise an issue to get in touch.
QUICK START: FOR UBIQUITI HARDWARE
Instructions for Cloud Key Gen 2 Plus (and other Ubiquiti hardware). Due to the relatively slow CPU and IO subsystems, running a remux this way will be somewhat slow. See below for instructions on how to run under Linux x86 below.
- Go to the "releases" page at https://github.com/petergeneric/unifi-protect-remux/releases and download the latest remux ARM64 binary (N.B. "ARM64", not "x86")
- Upload this to your Cloud Key home folder using SSH (SCP) with
tar -xf remux-arm64.tar.gz && rm remux-arm64.tar.gz && chmod +x remux
- Download the latest FFmpeg ARM Static Release (available on the releases page, and also from https://johnvansickle.com/ffmpeg/)
- Upload this to your Cloud Key and extract it with
xz -d ffmpeg-release-arm64-static.tar.xz && tar -xf ffmpeg-release-arm64-static.tar && mv ffmpeg*arm64-static/ffmpeg ./ && rm ffmpeg-release-arm64-static.tar.xz && chmod +x ffmpeg
- Run the following on your cloudkey:
export PATH=$HOME:$PATH
(you'll either need to run this every time you log in or put it in your.bashrc
file) - Navigate to where your .ubv video is located (base path: /srv/unifi-protect/video).
- Run:
remux *.ubv
- By default, only video is extracted. If you need to extract audio too, add "--with-audio=true" to your command
If FFmpeg is not installed (or if the command fails) the remux tool will leave the raw .aac and .h264 bitstream files; these can be combined with a variety of tools.
QUICK START: FOR x86 LINUX (UBUNTU 20.04 LTS)
Dependencies: ubnt_ubvinfo from CloudKey
N.B. If you have the (discontinued, unsupported) x86 Protect installation, you can use the native x86 ubnt_ubvinfo tool from it - just copy that file to /usr/bin/ubnt_ubvinfo. Otherwise, the following will run the ARM binary on your x86 machine at a slight performance penalty using QEMU.
- On your x86 machine, install qemu-user with:
apt install -y qemu-user gcc-aarch64-linux-gnu
- Copy
/usr/share/unifi-protect/app/node_modules/.bin/ubnt_ubvinfo
from your CloudKey to/usr/bin/arm-ubnt_ubvinfo
on your x86 machine - Run the following:
sudo tee /usr/bin/ubnt_ubvinfo <<EOF
#!/bin/sh
export QEMU_LD_PREFIX=/usr/aarch64-linux-gnu
exec qemu-aarch64 /usr/bin/arm-ubnt_ubvinfo $*
EOF
chmod +x /usr/bin/ubnt_ubvinfo
Dependencies: FFmpeg
To install FFmpeg, run:
apt install -y ffmpeg
Extracting video
Once the dependencies are installed, use the following instructions to get the unifi-protect-remux tool working:
- Go to the "releases" page at https://github.com/petergeneric/unifi-protect-remux/releases and download the latest remux x86_64 binary
- Upload this to your Linux server and extract with
tar -zxf remux-x86_64.tar.gz
- Transfer .ubv files from your CloudKey to your x86 server (on cloudkey, .ubv files are found under /srv/unifi-protect/video).
- Run:
remux *.ubv
- By default, only video is extracted. If you need to extract audio too, add "--with-audio=true" to your command
If FFmpeg is not installed (or if the command fails) the remux tool will leave the raw .aac and .h264 bitstream files; these can be combined with a variety of tools.
Command-line arguments
Usage of remux:
-with-audio
If true, extract audio
-with-video
If true, extract video (default true)
-mp4
If true, will create an MP4 as output (default true)
-output-folder string
The path to output remuxed files to. "SRC-FOLDER" to put alongside .ubv files (default "./")
-version
Display version and quit
-force-rate int
If non-zero, adds a -r argument to FFmpeg invocations
NOTE ON x86 WITHOUT QEMU
The quickstart instructions above show how to run the AARCH64 ubnt_ubvinfo tool shipped with Unifi Protect on your x86 hardware. This relies on qemu-user. If this tool is not available on your x86 machine (and you don't have the native x86 version of ubnt_ubvinfo -- for copyright reasons I can't supply this tool) then you will need to run the ubnt_ubvinfo command on your Ubiquiti hardware, then transfer the .ubv files along with a cached output of ubnt_ubvinfo to your x86 machine for final extraction.
See the scripts folder in the repository: these scripts generate a summary .txt file that you can pull back alongside the .ubv and run remux
on your x86 machine.
Known Issues
In order to create an MP4 the tool has to detect the framerate of the video; it works this out by looking at the time between the initial video frames. This should work unless the framerate is changed mid-video. In this case some of the video may appear to run faster or slower than realtime. This seems a pretty unusual case so I'm not planning special logic for it any time soon!