Friday, January 2, 2009

Screen Capturing for YouTube

Edit: I'm happy to announce that YouTube increased the quality of their normal videos, so you don't need to be concerned with the bitrate anymore! This saves a lot of aggravation. Also note there's no need for a non-widescreen size like 480x360 in non-HD; instead use 640x360.

Making quality videos of screen capture is tricky, especially for YouTube. There is plenty of technical stuff in this guide but if you want better videos you have to learn it. It has to be complicated. You'll probably have to educate yourself on some of the terms used in this guide (because if I explained everything in detail this would be a book, not an article).

If you just want to push a button and make it work there's a big chance you're not gonna be happy with the results. Perhaps it's best for you to try another easier guide, and come back here if you're not satisfied. I'll wait. For anyone still reading, here's the outline: Avoid resizing, pick a screen capture method, capture in high quality, how to do this with CamStudio, render a YouTube version, *CHECK THE BITRATE*, and purposely increase the bitrate if necessary.

The whole screen doesn't look so hot in this size, does it?Avoid Resizing. I don't know what program you use to edit your videos. You must educate yourself on how your program handles cropping and resizing. There are too many programs and they cost too much money for me to help you on each of them. Especially with screen capture, knowledge is quality and resizing is a bigger enemy than cropping, in my opinion. For example, if you've ever used a TV-out card to display your monitor on a TV set, you know what I mean. When you take a whole monitor and resize it down to something smaller it won't look as good. Let me explain what cropping and resizing are so you'll get what the terms mean:

Let's say we have a monitor of one size, and a video of another. In most cases, a YouTube video will be smaller than your monitor. There are two ways to get to the new size: cropping and resizing. Cropping is chopping a part of the picture off, like a crop at harvest. Let's say there's a video of my whole monitor. If I crop it, I'd take just a part of it – and that would be the new size of the video. Obviously, you lose the part you cropped out. Resizing is taking an image and scaling it down – losing detail. Whenever you resize, you lose detail (well... almost always).

Pick a screen capture method for your video. I have three methods: one method for high quality and two methods for HD. You need to decide which strategy you think is best for your video.

Method 1: high quality. Advantages: It's the sharpest for the most people. Even people with slower connections (for broadband) can likely keep up without the video pausing to load more. The low quality version won't look that bad. If you want maximum compatibility, use this method. Disadvantages: It has a 4:3 ratio, so there will be black bars on the sides. Only a portion of your monitor is captured. Following the mouse pointer around is a bit like tunnel vision. Of course, you can zoom in and out if your screen capture software allows it. How to do it: Create a 480x360 video. Either capture a 480x360 box that follows the mouse pointer around, or capture the whole screen and crop/zoom/resize to a 480x360 box. Remember, the video will look sharpest at a 100% zoom 1:1 ratio, so try to stay there. Zoom out and resize sparingly – when you want the big picture.

Method 2: HD player size. Advantages: It's widescreen and fits in the HD player nicely. It's a compromise between the smaller high quality video and full screen HD. You get more screen area than with method 1. Disadvantages: It will never have the sharpness of the original capture because of the resizing involved. The tunnel vision isn't as bad as in method 1, but you're not making use of the full HD resolution. People with slower connections or slower computers will have problems playing the video in real time. The low quality version will look pretty bad. How to do it: Capture an 854x480 region (or 852x480 is your software doesn't like that size), then scale it to 1280x720 in your editor. Or capture the whole screen and crop/resize/zoom to 854x480 – then resize to 1280x720. As with method 1, avoid zooming and resizing. And be sure to strongly advise your viewers to watch in HD.

Method 3: HD fullscreen. Advantages: you can fit your whole monitor, or most of it, in the video. Some viewers with 1280 pixels wide monitors will get a beautiful crisp image, clear as method 1, but with much more screen area. This may be a good future-minded strategy, meaning even though it's not compatible with a lot of people today, years from now it may be. Disadvantages: As with method 2, slower connections and slower computers will make for a bad experience for some viewers. Also, for monitors that aren't 1280 pixels wide, it will ruin the beautiful crisp image that some people can see. The low quality version will look atrocious. So you will alienate 1) people watching in low quality 2) people with slower computers and slower connections 3) people with monitors that aren't 1280 pixels wide. How to do it: Capture your whole screen, then do the cropping/pillarboxing necessary to make the video 1280x720. If your monitor is really huge, you could also capture a 1280x720 box that follows the mouse pointer around the screen. And be sure to advise your viewers to watch in HD.

Capture in high quality. With almost any screen capture program you'll have the opportunity to choose the type of file you save. There are some good formats. There are some bad ones. Pick one that gives you the quality you like without filling your whole hard drive. Worry about the final YouTube encode later. Just focus on getting high quality screen capture. If it works for you, CamStudio Lossless codec is excellent. It may not work with all your software. If not, and you have a very big hard drive, try Lagarith lossless codec. It's top quality. Get it from freecodecs.com if you don't have it. Xvid (also at freecodecs.com) is good for smaller file sizes. Feel free to experiment with other formats. Just make sure it looks good. Remember, you can reconvert to something else later; right now it's just important to get high quality footage. Capture in a resolution that works for you. You can capture your full monitor and crop and/or resize later (which may be tricky depending on your programs), or capture just a portion of the screen. Choose wisely.

How to do this with CamStudio. You don't have to use CamStudio, but it's free. One note: I do not record the audio with CamStudio because I've found it to be glitchy. I used to open Audacity and record at the same time, then put it together later. Now I use a separate field recorder so there's not an extra window open. But I mix the WAV in later; CamStudio is used to capture video only.

