How to Convert Quicktime MOV Video Files to MPEG-2

[Update 1: Fixed bugs in the batch file and made it available for download]
[Update 2: Wildcards are now supported]
[Update 3: Timestamps are now copied from source to destination files. For this, touch.exe is needed.]
[Update 4: File names with spaces in them are now handled correctly]

I recently bought a new compact digital photo camera, Panasonic’s Lumix LX3. Although I acquired it solely for its still image capabilities, I quickly discovered that it records video in very high quality, especially when compared to my digital video camera, a JVC model equipped with a hard disk on which video files are stored in MPEG-2 format in DVD resolution.

The major downside to the new LX3: the format in which video files are stored. For some reason Panasonic chose Apple’s Quicktime format. This essentially means that only Apple’s Quicktime software can play those files. That is far too inflexible for me. I need a video file format that can be played and edited with different applications, both today and in 20 years. I do not want to be caught in a format trap, like, for example, owners of Video 2000 equiment (remember that?).

I decided some time ago to store video footage in MPEG-2 format only. MPEG-2 is the format used on DVDs. Although these are soon to be replaced by Blue Ray Discs which employ a different codec, I am confident enough to be able to play and edit MPEG-2 even in 10 or 20 years time.

That left me with the question of how to convert Quicktime MOV files to MPEG-2.

Requirements

My camera creates .MOV files. The video stream is encoded as MJPEG, a simple codec that creates large files since compression is low. Here is some technical data on the format:

  • Video resolution: 1280×720
  • Aspect ratio: 16/9
  • Frame rate: 24 fps
  • Video codec: Quicktime MJPEG
  • Sound: 1 channel (mono), 16 kHz
  • Audio codec: uncompressed (PCM)

Since I only want to convert the video format, downscaling the resolution was out of the question. The resulting MPEG-2 file must retain the original resolution of 1280×720 pixels.

Research

I downloaded and tried out evaluation or free versions of the following programs. All are capable of reading MOV files and converting them to MPEG-2.

  • MP4Cam2AVI, free
  • AVS Video Tools, commercial
  • Magix Video Deluxe 15, commercial
  • SUPER, free, but dubious website
  • MainConcept Reference, commercial

Unfortunately none met my requirements. At first, the free MP4Cam2AVI looked perfect. But then it refused to read one of my video files which Quicktime played without complaint. The commercial AVS and Magix are limited to DVD resolution (720×576), which also applies to SUPER. MainConcept worked flawlessly in my tests and I was nearly convinced I would have to hand over € 290 to the manufacturer when I discovered a free alternative.

Solution

The MPlayer/MEncoder combo is a powerful toolkit for playing and encoding digital video. It has all codecs built it and does not rely on DirectShow, Video for Windows or any other framework. The best thing of all is that it is free and open source. Not even installation is needed. Just download and unpack it to any folder you like.

The downside of both MPlayer and MEncoder is that they are command line tools. This is especially true for MEncoder since it offers literally hundreds of settings which are controlled by equally numerous command line switches. That makes MEncoder extraordinarily difficult to use. Add to that the sparse documentation and you know why only few people use MEncoder directly. For that reason I was not able to find sample scripts for what I needed to do.

It took me some time to figure out which parameters to feed to MEncoder to make it do what I wanted. In oder to simplify the process in the future I wrote a batch script that takes the path to a MOV file, invokes MEncoder with the correct switches to make it convert the file to MPEG-2 and place it in the original file’s folder with the extension MPG.

Explanation

The first half of the script consists of comments. Please read those before putting it to use.

At the real start of the script various variables are set. You can adapt them to your needs, for example if you have input files with a differing resolution. However, you should leave LAVC_OPTIONS and MPEG_OPTIONS alone, unless you know what you are doing.

The script loops through all input files matching the input specification (a file system path that may contain wildcards). For each matching file, the script then checks for existence of the output file. This is a safety, since MEncoder will overwrite its output file without asking for confirmation. After that, MEncoder is invoked to create the MPEG-2 output file. Finally, touch.exe copies the timestamps from the source to the destination.

