Archive for October 2020

Decoding “.264” Non-standard Video files from Cheap IP Camera

I’m in the process of tinkering with the Amicom WiFi-enabled Outdoor Security Camera.

Amazon store link.

As usual with these types of devices that I buy, I tend to get a bit obsessive about wanting to understand how the thing works internally.  Suffice it to say I have Buildroot working and have loaded various additional Linux utility programs on the camera.  I also wrote my own custom application to simulate the ‘cloud’ service that it connects to, so that I can prevent it from using cloud services (and still make it work).  I might blog more about the larger reverse engineering and cloud simulation project later.

But, toward the end of the project, I wanted to ensure I could view the video files the camera saves on the (optional) embedded SD card.  The files have a .264 extension, but the format is (I think) a raw H.264 stream with chunks of audio data interleaved in between.  Completely non-standard. 

I Googled and found many sites that guide users through playing the .264 files with VLC.  See example.  But, turns out, these steps only allow viewing of the video data; the audio does not play because VLC doesn’t know how to read it.

I dug deeper and finally found a post from someone on videohelp.com who had figured out how to extract the audio portions of the file to a separate audio-only file: 

Brilliant.  @ljx34, whoever you are, I owe you a drink!

Using this script, we can split out the audio and re-combine it with the video in a standard format. I threw this script together very quick:

#!/bin/bash
raw_audio_temp_file=$(mktemp).aac
conv_audio_temp_file=$(mktemp).aac
./extractaudio.py "$1" "${raw_audio_temp_file}"
ffmpeg -i "${raw_audio_temp_file}" "${conv_audio_temp_file}"
rm -f "${raw_audio_temp_file}"
ffmpeg -i "$1" -i "${conv_audio_temp_file}" -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 "$2.mp4"
rm -f "${conv_audio_temp_file}"

Here are the two script files:

convert.sh

extractaudio.py

Put em both in the same directory and run:

./convert.sh <inputfile> <outputfile>

Of course you must have a Linux shell environment and have python3 and ffmpeg installed.