Pick the size of the region.Under Region, select Full Screen if you want to capture the whole thing. If you choose that method, you'll probably have to crop or resize in the final video, which can be a pain when you constantly want the screen region to move. The advantages are: it makes a good master so if you want to reedit the video someday or change the size you can, and it gives relatively small file sizes. Weird, huh? That's because the recorded region never moves, so only things that move need to be stored (your mouse pointer, a window as you drag it). Likely most frames of the video will be a repeat of the previous frame, saving data.

Check Enable AutopanSelect region or choose full screen.To record just a region of the screen, tracking your mouse pointer, click on Fixed Region. Then you need to fill in the width and height you want. Use 480x360 for method 1, and 854x480 for method 2. Warning: your software may reject this size so you may need to use 852x480 instead. Next under options, check Enable Autopan, so it will follow the mouse pointer around. I put the Autopan Speed to 71. See if that suits you.

Video optionsUnder options, click Video Options. 24 frames per second is required for high quality or HD on YouTube, so set Playback Rate to 24, but you can choose another rate if you want. For example you could capture at 12 frames per second, saving space, then convert to 24 later so YouTube will give you the high quality option. I uncheck Auto Adjust. Set quality to the max: 100. Keyframes every 200 frames should be fine. If you'll be waving the mouse around a whole bunch you can lower it though. For 24fps I set Capture Frames Every to 42 milliseconds (a 24th of a second). For 12fps I'd choose 83, for 15fps I'd choose 67, for 30fps I'd choose 33. Now you need to select your compressor. Camstudio's codec is great (get it at their website) – just make sure it works with your editing software before using it. If so, OK everything and you're ready to record. If it doesn't...

Set to RGB mode Try Lagarith lossless codec if you've got plenty of hard drive space. Click Configure. Under mode, make sure it's on RGB. OK everything. You're now ready to record.

Xvid encoding optionsOr try Xvid. It's a great way to save file space with pretty good quality. Click Configure. Tune it as shown. A target quantizer of 1 is maximum quality. I usually leave it there, but you can raise it if you want for smaller files. One more thing with Xvid. Click Other Options. Then you must uncheck the box for Display encoding status. If you don't, there will be a super annoying box that blocks the screen and won't go away. OK everything and you're ready to record.Uncheck this to save aggravation.

Render a YouTube version now that you captured in high quality and edited the video if necessary. This time file size is an issue, unless you love long upload times. Pick a maximum bitrate that's at least 1000kbps (AKA 1Mbps), and higher if 1000 isn't satisfactory. You want it to look great without being so big it takes forever to upload. Xvid/H.264/x264/WMV are some great options to consider. Don't worry so much about the file extension (AVI/MOV/MP4/WMV), it's what's inside that counts. Remember my warning about resizing. It's okay if you zoomed in and out with your screen capture software, but remember the video will be sharpest at 100% zoom and a 1:1 ratio. Zoom out for the big picture but zoom back in when you want detail. Your video should now be either 480x360 (method 1) or 1280x720 (method 2 or 3). You're ready to upload, right? Edit: Right!

Always double check with MediaInfo!

[Remember: thankfully, this part is now outdated!] Wrong. CHECK THE BITRATE! “But Derek I already set the bitrate to 1000kbps so I know it's OK.” Not good enough. This is important. If you mess this up you won't get the watch in high quality or HD option and it will come out crummy. When you set a bitrate, you're setting a maximum bitrate, but it could be lower in reality. For example, here's a video I encoded. I set the bitrate to 10,000kbps. But look what MediaInfo says: in reality it came out to 86.5kbps! MediaInfo is a great way to double check. Once it's installed you can just right click on your video then click MediaInfo. Configure it to text view. Read the line for "Bit rate" under the video section (not under the General section, which includes the audio bitrate!). If you can't install MediaInfo on your system, read my blog on “How the Heck Do I Find the Bitrate of My Video?” (Short version: divide the file size in bytes by 128, then divide that by the length of the video in seconds, then subtract the audio bitrate – and you have the actual bitrate in kbps.) Once you have the number – if it's less than 1000kbps, you need to purposely raise the bitrate. If it is, you're done.

Purposely increasing the bitrate. Sometimes it takes some extra work to make the bitrate higher. What you need to do is add more keyframes. Don't do this in maximum, or target bitrate mode, or you could lose quality. It's okay to add keyframes when you're encoding in lossless mode, target quantizer mode, or quantizer based mode. Here's how in Xvid and x264. Find the place where you can adjust the codec's settings (usually there's a Configuration button).

Adding keyframes in Xvid

With Xvid set to Target quantizer (not target bitrate), Click more, under Quality preset. Now you can lower the Maximum I-frame interval.

Adding keyframes in x264With x264 set to single pass lossless mode under Analysis & Encoding, or Rate Control depending on your version, lower either Min and Max GOP size, or Min and Max IDR-frame interval. It's the Max we're concerned about, but often you have to lower both or it rejects your changes.

I cannot tell you what your number is. It depends on your video. Here's what I know: if you pick a number too large, the bitrate won't be high enough. If it's too small, the file will be bigger than it needs to be, increasing your upload time. It could be 1, it could be 40. The only way to find out is to encode the video and check with MediaInfo. Annoying – yes – but at least you'll know for sure you're getting the link for high quality or HD – and you won't lose all. One click video converters can never guarantee that. Once you do get a bitrate over 1000kbps and the file size not super huge, you're done and you can upload the video.

2 comments:

Alessandro Portale said...

There are alternatives to XVid when uploading a losslessly encoded video to YouTube.

YouTube will accept ffmpeg's lossless ffv1, which comes with ffmpeg-tryouts or ffmpeg command line.

And if You want even smaller filesize just upload an avi with the TechSmith codec. The TS codec is free to download.

Shane said...

When I tried using the Lagarith lossless codec, I got this message: Failed (unable to convert video file)

Any help? =/