How to Use it

  1. Download the MPlayer binaries and unzip them to a folder of your liking
  2. Download Touch from Sourceforge and unzip it to the folder to which you unzipped MEncoder.exe
  3. Download the batch file and save it in the same folder to which you unzipped MEncoder.exe
  4. Open a command line (type cmd.exe at Start->Run)
  5. Switch the current directory to the folder containing “MEncode.cmd”
  6. Start the conversion of a MOV file by entering MEncode file.mov, or, to convert multiple files MEncode “C:\Videos\New Files\*.mov”

, , , , , ,

43 Responses to How to Convert Quicktime MOV Video Files to MPEG-2

  1. Maksym November 6, 2008 at 19:33 #

    Nice sript, thanks! Though on my PC it did like %~dpn1.mpg – haven’t figured out why yet – replaced it with 1.mpg for now.

  2. Helge November 7, 2008 at 09:53 #

    Maksym,what error did you get with %~dpn1.mpg? And which OS are you using?That syntax should work on any Windows OS from NT4 upwards, I do not know about 9x, though.

  3. Amauris November 24, 2008 at 00:46 #

    Thanks for the helpful script. It works also fine for my Lumix FX35. Except for one file with a length of only 1,1sec and a size of 3,26MB. The destinatin filesize is always 0MB and cannot be played. Any ideas?

  4. Helge November 24, 2008 at 09:48 #

    Amauris,what is the output you get from MEncoder.exe on the command line? Could you post that, please?

  5. Peter November 30, 2008 at 22:45 #

    Thanks for finding this tool and your script, Helge – works great (on x86 Vista).I’m have Lumix TZ5, and realized that it makes some nice videos as well (minus the audio which is pretty poor).Gruss aus Redmond, WAPeter

  6. yang December 7, 2008 at 18:53 #

    Hallo Helge,ich habe gerade eine LX3 nicht zuletzt wegen ihres HD-Video gekauft. Aber ich kann die Videofiles nicht weiterverarbeiten (sprich einen Film erstellen) wegen dieses unerwünschten QuickToime-Formats. Deine Lösung hört sich gut an, aber ich bin schon beim 1. Schritt auf Schwierigkeit gestoßen, weil die folgende Link nicht mehr Up-to-Date ist. http://www.mplayerhq.hu/design7/dload.htmlKannst Du mir helfen?Viele Grüße,Yang

  7. Helge December 8, 2008 at 13:44 #

    Yang,please post in english.The download link for mplayer/mencoder works for me.

  8. yang December 10, 2008 at 22:33 #

    Hi, Helge!I finally succeeded in running your script. Many thanks for the detailed description.I’ve got some questions: (1) Is it possible to create a better output by using a higher bit rate, say min=16000 b/s max=26000 b/s, or it doesn’t make sense to choose such a high bit rate?(2) Is it possible to increase 24p to 30p?(3) Is there a simple way to convert only the sound of the MOV-file into a WAV-file or MP3-file?Best regards,Yang

  9. Helge December 11, 2008 at 11:03 #

    Yang,good to hear it works now.To your questions:1) You can indeed change certain parameters used by the script. In order to do that, locate the section below “::Variables used during encoding”. Modifying VIDEO_BITRATE and VIDEO_BITRATE_MAX sets the minimal and maximal bitrate of the resulting MPEG-2 video. Depending on the quality of the input video and your expectations/requirements you may increase or lower these values.2) The framerate of the resulting video must match the framerate of the original (input) video or audio and video will be out of sync. So this basically depends on your camera’s format.3) Stripping the sound from the MOV file and writing it to a separate (MP3) file is something I have not looked into, so I cannot give you tips on how to do it.

  10. ken3830 December 13, 2008 at 17:01 #

    Once I figured out that I have to download the “outdated” mplayer binaries and not a package, it was quite easy to set up.Cheers. Now I have to research more and find out how to rebuild it from source and how to access its API from Java or VB!

  11. ken3830 December 19, 2008 at 17:50 #

    I am getting the buffer overflow that is mentioned in the command file. It says to increase the abuf_size from 4 to a larger value.But abuf_size appears to be set to 8 despite the buffer overflow stating the buffer is 4096.Am I being niave. Sorry.

  12. Helge December 19, 2008 at 22:21 #

    Ken3830,I only figured this out after looking at the source code of mencoder. As mentioned in the batch file, abuf_size needs to be increased from its default of 4. The value 8 worked for me, but for your files higher values may be necessary. Try setting abuf_size in MPEG_OPTIONS to 12 or even higher.

  13. ken3830 January 10, 2009 at 09:25 #

    Helge,I have just noticed that I am losing the last 20 secs or so of my video clips. The clip is about 30 secs long. The last bit is really the bit I want! It is a 1280 x 720 .mov file and I am using your original mencode.cmd file.Any ideas. Thanks.

  14. Dave January 24, 2009 at 07:38 #

    Thanks for the script and the software reference. It works well, very impressed with the quality of the conversions, particularly where the source file is avc or avchd. I’ve tried various software programs and they usually give a noticeable drop in picture quality when converting avc to mpeg2.Just out of interest I made a couple of changes to your script.1. Removed frame rate setting which results in frame rate of source file being used (which is what I prefer)2. Added -vf scale=720:576 into the main command line (mencoder…)to produce a PAL compatible mpeg2 file (which can be used to author and burn a DVD).I can supply a copy if you are interested.

  15. Bruce Kahn March 12, 2009 at 22:35 #

    I very much like the idea of this script, and thank you for writing it. Here are some of my observations/issues.Initially, I had trouble locating the MEncoder.exe file. Most of the links didn't include it.Unfortunately, this batch file seems to be acting very flaky for me, and I can't trust the results. Any help would be appreciated.Initially, I used a small file to try it and got 0 file size (like Amauris). When I use larger files, I get output, but it is very deceptive. When I play the .mpg files they say that they are the same length as the original .mov files, but the end of the original file is actually cut off. So apparently, the encoded portion is being "stretched" to fit the desired length or something like that. This could be the same problem of missing the last 20 seconds that Ken3830 reported.Here is some sample outputMEncoder GIT-6e54f40-4.2.1-sjlj-Kovensky-mt 20090304 (C) 2000-2009 MPlayer Teamsuccess: format: 0 data: 0x0 – 0x5f1315libavformat file format detected.[lavf] Video stream found, -vid 0[lavf] Audio stream found, -aid 1VIDEO: [mp4v] 1280×720 24bpp 30.000 fps 0.0 kbps ( 0.0 kbyte/s)[V] filefmt:44 fourcc:0x7634706D size:1280×720 fps:30.000 ftime:=0.0333==========================================================================Opening audio decoder: [alaw] aLaw/uLaw audio decoderAUDIO: 16000 Hz, 1 ch, s16le, 128.0 kbit/50.00% (ratio: 16000->32000)Selected audio codec: [ulaw] afm: alaw (uLaw)==========================================================================PACKET SIZE: 2048 bytes, deltascr: 43885MPEG MUXER, patching resolution to 1280×720 framerate to 24 fps aspect ratio to 16/9Opening video filter: [expand osd=1]Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 8==========================================================================Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec familySelected video codec: [ffodivx] vfm: ffmpeg (FFmpeg MPEG-4)==========================================================================VDec: vo config request – 1280 x 720 (preferred colorspace: Planar YV12)VDec: using Planar YV12 as output csp (no 0)Movie-Aspect is 1.78:1 – prescaling to correct movie aspect.videocodec: libavcodec (1280×720 fourcc=3267706d [mpg2])[VE_LAVC] High quality encoding selected (non-realtime)!…BUFFER UNDEFLOW at stream 0, raising muxrate to 11088 kb/s, delta_scr: 39896BUFFER UNDEFLOW at stream 0, raising muxrate to 12196 kb/s, delta_scr: 36269Flushing video frames.Writing index…Overhead: -0.000% (28892889245286400 / 215609969599315968)Writing header…Video stream: 10668.328 kbit/s (1333541 B/s) size: 10112686 bytes 7.583 secs 183 framesAudio stream: 112.000 kbit/s (13999 B/s) size: 85344 bytes 6.096 secs

  16. D.F. April 13, 2009 at 05:02 #

    Thanks for this posting. i, too have a lumix. i, too, only bought it for still pix, and discovered the video aspects of it. i found dealing with the huge .MOV files awkward. thanks for the MPlayer links!

  17. Glam_Fakir April 29, 2009 at 03:52 #

    Hello Helge, I hope this thread is still active. I’m struggling with locating MEncoder.exe.I managed to download a more recent version of MPlayer to my PC but I cannot find any mention of the Encoder when I search for the .exe file.I have put the touch.exe file inside the MPlayer folder but I followed your cmd instructions and the file was not recognized. I admit I am out of my depth here but I need something to convert mov to mpeg1/2 for a college video project which I am doing.Thanks for your help.Vielen Dank und freundliche GruesseGeorge

  18. Dave April 29, 2009 at 10:42 #

    I found the Windows files a while ago but I have discovered recently that they are no longer in the main table on the Download Source & Binaries page.. If you click on Old Releases link just below the main table, then select the win32 directory and download MPlayer-mingw32-1.orc.zip (about 10M), you should be right.Dave

  19. Ian Johnson May 1, 2009 at 22:34 #

    What would I add to this script to delete the source files after the conversion has finished? Where can I go to learn how to change the settings for Divx output? Do you know if this version of mencoder would handle avchd?I just got a Lumix TZ7 and have been looking for just this kind of thing. It shoots HD in MJPEG or AVCHD. My media center is too old to handle playback of AVCHD or HD sized MJPEG. I would love to have a script that runs as a scheduled task that can check the folder for .movs, convert then delete them.

  20. Dave May 11, 2009 at 11:28 #

    IanI had a similar requirement with the TZ7 camera. I can supply a couple of scripts to convert 1280×720 MJPEG or AVCHD files from the TZ7 to PAL standard MPEG files (720×576, 25Hz). I can also indicate how to delete the source file but I wouldn’t recommend it unless you have the originals saved away somewhere else. I would be keeping the HD files for the future. Afraid I can’t help with DivX. If you want to supply your email I can send the scripts. I don’t know how to provide a download through this blog.

  21. ken3830 May 11, 2009 at 19:47 #

    I have just downloaded a utility that does .mov to .avi and probably much more. Its an exe that has all its codecs etc. in its own directory, so its not dependant on anything else. Looks good and seems fast compared to others I’ve tried.MP4Cam2AVIJust google it for the download. It’s free and open sourced as well.Cheers

  22. Helge May 12, 2009 at 09:19 #

    ken3830,as I have written in the article, I have tried out MP4Cam2AVI. The description of the tool sounded very good, indeed, but it would not read all of my MOV files. Which version did you try?

  23. Mark May 18, 2009 at 22:08 #

    Finding this tool very useful, thanks.Is a script available for PAL/DVD compliant conversions?

  24. Dave May 21, 2009 at 22:12 #

    MarkI started with Helge’s script and experimented with some modifications to produce PAL DVD compliant mpeg files. I use one of these scripts with AVCHD files from my new Panasonic TZ7 camera. I edit and author the mpeg files in MPEG Video Wizard software which has the advantage that it does not re-compress compliant mpeg files.The modifications to Helge’s script involve rescaling to 720×576,changing the frame rate to 25 fps and changing the video bitrate to comply with the PAL DVD standard. I have a few different scripts for different types of camera file. What sort of camera files are you using ? If you are interested let me know and I can supply copies of my scripts.

  25. Kar Gee June 30, 2009 at 17:18 #

    Hi,I'm trying to edit the resulting MPEG-2 file using Ulead VideoStudio, but unfortunately, I can only edit in a 25 fps environment, whereas the output from MEncode still keeps the file at 24 fps. Is there any way to convert the frame rate?

  26. Gordon July 14, 2009 at 00:07 #

    Helge,Thanks for sharing your script. I have been trying (unsuccessfully) to use it to convert some low resolution video from an old Kodak digital camera. I'd really appreciate any help on resolving my problem.I have altered some of the encoding variables in the batch file to match the input video::: Variables used during encodingset X_RES=320set Y_RES=240set ASPECT_RATIO=4/3set FRAMERATE=20set VIDEO_BITRATE=12000set VIDEO_BITRATE_MAX=16000set AUDIO_FREQ=16000set AUDIO_BITRATE=128set AUDIO_CHANNELS=1Here is an example of the error I get:C:\Program Files\mplayer>Mencode c:\video\100_9998.movMEncoder 1.0rc1-3.4.2 (C) 2000-2006 MPlayer TeamCPU: AMD Athlon(tm) XP 3200+ (Family: 6, Model: 10, Stepping: 0)CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 0 SSE2: 0Compiled with runtime CPU detection.Option mpegopts: Unknown suboption interleaving2Error parsing option on the command line: -mpegoptsExiting… (error parsing command line)Cannot open c:\video\100_9998.mpg. Error: 2Any idea why it is stumbling on the interleaving2 suboption? I tried removing interleaving2 from the cmd file and it then stumbles on the abuf_size suboption.Thanks,Gordon.

  27. Poliklinik July 17, 2009 at 18:59 #

    Great job.Easy and clever.Thanks,this is a usefull complement our panasonic cameras.

  28. Dave July 21, 2009 at 10:08 #

    Reference Kar Gee's question. First change the FRAMERATE setting in Helge's script to 25. Then, in order to maintain A/V sync, add the command -fps 25 to the mencoder command line.

  29. Computer Bit July 25, 2009 at 05:34 #

    Hello All,I am trying to download MEncoder. I tried downloading it from: http://www.mplayerhq.hu/design7/dload.html However, I am unable to locate the exe file. All the bz2 files do not have the exe.Can someone please point me to the zip file containing the exe files?Thanks,Sam

  30. Dave July 28, 2009 at 11:38 #

    SamSee my comment dated 29 April above.Dave

  31. Kenton August 1, 2009 at 05:15 #

    I have downloaded and 'successfully' ran the cmd script. The problem I'm having is that it doesnt seem to quite work for my DMC-TZ1. My TZ1 differs from your LX3 by not having a x720 mode, my largest is 848x480x30fps. So, I changed your XRES, YRES and FRAMERATE accordingly.When I run it, it creates an mpg file, however it seems to skip some frames periodically, and the audio is out of sync.I can't seem to figure out how to copy and paste the mencode output, otherwise I'd paste it here.Any help?Thanks,Ken

  32. Dave August 3, 2009 at 21:58 #

    KenIf you want to email me a copy of your final script (see my profile for email address), I'll have a look at it to see if I can fix it. No guarantees though !Dave

  33. Rallymax August 5, 2009 at 19:30 #

    Thankyou SO MUCH for working out how to turn the MOV[MJPG+PCM] into legal MPG[M2V+PCM] for DVD.I've wasted 30+ hours trying to simply put footage from my DMC-FX35 onto a DVD to send baby pictures to my mum. RRRR! (and I used to be a video professional!)I have some of the footage at 10fps not 30 (b/c I was running out of SD space). Unfortunately after running the script the 10fps plays back fast.Do you know of the command argument to re-encode at a different framerate?GREAT SCRIPT!!!btw, I had a HARD time getting an MEncoder.exe binary and ended up getting it here:http://mediacoder.sourceforge.net/I've been using it to try to do the conversion but it isn't making legal MPG – Adobe ENCORE wants to re-encode and during DVD build it CRASHES Encore due to a bad end-of-mpg file problem in the source.

  34. Rallymax August 5, 2009 at 19:48 #

    I found that taking "-ofps %FRAMERATE%" out of the command line but leaving in the MPEG setting of "vframerate=%FRAMERATE%" worked.This is the ENGLISH MEncoder docs:http://www.mplayerhq.hu/DOCS/man/en/mplayer.1.html#CODEC SPECIFIC ENCODING OPTIONS (MENCODER ONLY)

  35. Jeff September 27, 2009 at 01:10 #

    I had some of the same problems as Kenton and fixed them as follows. I never would have gotten mencoder to work without this script!I have a Panasonic Lumix LZ5, so I changed the resolution to 640 by 480, aspect ration to 4/3, and framerate to 30. In the mencoder line I added -mc 0 after the -noskip: this was essential to preventing skipped frames. I also added -vf harddup. When there were other problems, this seemed to create enough frames so that audio and video stayed in sync, but harddup may not really be necessary any more.The most critical change was to change VIDEO_BITRATE from 12000 to 6000. I don't know what why that parameter worked, but it did!

  36. preske September 28, 2009 at 12:19 #

    I can't seem to get it to work.I'm getting "cannot open 'location-of-file.mov' Error: 2I can't translate the other error in proper english, but it is something like "mencoder wasn't recognized as an internal or external batchfile, program or 'something i can't translate'

  37. jaya April 4, 2010 at 13:30 #

    Hi. I was wondering why you used 112 for the audio bitrate when the LX3 produces files with audio in 256kbps. Does that make a huge difference? Thanks!

  38. Case April 22, 2010 at 11:08 #

    Hi. I have been looking for something like this for ages – found it through the LX3 blog. Thanks for taking the time to share it – Just have to see if I can get it to work now…

  39. Petals and Paws Photography July 15, 2010 at 16:02 #

    I'd like to email you privately Helge – however looking at your profile page, your email is no longer there.Does anyone have his email addy?I have LX-3 questions for him – thank you so much everyone. petalsandpawsphotography(at) yahoo (dot) com

  40. Petals and Paws Photography July 15, 2010 at 16:05 #

    http://blogs.sepago.de/helgealso, fyi – error on your techpage. stating out of date. I included the link to said error.

  41. Cis'land September 5, 2010 at 03:01 #

    Hello helge,I have this result, can you help me on thisThanks RolandoC:\mplayer>MEncode test.movMEncoder 1.0rc1-3.4.2 (C) 2000-2006 MPlayer TeamCPU: Intel(R) Core(TM)2 Duo CPU T7100 @ 1.80GHz (Family: 6, Model: 15, Stepping: 13)CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 0 SSE2: 0Compiled with runtime CPU detection.Option mpegopts: Unknown suboption interleaving2Error parsing option on the command line: -mpegoptsExiting… (error parsing command line)Cannot open C:\mplayer\test.mpg. Error: 2C:\mplayer>

  42. Wayne Shaddock September 18, 2010 at 21:00 #

    Greetings, Helge!I'm a bit confused when trying to sort out what I need to install to use mencoder on Windows 7. I'm guessing that the part at the beginning that says "For a complete MPlayer installation you will need sources, a set of binary codecs, and a skin if you want a graphical user interface" is referring only to Linux users.I'm pretty comfortable with command line stuff, but I'd sure appreciate a simple step-by-step on how to set this up so I can use your batch files to do some conversions from .mov to .mpeg2.I really don't have time for the learning curve on this. Trying to sort through all of the geek-speak is getting me grumpy! ;-)Wayniack!

  43. Guile November 15, 2010 at 22:03 #

    Today I discovered AviDemux (free) for other purposes (converting a m2ts file). However it’s also capable to convert MOV files with or without reencoding. Reencoding to MPEG2 is possible. I haven’t tried this yet. It’s even possible to put the MOV streams into an AVI file, so you can reencode with Virtualdub. Maybe worth a try.

Leave a Reply