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
- Download the MPlayer binaries and unzip them to a folder of your liking
- Download Touch from Sourceforge and unzip it to the folder to which you unzipped MEncoder.exe
- Download the batch file and save it in the same folder to which you unzipped MEncoder.exe
- Open a command line (type cmd.exe at Start->Run)
- Switch the current directory to the folder containing “MEncode.cmd”
- Start the conversion of a MOV file by entering
MEncode
file.mov
, or, to convert multiple filesMEncode "C:\Videos\New Files\*.mov"
46 Comments
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.
iDealshare VideoGo can convert QuickTime unplayable MOV to QuickTime compatible MOV or MP4 on Mac or Windows.
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.
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?
Amauris,what is the output you get from MEncoder.exe on the command line? Could you post that, please?
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
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
Yang,please post in english.The download link for mplayer/mencoder works for me.
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
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.
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!
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.
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.
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.
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.
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
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!
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
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
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.
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.
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
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?
Finding this tool very useful, thanks.Is a script available for PAL/DVD compliant conversions?
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.
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?
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.
Great job.Easy and clever.Thanks,this is a usefull complement our panasonic cameras.
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.
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
SamSee my comment dated 29 April above.Dave
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
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
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.
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)
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!
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'
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!
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…
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
http://blogs.sepago.de/helgealso, fyi – error on your techpage. stating out of date. I included the link to said error.
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>
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!
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.
You may want to convert some of the MOV files to MPEG (MPEG-1 and MPEG-2) for burning MOV to DVD for the DVD player or for some other MPEG-compatible video programs, for which a professional MOV to MPEG converter – Avdshare Video Converter is needed.
Avdshare Video Converter can Convert the MOV to WMV, ASF for compatibly playing or editing the MOV file in or on Windows Media Player, Windows Movie Maker, etc.