Batch script to convert movies for Zune using ffmpeg

I have a first-generation Zune and am fairly happy with it. Music-wise, it’s much better than an iPod since half my music is in WMA format and I’m not about to transcode it. Video-wise, though, it doesn’t decode anything but WMV. This wouldn’t be such a big deal if the Zune software at least transcoded movies for you, but I’ve never had luck doing so (I think it chokes on anything using XVID codecs, for example). And I haven’t found any free 3rd-party apps that work out of the box.

Fortunately, there’s the trusty ffmpeg to the rescue. There are some Zune-optimized settings here, as well as a link to the latest Win32 binaries. So, with the following Windows Script Host script I wrote, you can transcode a whole directory at once.

// batch_ffmpeg.js - encodes all AVI files in input directory to Zune-compatible WMV files
// Note, this doesn't do full recursion; only top-level.  Also overwrites existing files.

// syntax:   cscript batch_ffmpeg.js full_path_to_inputdir full_path_to_outputdir
// e.g.,     cscript batch_ffmpeg.js C:\videos\ C:\videos_for_zune

// edit this for your system
var ffmpeg_path = "C:\\shared\\ffmpeg\\bin\\ffmpeg.exe";

dirArgs = WScript.Arguments;
if (dirArgs.length != 2) {
    WScript.echo("Error: specify absolute paths to input and ouput directories.\n" +
        "e.g., cscript batch_ffmpeg.js C:\\videos\ C:\\videos_for_zune ");

var inputdir = dirArgs(0);
var outputdir = dirArgs(1);

WshShell = new ActiveXObject("WScript.Shell");
var fso = new ActiveXObject("Scripting.FileSystemObject");


var fileArr = new Array();

// push into an array, since Enumerators know their length...
var fc = new Enumerator(fso.GetFolder(inputdir).files);
for (; !fc.atEnd(); fc.moveNext()) {
    var file = fc.item();
    if ("\.avi$") != null)

for (var i=0; i

Leave a Reply

Your email address will not be published. Required fields are marked *