Skip to content

Commit

Permalink
Amend ubvinfo callout to prefer the ubnt_ubvinfo shipped with Unifi P…
Browse files Browse the repository at this point in the history
…rotect where possible.
  • Loading branch information
petergeneric committed Aug 2, 2020
1 parent 081ff99 commit 560b099
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
29 changes: 21 additions & 8 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
OVERVIEW
========

This is a Java tool that extracts an H.264 video bitstream from Ubiquiti's proprietary Unifi Protect .ubv container.
This is a Java tool that extracts an H.264 video bitstream from Ubiquiti's proprietary Unifi Protect .ubv container. Native binaries are available for ARM64 and AMD64 Linux systems.

QUICK START FOR CLOUD KEY GEN2
==============================

1. Go to the "releases" page at https://github.com/petergeneric/unifi-protect-remux/releases and download the latest remux-arm64 binary.
2. Upload this to your Cloud Key, leaving in the home folder
3. Navigate to where your .ubv video is located (/srv/unifi-protect/video)
4. Run ~/remux-amd64 with a single argument, the .ubv file you want to extract from (e.g. ~/remux-amd64 2020/08/01/XXXXXXXXXXXX_0_rotating_1596300058863.ubv)
5. Once the tool completes, you'll find a series of .h264 files in the same directory as the .ubv input
6. Transfer these to your machine. The .h264 files are raw video bitstreams. It will be easier if you remux them into an .MP4 wrapper using FFmpeg
7. Install FFmpeg for your platform (https://ffmpeg.zeranoe.com/builds/ for Windows, apt install ffmpeg for Linux, brew install ffmpeg for MacOS using HomeBrew or https://evermeet.cx/ffmpeg/ otherwise)
8. Use the following command to remux each .h264 into an MP4: ffmpeg -i example.h264 -vcodec copy example.mp4


LIMITATIONS
===========

1. Currently this tool only works with single partition files. In the future it will be expanded to work with multiple partitions, by creating multiple .mp4 files
2. Currently only the video stream is extracted. The underlying can be used to extract the audio bitstream too, but currently the tool does not do this. The resulting AAC and H.264 bitstreams can be muxed together into an MP4 trivially.
3. The tool expects a UNIX system (tested on Linux and MacOS, BSD should work too). The code will run just fine under Windows, but the provided scripts expect UNIX.
1. Currently only the video stream is extracted. The underlying can be used to extract the audio bitstream too, but currently the tool does not do this. Raise an issue if there's interest in this functionality.
2. The tool expects a UNIX system (tested on Linux and MacOS, BSD should work too). The code will run just fine under Windows, it's just untested.

FINDING SOURCE MEDIA
====================
Expand All @@ -28,12 +39,14 @@ Build Native Binary

You can build a native binary using GraalVM's native-image tool. Instructions on how to install the dependencies are at:

https://www.graalvm.org/docs/reference-manual/native-image/
https://www.graalvm.org/docs/reference-manual/native-image/ (the installation is as simple as: unpack latest graal CE, run "gu install native-image")

N.B. for Ubuntu you'll also need the following packages:
N.B. for Ubuntu you'll also need the following packages (N.B. libz-dev may also be zlib1g-dev):
apt install build-essential libz-dev

Then simply run "make native-image" to invoke Maven and then run the resulting .jar through Graal
Make graal your default JVM (export JAVA_HOME=/path/to/graal), put it on the path (export PATH=$PATH:/path/to/graal/bin)

Then simply run "make native-image", which will run a Maven build and generate a "remux" binary via Graal

Install FFmpeg
--------------
Expand All @@ -50,7 +63,7 @@ RUNNING
Entirely locally
----------------

If you have a version of ubnt_ubvinfo that runs on your system (and it's on your PATH), you can run "remux.sh some.ubv"
If you have a version of ubnt_ubvinfo that runs on your system (and it's on your PATH), you can simply run "remux somefile.ubv"

Run ubvinfo remotely and remux locally
--------------------------------------
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/Remux.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ private static Stream<String> ubvinfo(final File inputFile) throws IOException,
{
tempFile = File.createTempFile("ubv", ".txt");

ProcessBuilder pb = new ProcessBuilder("ubnt_ubvinfo", "-t", "7", "-P", "-f", inputFile.getAbsolutePath());
final File cloudkeyBinaryLocation = new File("/usr/share/unifi-protect/app/node_modules/.bin/ubnt_ubvinfo");

// If possible, use the ubnt_ubvinfo under /usr/share. If not present, assume ubnt_ubvinfo is on PATH
final String binary = cloudkeyBinaryLocation.exists() ? cloudkeyBinaryLocation.getPath() : "ubnt_ubvinfo";

ProcessBuilder pb = new ProcessBuilder(binary, "-t", "7", "-P", "-f", inputFile.getAbsolutePath());
pb.redirectError(new File("/dev/null")); // Discard error
pb.redirectOutput(tempFile);
Process process = pb.start();
Expand Down

0 comments on commit 560b099

Please sign in to comment.