Mar 3

Converting video from cheap cameras for quick review

Category: Uncategorized

I have a two different sets of cameras that I bought to keep an eye on my porch. This was mostly there to confirm if someone did or didn’t deliver something because I had too many times issues where something was supposedly delivered to the porch but never made it. I decided to add some cameras so that I could tell if it was actually delivered or stolen. I’ve since had one example of a package stolen and been able to validate a bunch more deliveries. I’ve had some issues with Safeway’s delivery service that is it’s own blog post but in this post I’d like to cover how I convert the video files from my FDT and Zosi cameras for reviewing on my Mac.

Tackling the Zosi

The first device to cover is my Zosi device that I bought from AliExpress. In it’s case, I plug in a USB drive directly and “backup” the video files. My use case with the Zosi camera was validating if the Safeway delivery tried to deliver during it’s two hour window. My Zosi camera is continuously recording which makes it a great fit for this sort of brute force approach. Unfortunately after exporting the AVI files from the device and opening them up in VLC, they don’t seem to play properly. I’m not quite sure what is going wrong but I do know that there is a solution.

for FILE in *.avi; do ffmpeg -i $FILE $FILE.mp4; done

That’s it! Really simple use of ffmpeg to convert the files from the AVI format to MP4. This means that Finder on the Mac will also start to play these properly and VLC seems to behave better. This is surprisingly simple to do and seems to clean up the files quickly.

Handling the FDT

The second device is an FDT wireless camera that I purchased from Amazon. The FDT devices are configured to only record motion that happens so that I don’t have to scrub through a bunch of media. These cameras also supported push notification though this has broken for me recently so I’m not sure what is going on there. These support writing to a local SD card which you can take out and are also accessible via a standard HTTP interface. For this situation I needed to figure out in a nearly 24 hour window when someone had dropped something off at my door. Since this camera only records motion, then each of the videos it records should include a hit. The problem with this is that the way the cameras are positioned is inclusive of the road so I can identify the vehicles going past. This means we capture a lot of hits from cars driving past which is mildly frustrating.

The first step is to download all of the candidate files:

wget -r --no-parent http://10.0.1.171/sd/20200301/record000 --user [username] --password [password]

On my network, the device is accessible at 10.0.1.171 and I was looking at the first of March, 2020. You’ll note this also includes a username and password for the HTTP authentication to download, you’ll need to change that to be the same . I use wget here to point it to a path and have it suck down all of the contents of the directory.

The next step is to convert the 264 files into a usable MP4 file. Unlike the Zosi camera that records into a mostly usable format, the FDT cameras now record to a format that ends with 264. You can’t easily convert this file with ffmpeg and opening it up in tooling like VLC doesn’t work properly. Fortunately someone smarter than me figured this out on how to read these files and convert them into something useful. There are a couple of updates to the page and I’ve used the earlier one but there is also a later one with some instructions. This does require some compilation of C code but it’s relatively straight forward to do. Compiling the code is simple, just put it in a file (e.g. 264tomp4.c) and run GCC (you should have Xcode command line tools installed):

gcc -o 264tomp4 264tomp4.c

Then you need to use that to convert your 264 file, in my case I decided to bulk convert them:

for i in *.264; do ~/Programming/264tomp4/264tomp4 $i; done

Then you can merge them together into a single file:

ffmpeg -vcodec h264 -i "concat:$(ls *.mp4 | paste -sd "|" -)" -vcodec copy -acodec copy output.mp4

This gives you a convenient since mp4 file called output.mp4 with everything in it. It’s ignoring the audio file that is extracted with it because in my use case I just wanted to see when the person showed up.

Now on that page there is a second set of code to use which requires slightly different changes. It’s exporting out timestamps and if you use the same gcc command above, you can give it a spin as well.

For it I ended up scripting it a little bit more (I called it 264tomp4_2.c):

for i in *.264;
do
    FILENAME=`basename $i .264`
    echo $FILENAME
    ~/Programming/264tomp4/264tomp4_2 $i
    ffmpeg -i $FILENAME.wav -y $FILENAME.mp3
    mkvmerge --output $FILENAME.mkv --timestamps "0:$FILENAME.video.ts.txt" $FILENAME.h264 $FILENAME.mp3
done

What I’m doing here is a little bit different in that it’s looping to create individual MKV files with that second script. It’s converting the WAV files into MP3 and then using mkvmerge from mkvtoolnix. This creates multiple individual MKV files though they now have audio and in theory have more consistent frame rates. I haven’t found a quick and easy one liner to convert these into a single large file like the earlier script but these files have audio which is an advantage.

All of the non-standard applications were installed via homebrew: wget, ffmpeg and mkvtoolnix (for mkvmerge).

No comments

No Comments

Leave a comment

%d bloggers like this: