Upload High Quality YouTube Videos 16:9 Aspect Ratio (Widescreen) with Mencoder

After a lot of experimenting I finally found the settings that would allow me to upload a video to YouTube to be played in High Quality. This is for the 16:9 aspect ratio so if you are looking for the 16:9 settings, see Upload High Quality YouTube Videos 4:3. You will need Mplayer, and if you are on Windows, you may want to try out one of the GUI versions. Other platforms can see the Unofficial Packages. Mencoder is a very powerful command line video processor, for more help see the man page. I don’t pretend to know all of the video processing options, but i can explain the ones we are about to use. The basic command line is as follows:

mencoder -oac mp3lame -lameopts br=256 -ovc x264 -x264encopts crf=10:me=umh:subq=9:nr=100 -vf expand=:::::16/9,scale=1280:720 -of lavf -lavfopts format=psp -o output.mp4 input1.avi input2.mpg input3.avi

 

Mencoder can take multiple input videos and produce a single output video which I have shown in the example. The videos must be of the same size and framerate, but not necessarily of the same format. You must specify an audio encoder (oac) and a video encoder (ovc) to produce a new video.

The audio encoder we chose is the MP3 encoder -oac mp3lame, which is a very high quality audio codec. Next we specified some options to the encoder with -lameopts br=256 which specifies an audio bitrate of 256Kbps, which is pretty high. You could also encode this to AAC by specifying -oac faac -faacopts br=256. I leave my videos with stereo sound, YouTube can downmix to mono if they like.

Next, we specify the video codec with -ovc x264 which is recommended as MPEG4 encoding. Set options for the video codec with -x264encopts crf=10 which specifies a quality setting, NOT A BITRATE! The lower the crf, the higher the quality. I chose crf=10 just to use extra high quality. The documentation says that crf=0 is lossless, but I have not tested it and in my experience lossless encoding formats can be problemsome and waste space, time, energy, and sometimes money. For those of you who are hardheaded like me, you will spend hours playing with lossless formats before realizing that making video files that are 10x the necessary size, have zero difference in visual quality, and aren’t even lossless anyways due to colorspace conversions so don’t say I didn’t warn you! (But I did tell you just to screw with you and make you waste your entire day.) I do not change the FPS because my source video was 25 fps and YouTube highly discourages this. You need at least 24fps for high quality so if you want to change it, add -ofps 24 to your command line, but don’t blame me if your video plays like poop.

Some of my videos are not already in 16:9 aspect ratio, so I used the -vf expand=:::::16/9,scale=1280:720 option. This specifies two video filters. the first video filter converts to a 16:9 aspect ratio by adding black borders. This prevents distortion that would cause stretching vertically or horizontally by the second filter, which resizes the video nicely to the required 720p format needed by YouTube. If your video is already in 16:9 aspect, then just use -vf scale=1280:720. If your video is already in 16:9 aspect ratio and in 1280 x 720, then leave this out altogether.

By default, mencoder uses the AVI container format. A container format contains streams which may be audio or video. There will be a separate stream for your audio than for your video, separate codecs, everything is separate. I could not get YouTube to accept my videos for high quality in the standard AVI format, but I don’t know that I wasn’t doing something wrong. No matter, I switched to an MP4 container format and I am problem free. -of lavf specifies that we will use the container format code called lavf which is an internal code structure that just does container formats. There may be others to choose from, but this is the most useful. The lavf code produces several different container formats so we specify MP4 with -lavfopts format=psp. PSP videos use the MP4 container format, so that is what is was named for lavf's purposes.

-o output.mp4 input1.avi input2.mpg input3.avi specifies the output file output.mp4 as well as three input files. You could have just one input file, or you could have more than three. Just remember, the input files must have the same video size and framerate for this to work.

Good luck, and have fun waiting for uploading time with YouTube. Some have reported that it can take over 24hrs before YouTube can completely process high quality videos, but mine only took an hour or less. If you need 4:3 aspect ratio, see the Upload High Quality YouTube Videos 4:3.

Comments

Leave a Reply

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