Freebox Batch Video Conversion (mp4 to mkv)

mp4-to-mkv

I often have the problem of needing to convert a folder full of video files to a format compatible with my Freebox, without spending ages in front of my machine doing each video individually. This often happens when I have several takes from my mobile phone or camcorder as mp4 files. Here’s how I worked out how to do it. These instructions apply to Windows 7, and may also work elsewhere on Windows machines.

I have tailored these instructions for a generic encode that will work on Freebox (ADSL triple-play box in France) but since the resulting files stick to standards they should work on most set-top boxes and portable players, including phones and tablets except iPhone/iPad, which read mp4 natively anyway… The typical conversion required is from mp4 to mkv or avi; I prefer mkv for the Freebox as it has worked in more cases for me.

I’m assuming the video codec doesn’t need changing. Most video I encounter is h264 or XviD which are Freebox compatible. This makes converting much faster, because re-encoding video takes ages. I do force audio encoding though, because I’ve had problems with AAC audio tracks (which the Freebox v5 doesn’t like very much at all) or raw PCM and other audio formats that don’t play nice.

Be careful with some Android phone video as it can have dynamic framerates. See advanced notes on how to change codec or force a framerate on your video which will help keep audio and video in sync. If you need to edit after you’ve converted your takes, you’ll be better off with a constant framerate.

Tools required:

AviDemux – https://avidemux.sourceforge.net/ a capable video editor / converter. Open Source and free. This also works on Mac and Linux, and the simple batch file below is adaptable for bash shells which would cover Mac and Linux. Work it out for yourself.

Files required:

1. The script file for AviDemux. This is a simple file used to provide instructions to AviDemux to save the mp4 video file you have as an mkv, and re-encode audio to Lame MP3 @ 128kbps. It provides a generic display width of 1280 pxiels but this may not be used if the source video is different (we’re not re-encoding video here).

#PY  <- Needed to identify #
#--automatically built--

adm = Avidemux()
adm.videoCodec("Copy")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"unknown")
adm.audioAddTrack(0)
adm.audioCodec(0, "Lame", "bitrate=128", "preset=0", "quality=2", "disableBitReservoir=False");
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0,0)
adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1280")

2. The batch file, which will just search all mp4 files and loop through, calling AviDemux each time.

set avidemux="C:\Program Files\Avidemux 2.6 - 64bits\avidemux.exe"
for %%f in (*.mp4) do \
  %avidemux%  --force-alt-h264 --load "%%f" --run fbx.py --save "%%f.avi" --quit

For convenience download a zip file with these files.

Putting it all together:

Set line 1 of the batch file (test.bat in the download) to point to the path where your avidemux.exe resides.

Copy both files into an empty folder.

Copy your .mp4 files to convert into that folder too.

Double-click test.bat and the script will take each mp4 file one-by-one and send it to AviDemux to encode/mux it for you. AviDemux will launch a window each time, but you should not need to interact with it at all. Once it has finished, you will have a bunch of .mkv files with your mp4 files.

Advanced notes

You can do all sorts of encodings with this method. The batch file can be changed to look for avi, mkv or other video file extensions. Just change (*.mp4) to (*.avi) or whatever.

If you want to re-encode video, you can create a specific conversion file from AviDemux by loading a single video to convert, setting up your parameters, then using File > Project Script > Save As Project to create a scripting file. Then edit that file to remove specific lines (like the filename and segment lengths) but to keep the video and audio codec information, and reference that new file on line 3 of the batch file.

3 Responses to “Freebox Batch Video Conversion (mp4 to mkv)”

  1. Stephan Says:

    HI,

    Been searching high and low for exactly this. Works perfectly!
    Thanks for taking the time to put this together, it’s going to save me hours of unnecessary clicking!

  2. Derek Brennan Says:

    Simon,

    Thanks for your excellent article on batch conversion using AVIDemux.

    I modified your two files to help me copy .MOV files to MP4 with the same video and audio. Following are my modified files.

    set avidemux=”C:\Program Files (x86)\Avidemux 2.6″
    for %%f in (*.mov) do %avidemux% –force-alt-h264 –load “%%f” –run fbx.py –save “%%f.mp4″ –quit

    #PY <- Needed to identify #
    #–automatically built–

    adm = Avidemux()
    adm.videoCodec("Copy")
    adm.audioCodec("Copy")

    These modified files work only once converting 2 of 3 selected .MOV files. I have not been able to convert any additional files.

    Do I have a fundamental error in my modified files?

    Thanks,

    Derek

  3. Simon White Says:

    Sorry Derek I don’t see any problems, but it might be an issue with a different version of AVIDemux or file extensions not being all lower case. Can’t think of anything else.

Leave a Reply