How I restore unfinished recordings from Canon camera in Windows/Linux/Mac.

Preface

The year is 2019, and I still prefer to take pictures/film videos using a separate physical camera, and in the meantime most people just casually whip out their phone and tap its screen to do the same (that makes me a part of a certain minority, I guess. Does that mean I'm entitled to welfare of some sorts?).
The reason behind this? Mostly the ability to do 20x optical zoom, but there's heaps of other subtle pros like better picture quality in dim lighting.

I've been a satisfied owner of Canon SX280 HS camera for about 5 years now, and all those years I was plagued by one and the only problem it has: when I'm filming videos, it abruptly switches off. Sometimes it saves the video that's being filmed, and in some cases it is lost - what's left behind is file with .DAT extension that can't be played back.

Here's what it's caused by: SX280 determines the charge level of its battery by gauging the voltage level. This is good enough for scenarios where device is draining the battery with constant load: 4.2V translates to full charge, 3V to dry battery. But as soon as you start filming (or start filming + zoom in or out - this exacerbates the current drain) current consumption raises abruptly, leading to a sag in battery's voltage as it's trying to provide enough current.

The battery that comes with Canon SX280 is generally too small to supply currents required by certain usage patterns (like filming and zooming at the same time) - that means that as soon as that abrupt voltage drop happens, there's 2 possible ends to this game:

  • Voltage drop is detected by firmware as a signal to shut down: camera shuts down safely, stopping your filming process and saving it to memory card.
  • The battery can't supply the current that camera's trying to leech (that sign usually starts rearing  its ugly head as the battery gets worn due to use) and voltage just collapses in correspondence to huge current surge. Camera just dies, and unfinished recording with .DAT extension is left behind for you to puzzle over.

Obviously, just as I did, you'll start looking for a way to stop that (this is probably how you've stumbled upon this post), and you'll find hoards of people online that claim to have solved the problem.

Hey, looks like not all is lost? Wrong.

"Solutions" usually fall into one of the following categories:
  • Firmware upgrade. Nope, didn't work for me at all.
  • Covering the middle battery terminal that camera uses to sense battery voltage. 
To be frank, knowing what the issue is caused by you'll see that all of those solutions can be categorized as "duct tape": even if you manage to switch off battery level sensing, there's no way you could circumvent outright low battery capacity and insufficient current output.

My advices for fellow owners of Canon SX280:
1) Buy a hella lot of spare batteries. For more expensive batteries, the time from brand new condition to onset of abrupt shutdowns will definitely be higher than for cheap knockoffs, but eventually they all start to exhibit the same abrupt shutdown syndrome due to wear.

My squadron of batteries in a tidy box. One more is inside the camera I'm taking this pic with.

2) Cover the middle terminal of each one of them - this will prevent firmware from switching the camera off when battery voltage sags. It'll also mean that you'll drain you battery absolutely dry on each usage - this will nibble at its capacity. Also, the only way to determine that it's time to change the battery from now on would be to observe your camera turning off and refusing to turn back on.

A drop of instant glue works charms.

There's only one problem to address now: what do I do with those .DAT files? Is there a way to restore them? From what I've seen on the Internet, people seem to be content to just hand their files over to one of the multitude of online services that will restore the video at a rate of N US dollars for 1 minute.

My damn camera was misbehaving so often that if I decided to pony up I'd go broke after a fruitful trip abroad, with weeks of having camera switch off at a whim and all that.

That's why I had to come up with this no-BS DIY way of restoring corrupt video files without having to pay that I'm now sharing with you. It utilizes the free version of an old Windows command-line program called recover_mp4. Since it only works on Windows and it is quite cumbersome to make it restore more than one video, I wrote 2 scripts that take in a folder of "bad" files and one "good" file and restore them all. Unix version of this script invokes recover_mp4.exe via Wine.

Related links:
Wayback machine-restored software page (in Russian, but it's got a full list of command line options)
Rundown of MP4 container format
Detailed spec of MP4 binary format

Instructions

  • Download the archive with the required files from this repo OR my Google Drive link here. This script works on all major platforms: Windows, and Linux and Mac as well thanks to Wine invoking the Windows executable.
  • Open README.txt for further guidelines.
  • When everything is set up, execute recover_mp4.bat on Windows or recover_mp4.sh  on Linux/Mac.
  • Recovered video files are located in ./recovered directory.

Some notes on usage:

* Make sure all settings at the top of the script are correct.
* If video or audio still appears jittery post-recovery, try different video player application. VLC worked best for me.
* If it still not up to snuff after restoring process - you might have to introduce additional steps between restoring video+audio tracks and streaming it to container with ffmpeg.

Personally, I've had a persistent problem with gaps in sound track. When played back in any audio player, it had small but audible silent gaps, but as soon as I opened that track in Audacity the waveform looked absolutely normal. Just exporting the sound again through Audacity solved the issue. I could not incorporate Audacity as an additional step in console-driven process, and soon enough I found out that re-encoding the stuttering audio file to MP3 achieves the same.

Comments