Transcode MOV to MP4

GitHub Source


Digital cameras and phones typically save video to MOV (Motion JPEG) files. I share my photos & videos via a self hosted open source photo gallery (zenPhoto). MOV files must be converted to a compatible format like MP4 to stream through the readily available web video players like Flowplayer.

Script features:

  • Handles multiple files at once… even from different folders, e.g. when part of a file explorer search result
  • Applies rotation where recognized in the EXIF metadata.
  • Touches new file datestamp to be same as original.

Leverages 3rd party tools:

  • FileMenu Tools (FMT) - handy for creating a FileExplorer right mouse context menu for executing transcode on selected files
  • See new free approach for the Context Menu piece
  • HandBrake - read something that suggested HandBrake is faster than ffmpeg and that appears true on my quick comparison
  • MediaInfo - pulls the EXIF metadata to determine if any rotation is necessary


  1. save transcode.ps1 to a known location
  2. install FileMenu Tools and disable all the commands you don’t want.
  3. Configure a “transcode” command as shown in screenshot below... edit for your path
  • updated FMT Arguments: -Command "{path}\transcode.ps1" -list %TEMPFILEPATHS% -rotate auto
  1. install HandBrake and put HandBrakeCli in your path
  2. minimally, put MediaInfo.exe and MediaInfo.dll in your path

Windows File Explorer UI example

enter image description here

Transcoding Motion-JPEG (.MOV) to MPEG-4 (H264)


please see => Newer Approach


I have a Panasonic DMC-ZS5 (dpreview, Panasonic) which creates .MOV files that contain the Motion JPEG (M-JPEG) “format” (for want of a more technical term).

In order to stream those videos from my IIS/PHP based photo gallery (, they must be converted to a more “web compatible” format like MPEG-4.  I haven’t found a more straightforward approach than direct batch conversion to another format… you can readily automate the conversion of say all the videos in a folder so it’s pretty much turnkey and ignore.

Update 2015-01-05: This is my current go-to:

for %v in (*.mov) do ffmpeg -i "%v" -vcodec h264 -acodec aac -strict -2 "%~nv.mp4"


  • make sure to double up all the %%v if you put in .cmd batch file
  • ffmpeg is a very popular 3rd party command line util. I get mine from here.

Update 2015-07-18: cropping 3D movies down to single image

ffmpeg -i "in_movie_file.ext" -vf "crop=960:800:0:0,setdar=4:2" -vcodec h264 -acodec aac -strict -2 "out_movie_file.mp4"
  • obviously check the real resolution before setting the crop… just divide it by 2
  • “setdar” is the aspect ratio… i found it was necessary… one way to find it is with VLC CTRL-J on the original video

VLC will do this via a command line like so:

"c:Program Files (x86)VLCvlc.exe" -vvv %1 --sout=#transcode{acodec=mpga,vcodec=h264,venc=x264,deinterlace,vfilter="rotate{angle=270}"}:standard{mux=mp4,dst="%~n1.mp4"}, vlc://quit


  • I’ve had to remove the acodec=mpga for my iPhone MOV’s or else I get garbled audio.
  • I included the vfilter=”rotate…” for rotation syntax since it was so hard for me to find but only include if you want rotation.

However, I noticed that VLC chops off the last 2 seconds no matter what I do… it seemed a little better choosing a different vcodec but h264 is too rocking to use anything else.

So I wound up going with QuickTime as my go-to transcoder for now.  It doesn’t truncate any video and creates a slightly smaller output file than VLC.  The compression is dramatic and h264 does an awesome job with preserving quality… even while maintaining 1280 x 720 HD, a 100MB MJPG will go down to a 5MB h264/MPEG file.

Following code stolen from here and tweaked a little, automates the QuickTime COM API to convert a directory full of MJPG’s (see sample code for Chapter.8 > “BatchExport.js”).

There’s no reason why this shouldn’t be in PowerShell… it’d be interesting to see if it was any more readable.

//    Written by    :    John Cromie
//    Copyright    :    ? 2006 Skylark Associates Ltd.
//    Purchasers of the book "QuickTime for .NET and COM Developers" are entitled   
//    to use this source code for commercial and non-commercial purposes.                   
//    This file may not be redistributed without the written consent of the author.
//    This file is provided "as is" with no expressed or implied warranty.
function unquote(str) { return str.charAt(0) == '"' && str.charAt(str.length - 1) == '"' ? str.substring(1, str.length - 1) : str; }
// Run from command line as follows:
// cscript BatchExport.js , , , , , 
var sourcePath, destPath, configXMLFilePath, convertFileExtension, exporterType, exportFileExtension;
// Get script arguments
if (WScript.Arguments.Length >= 4)
    sourcePath = unquote(WScript.Arguments(0));
    destPath = unquote(WScript.Arguments(1));
    configXMLFilePath = unquote(WScript.Arguments(2));
    convertFileExtension = unquote(WScript.Arguments(3));
    exporterType = WScript.Arguments(4);
    exportFileExtension = WScript.Arguments(5);
//sourcePath = "D:QuickTimeMoviesBirdsKittiwake";
//destPath = "D:QuickTimeMoviesExportDest";
//exporterType = "BMP";
//exportFileExtension = "bmp";
// Sanity check arguments
var fso = WScript.CreateObject("Scripting.FileSystemObject");
var e = "";
if (!fso.FolderExists(sourcePath))
    e += "Source path does not exist : " + "[" + sourcePath + "]n";
if (!fso.FolderExists(destPath))
    e += "Destination path does not exist : " + "[" + destPath + "]n";
if (!fso.FolderExists(configXMLFilePath))
    e += "Config XML file path does not exist : " + "[" + configXMLFilePath + "]n";
if (convertFileExtension == undefined)
    e += "No convert file extension supplied!n";
if (exporterType == undefined)
    e += "No exporter type supplied!n";
if (exportFileExtension == undefined)
    e += "No exporter file extension supplied!n";
if (e != "")
    WScript.Echo("cscript BatchExport.js , , , , , ");
// Launch QuickTime Player   
var qtPlayerApp = WScript.CreateObject("QuickTimePlayerLib.QuickTimePlayerApp");
if (qtPlayerApp == null)
    WScript.Echo("Unable to launch QuickTime Player!");
var qtPlayerSrc = qtPlayerApp.Players(1);
if (qtPlayerSrc == null)
    WScript.Echo("Unable to retrieve QuickTime Player instance!");
// Set up the exporter and have it configured
var qt = qtPlayerSrc.QTControl.QuickTime;
var exp = qt.Exporters(1);
exp.TypeName = exporterType;
// settings file...
var FileSystemObject =  WScript.CreateObject("Scripting.FileSystemObject");
var configXMLFileInfo;
if ( FileSystemObject.FileExists(configXMLFilePath) )
    configXMLFileInfo =  FileSystemObject.OpenTextFile( configXMLFilePath );
// if settings files exists, load it and assign it to the exporter
if ( configXMLFileInfo )    {
    var configXMLString = configXMLFileInfo.ReadAll();
    // cause the exporter to be reconfigured
    var tempSettings = exp.Settings;
    tempSettings.XML = configXMLString;
    exp.Settings = tempSettings;
} else  {
    //otherwise, get the settings from the user dialog and save them to xml file for subsequent runs
    var configXMLString = exp.Settings.XML;
    configXMLFileInfo = FileSystemObject.CreateTextFile( configXMLFilePath );
    if ( configXMLFileInfo )  {
    } else {
        WScript.Echo("Unable to create config XML file : " + "[" + configXMLFilePath + "]");
var fldr = fso.GetFolder(sourcePath);
// Regular expression to match file extension
var re = new RegExp("."+convertFileExtension+"$", "i");
// Iterate over the source files
var fc = new Enumerator(fldr.Files);
for (; !fc.atEnd(); fc.moveNext())
    var f = fc.item().Name;
    // Filter by file extension
    if (!re.test(f))
        // Open the movie and export it
        var mov = qtPlayerSrc.QTControl.Movie;
        if (mov)
            // Strip file extension and compose new file name
            f = f.replace(/.[^.]*$/, "");
            var fDest = destPath + "" + f + "." + exportFileExtension;
            exp.DestinationFileName = fDest;
            WScript.Echo("Exported: " + fDest);
    catch (err)
        WScript.Echo("Error Exporting: " + fc.item());    
// Tidy up

Considering Home Network Storage Alternatives

My current bottom line is that I’ve got a 6 x SATA ICH9R just sitting there on my main Windows 7 machine’s mobo for free so I slapped on 2 TB x 2 in RAID1, published a few shared folders and leave that machine powered on 24/7. After everything else (optical & OS drives) I had two ports left doing nothing so the previous gen 750GB’s x 2 are in RAID0 receiving scheduled backups for a little more cheap peace of mind. I’m hoping by the time I actually need more space, that there will be something along the lines of a 5-bay Drobo engineered around SATA 3.0 (6 Gb/s) internally and USB 3.0 (5 Gb/s!!) externally to finally give us some serious speed for that $700 price point. My big up front consideration: NAS vs DAS

  • What’s better, a true stand alone NAS box –OR- a large/fast DAS array shared from your primary machine???
  • FOR THE HOME scenario: I always go back to preferring DAS connected to my main beefiest workstation/”home-server”
  • You get to rally the performance wagons around at least one location where you have absolute top end HDD access when you want it…
  • If you go with a NAS, you basically accept that GbE is your top end… true, even DAS RAID0 HDD configs generally level out around 100MB/s average xfer rate which is basically the GbE saturation point (1 Gb/s = 125 MB/s minus some packet overhead puts you right around 100 MB/s)… but sequential burst rates can go upwards of 300MB/s (2.4 Gb/s) … so I believe NAS over GbE could very well prevent your drives from spitting the bits as fast as they’re capable.
  • After chasing NAS box performance specs for a while you start to realize that the end game is basically spec’ing out a mid-range PC… so that’s why I can’t stop swinging back to throwing my money at the primary machine’s horsepower and just leave that powered up all the time to share files.
  • My current working scenario is based on a main machine that’s sits at the center of our home’s media universe as the do-it-all living room media player… projector, good speakers, VLC, iTunes, etc… after that, it’s a matter of streaming (primarily video) wirelessly for individual needs (internet tablet, wifey’s PC, etc)… even if I did have the luxury of hiding that main machine somewhere other than the main living space, I think I’d just roll with a cheapo networked media player (e.g. Western Digital TV) in the living room with network storage requirements still covered by the main box.
  • Invariably one wants to share a few things out on the internet as well as around the home… my config readily lends itself to accomplishing this from simple IIS Directory Browsing up to a full blown photo gallery (PHP/MySQL based zenPhoto, love it!!)… other NAS boxes (Synology, etc.) market themselves on more and more “server” oriented features, but why fuss with learning and navigating around the limitations of various embedded linux flavors when you can have the full power of your primary machine’s OS to load up all kinds of goodies?? e.g. Synology’s built in photo gallery is nice but open source is always going to be ahead of the game
  • Another consideration: you don’t hear much talk about virus checking and NAS… maybe I’m worrying about this too much but full scans are something that one must do from time to time… ok yes, most of what we’re putting out there is going to be non executable media that doesn’t require scanning… but being a developer, I’ve developed a fairly extensive library of software that I like to have on hand… it’s doesn’t add up as fast as movies but it’s substantial… and apparently even JPG’s can get viruses… the thought of scanning all those files over the wire (repeatedly) just doesn’t appeal to me.
  • I like the idea of running a reasonable database in this space… granted the optimal database drive configuration is not the same as your primary storage volume –BUT- you do still benefit from having those byte buckets near each other for backups and such
  • [29 Sep 2010] Another one hit me: We finally have full symbolic/hard-link flexibility under Windows 7 NTFS… we can cross phyiscal drives with a link, etc… this allows full granularity to choose exactly what consumes the more valuable RAID1 space but still symlink anything into the same visible folder hierarchy… e.g. a single “movie” shared folder is physically comprised of “classics” subfolder (hosted on RAID1) in addition to “unwatched” (hosted on RAID0)… Shell Link Extension makes symlinks awesomely convenient to create with Windows Explorer.
  • For the HOME sized problem: There starts to be a pile of compelling reasons in favor of connecting the physical storage to the main CPU horsepower over the highest bandwidth possible

Pertinent specs:

  • MB/s = MegaBytes per second, Mbit/s & Mb/s = MegaBits per sec, GbE = GigaBit Ethernet, Gb/s = GigaBits per sec
  • Notable NAS vendors: Synology, QNapBuffalo, LaCieHP, Acer, AsusNetGear, Cisco, ZyXEL
  • Performance rundown of many popular NAS boxes
    • RAID0 based units hold the crown – and nothing tops out much over 100MB/s read or write
    • Didn’t realize the Qnap’s were kicking so much arse
    • The NetGear seems to be the champ but she’s pricey (see my note about their X-RAID technology below under Holy Grail)
  • HD Video Streaming, minimum required bandwidth: in the ballpark of <10MB/s (per client)
    • Blu-ray spec max data transfer rate = 54 Mbit/s (~7 MB/s)
    • HD DVD spec max data transfer rate = 36 Mbit/s
The Holy Grail (at the raw storage level):
  1. Single Volume – a single logical storage pool
  2. Redundancy – at least single drive failure redundancy (with RAID 5 style efficiency)
  3. Different Size Drives – we all want to take advantage of the biggest/cheapest drive available from one year to the next

These are the only options I’m currently aware of:
  • Drobo
  • Windows Home Server
  • NeatGear has something called X-RAID2 in their ReadyNAS line that looks pretty good as well… 6 bay Pro model (empty) = $1000 street <yikes>
  • zFS – Solaris only…various OpenSolaris based versions out there… people do run it under a Windows VM with some success but seems clunky
  • BeyondRAID is like RAID 5 striping & redundancy yet with the freedom of on-the-fly swapping of any drive size
  • Pre-emptive, automatic self healing
  • Tool-less, Tray-less HDD slots
  • Sexy Health lights
  • OS X TimeMachine compatible
  • Downsides:
    • – a bit pricey (5 bay, eSata “Drobo S” = ~$700 empty!) … i feel like they’re charging about $100-$200 over average hardware for their secret sauce
    • – unfortunately it’s run of the mill speedy (60-90 MB/s over eSATA)… too bad we can’t justify the cost with some extra performance
    • – unavoidably it’s running a proprietary format in order to work its magic … the million dollar questions is: What is Drobo’s track record now that they’ve been out there a while??  Definitely need to dig up some solid reliability satistics…  If it ever does totally puke on you, you’d have to wait for a replacement unit to drop in your drives and see what’s still there… and after that, only Data Robotics Inc can possibly save you and it’ll cost you.
    • but is this really any different than RAID5?  RAID is pretty much the same vendor specific lock-in isn’t it??… if your RAID controller up and dies (for me that’d be my mobo 😐 … you’d have to obtain nearly identical duplicate hardware to salvage your drives… apparently you can migrate across same vendor like ICH9R –> ICH10R which does give slightly more flexibility
Windows Home Server
  • You can install PHP
  • It does run fine in a VM
  • OS X TimeMachine compatible
  • – When you add a drive you must designate it as either Storage or Backup (the Storage pool offers no redundancy)
  • – Obnoxious – there’s something whacky about how it does not balance allocation very well across available drives
  • WHS “v2” aka “Vail” due sometime 2010 (V2 is Windows 2008 based, V1 is Windows 2003 based)
  • Great dissection
    • v1 was basically a fancy tack-on above NTFS – “Drive Extender was the biggest component of the secret sauce that made WHS unique from any other Microsoft OS. It was Drive Extender that abstracted the individual hard drives from the user so that the OS could present a single storage pool, and it was Drive Extender that enabled RAID-1 like file duplication on WHS v1. Drive Extender was also the most problematic component of WHS v1 however: it had to be partially rewritten for WHS Power Pack 1 after it was discovered that Drive Extender was leading to file corruption under certain situations.
    • v2 Drive Extender is now ‘below’ NTFS… proprietary block based storage… single file can/will be spread across multiple disks (“chunking”)
      • biggest downside is that you can no longer just plop a WHS drive in another server to pull files in an emergency
      • chunking means that you’re in a more RAID0 like risk category for your main storage
      • enables backup of open files… to me, Drive Extender v2 provides similar freedoms to what Volume Shadow Copy provides us elsewhere
    • Great stuff in the many comments:
      • This comment basically sums up my WHS vs Drobo question => [RE: Almost there by davepermen on Wednesday, April 28, 2010, on comment page 2] – “in storage-loss for the security, raid5 is superior. if all your data is in duplication mode on whs, it needs 2x the storage space. raid5 needs "one additional disk".” … so Drobo is more like WHS flexibility + RAID5 reliability… so they really are the only game in town and hence the price.
  • Generally accepted as a solid WHS implementation: HP Storage Works x510 (rebranded MediaSmart EX495)


Richard Feynman (Nobel Physicist, 1918 – 1988)

Richard_Feynman Just kinda catching up with how “fun smart” this guy was… worked on the Manhattan project, all kinds of creative physics problem solving, “Original Prophet of Nanotechnology”, Nobel prize in Physics 1965, liked strip clubs, art and bongo drums… there are at least two semi-auto biographies out there in public circulation… I’m reading “Surely You’re Joking, Mr. Feynman!” right now… also a few enjoyable BBC Horizon videos featuring a fair amount of direct interview content: “The Pleasure of Finding Things Out (1981)”, “The Quest for Tannu Tuva (1988)” and “No Ordinary Genius (1993)

Very interesting (old) BBC series by James Burke – tracks the thread of inventions underlying our specialized society
I’ve watched episodes 1-4 so far… 4 is a pretty good one
Simply starting at the beginning seems good too
Make sure you take advantage of the preconfigured playlists — look for “(play all)” — so they queue up and you can watch them straight through w/o having to continually find the next one — which really takes away from the enjoyment after a while
Search for “james burke episode xxx” to dial in on each bundle if you’re not seeing it from the URL I gave above… there appear to be at least up to 20 episodes
(btw: My buddy Joel turned me on to it… he’s full of nifty idears… here’s a gratuitous plug for his vlog site: