Sunday, 31 May 2009

Extracting and changing the soundtrack

Supposing you have a video of car-crashes and want to add some rousing music, Tschaikowsky's 1812 Overture for example. VirtualDub allows you to do this very easily.

Replacing the audio

Open the video clip, then go to the Audio menu, select Audio from other file and choose your clip. It could be an AVI or MPEG video file, or a WAV or MP3 audio-only file. Then simply save with Direct stream copy enabled on both the Video and Audio menus.

Unfortunately this will probably not produce the result you want due to the clips being of different lengths. This may need some time-consuming editing. If the video is longer than the audio then you can hack away at it fairly freely to get it down to time. If the audio is longer then you can slow down the video (you might want to do this anyway). Go to Video -> Frame Rate..., then under Source rate adjustment select Change so video and audio durations match.

Extracting a soundtrack

You can save the soundtrack from a video clip as a WAV file for editing in an audio program of your choice. Just load the clip, go to the File menu and pick Save WAV....

To save a track from a CD as a WAV you'll need another program. Media Player Classic will do. Just insert the CD, select the track you want, and use the File menu Save As... option to create the WAV file.

Compressing the audio

When saving a clip always use Audio -> Direct stream copy until you're ready to produce the final result. Uncompressed formats such as WAV have the advantage of the View -> Audio display option for easier editing, but will eventually need compressing or the file will be twice the size it ought to be. Audio imported in MP3 or similar formats shouldn't need re-compressing. Use the File -> File Information option to chect that the audio data rate isn't excessive (ie. greater than 192kbps).

Example video

You can often get a cheap but amusing effect by combining a video with a totally unsuitable soundtrack. Here I've taken some nasty blood-and-guts and set it to a beautiful piece by Mozart:

http://rapidshare.com/files/238693851/Cutting-Moments-Mozart-01.avi
(1:42 minutes, 384 x 288, 8MB)

Changing the frame rate

Sometimes it's useful to change the rate at which an AVI clip is played back and VirtualDub offers several ways of doing this.

Simple adjustment

One the Video menu select Frame rate.... Tick the Change frame rate to (fps) box and enter a new frame rate. Lower than the original for slow-motion, higher for speeded up video. In this example I'm changing a 25fps PAL clip to 12fps, approximately half speed.

The sound will go out of sync with the picture if you do this, but I don't care in this case because I'm going to add a new soundtrack later.

This feature doesn't create or destroy any frames, it just plays the originals at a different speed, so you can save with Video -> Direct stream copy.

Frame rate decimation

Throws away every second frame (or two out of three frames etc.). This option is useful for creating clips with a small file size without harming the still picture quality too much. You will lose audio sync so must recode (Video -> Full processing mode but not Audio) to get it back.

Inverse telecine

This applies to 30fps (60 fields interlaced) NTSC format clips made from 24fps feature films (ie. most US/Japan sourced DVDs). The frame rate conversion used for this is called 2:3 pulldown. What this means is the first frame from the cinema film is spread over two video fields (half-frames), the second over three fields, the third frame two fields again, the fourth frame three fields, and so on.

This process introduces blurriness, juddering on slow pans, and "combing" interlacing artefacts on freeze-frames. VirtualDub provides options to undo the damage. And the very best of luck in getting it to work! For more information see this Wikipedia article on 2:3 pulldown.

Friday, 29 May 2009

Tidying audio at the ends of a clip

Usually the audio for a scene will end at the same time as the video and the resulting clip ends neatly. But sometimes the audio runs on a little into the next scene, and cutting at the end of the video can leave a speech in mid-word or music in mid-bar. Similar things can happen at the beginning of a scene. The effect is irritating and messy, and it's possible to tidy it up.

Tidying the end

If the problem is at the end of the clip it's very easy to fix. Rip the original clip with a few seconds of slack on the end. Load it into VirtualDub and snip off the end of the clip bit by bit until the sound finishes neatly, never mind about the pictures.

Now you can get rid of the unwanted picture frames by masking. Make a selection starting with the first frame you don't want, and ending with the end of the clip. Go to the Edit menu and select Mask selected frames. Masked frames (labelled with an [M] on the timeline) will not appear when the video plays, instead the last frame displayed freezes. You can now save the clip using Direct mode for both audio and video.

Tidying the start

The same thing can be done at the beginning of the clip, but it's a bit trickier. The main problem is that the first frame is displayed whether you mask it or not. Furthermore, the same editing caveats apply as if you were deleting the frames instead of masking them: Full processing mode + Smart rendering should be enabled.

It's possible to get rid of the frozen first frame of Clip A by finding a silent clip with blank video in the exact same format, Clip B. You can always extract one of these from a piece of "dead air" on a feature film or similar. Load Clip B afresh and append Clip A. Now you can delete all but the first frame of Clip B, mask all the other frames of Clip A you don't want to see, and save the result.

Wednesday, 20 May 2009

Cropping, resizing and adding logos

The picture on many DVDs is letterboxed or pillarboxed. In other words, the picture frame is filled out with black bars at the top and bottom or at the sides. This is ugly, especially if you're playing a clip in a desktop window. Sometimes you want to resize the picture, maybe to fit the requirements of Youtube or to join clips from different sources together. It also can be handy to label a clip with a logo or text caption. This section explains how to do all these (and more) in one step. But unfortunately this involves re-encoding the clip, so first make sure your source clip is coded at the highest quality possible.

Cropping

I have here a clip from a film on PAL 4:3 format DVD which is framed at 1.66:1, leaving black bars at the top and bottom. I'm going to get rid of them. This is done using filters, in this case a null one.

Go to the Video menu and select Filters.... Click the Add... button to get a list of filters. Choose the null transform from the list and click OK. This is the result:

The null transform filter doesn't actually do anything to the picture, it just allows us to use the cropping function. So press the Cropping... button. To crop top and bottom use the Y1 and Y2 gadgets, for left and right the X1 and X2 ones. Keep to multiples of 8 or you can have problems playing back the finished clip. In my case offsets of 56 are just right. Below I've just cropped the top part.

Now I just need to enter 56 in the Y2 box and click OK to finish. This is the result, showing that the final frame size will be 768 x 464. Click OK and now the clip can be saved with Video -> Full processing mode switched on.

Resizing

As well as cropping I want to resize the clip to 640 x 360. This is a bit tricky as it's a different aspect ratio to the original so will need pillarboxing, ie. black bars at the sides. Cropping and resizing can be done at the same time so I'm going to go back to the original clip and start again.

Go to the Filters dialog and add a resize filter. Don't change any of the values in the resize dialog for now, just click OK and get this:

Now add the cropping just as before. Cropping is always done first, on the original rather than the resized image so the values of 56 top and bottom are the same.

Now to do the resizing. Double-click the filter to configure it. If we just wanted a half size image this would be easy - just check the Relative box and enter 50 (%) and everything's done.

In this case the target size is 640 x 360, which means changing the aspect ratio so this is a bit tricky. Check the Absolute box and enter the new dimensions. In this case we need to pad out the sides while keeping the height the same. So enter 360 as the height and the width will fix itself to an odd fraction.

Now under the Framing options section check the Letterbox / crop to size button and enter the final dimensions of 640 x 360. Use the Show preview button to confirm everything is correct.

That's everything done so click OK and now you can save the clip.

Adding a logo

To complete the clip I want to add a caption giving the title and who is in it. To do this you need to create a still image to overlay onto the video. Create this with your favourite program, in my case Paint Shop Pro.

To keep things simple, open a blank image with the dimensions of the output video, here 640 x 360. Select pure black for the background colour, and pure white (RGB 255, 255, 255) for the foreground, then write your caption / draw your logo. In my case I just want a single line of text at the bottom of the picture so this is easy. Save it in a lossless format (eg. .BMP), not .JPEG.

Now to combine this logo with the video. This should be done at the same time as the cropping and resizing to retain the best image quality. Go to the Filters dialog, click Add... and choose logo from the list. Here's how to set up the options. Both file selections are the same image I just created. There's a Preview button to keep track of what you're doing.

This is very basic. The only "fancy" setting I chose was to set the Opacity to 50%, which is easier on the eye. Using colours is not always a good idea as they tend to "bleed" on low bitrate videos. Now if the Filters dialog looks like this we're finished and ready to save the finished version:

Further editing with VirtualDub

Only a little more complicated than the previous post, this will explain how to delete any part(s) of a clip you like, or save any part you like.

Vital points to remember

  • Deleting parts of the clip from the timeline doesn't harm the original clip - the only time a file is changed is when you finally save the result. So if you mess up you can always just reload the original.
  • A selection on the timeline consists of the frames from the first up to but not including the last one.

Editing without losing picture quality

It's very simple to delete a segment from a clip. Select the first frame, click Mark-in, select the frame where you want the video to pick up again and click Mark-out, then press Del. Repeat this as many times as you like. To extract a segment as a separate file, just select it and save from the File menu as usual.

But to avoid the picture degrading due to re-encoding the video (and also to make selecting the correct end points easier) it's important to keep to key frames. For a full explanation, see the Help topics under Processing -> Direct mode. Meanwhile, select Direct stream copy from the Video menu and follow these rules:

  • When deleting a segment, always end the selection with a key frame (or the end of the clip)
  • When extracting and saving a segment, always begin with a key frame

Free editing

If you can't keep to key frames then you must change the processing options. Go to the Video menu and select Full processing mode, then Smart rendering. This will only re-encode the frames that are strictly necessary, not the whole thing.

Make sure that you only re-encode these frames once. Don't snip 50 frames, save, load the output file, decide it wasn't enough and snip 10 more and save again. Leave this editing step till the very last moment, especially if you're going to use further processing such as cropping and resizing.

Wednesday, 13 May 2009

Basic editing using VirtualDub

For a fast, easy to use, and free video editor go and download VirtualDub. This superb little program can do many common editing tasks very quickly. The downside is that it can't do everything you might want, and though the interface is simple enough to use it's not very intuitive when you first meet it. Here I'll be explaining how to do three basic tasks:

  • Tidy a clip by snipping off the end
  • Join several clips together
  • Save space by compressing the audio

VirtualDub main interface

Drag the slider along the timeline like any ordinary video player. I've highlighted the most important buttons for selecting parts of the timeline.

  • Start / end selection, or Mark-in / Mark-out simply sets the start and end point of a segment of the timeline. Important: a selection runs from the first frame, up to but not including the last frame. This makes editing easier as long as you bear it in mind when deleting segments.

  • Frame back /forward buttons move the slider back or forward one frame at a time. Going backwards can be slow.

  • Key frame indicator, a very important concept for editing. Key frames are coded as still images, the rest of the frames (deltas) are coded as differences from the keys. Edit out a key and the deltas up to the next key are useless as they cannot be decoded. Hold down the Shift key when dragging the slider with the mouse to keep to key frames (this is faster too). For easy editing always end the selection with a key frame or the end of the clip.

Importance of Direct stream copy

When you start up VirtualDub always go to the Video menu and select Direct stream copy as below. This makes sure the new clip is copied directly from the original video stream without any additional processing. Not only does this not degrade the picture quality at all, it's also very much faster. There's a Direct mode for the sound as well on the Audio menu, and this is selected by default.

Snipping the end off a clip

The sample clip I created earlier runs on a fraction of a second into the next scene, which looks messy. I want to cut this bit off. As a matter of routine it's a good idea to encode about fifteen seconds more than you need and edit off the surplus rather than fiddle around getting the length perfect in the first place.

Move the slider right off end of the clip and click Mark-out. Now move it back until it's on the first frame you don't want and click Mark-in. This frame will probably be a key frame, but always check it's the right one by stepping back to the previous frame. In my example I only have to snip a single frame, but below I've selected more to make things clearer

The part you don't want is now selected in blue so just press Del to delete it. Now save the clip under a new name and you're done. A couple of notes:

  • If part of the clip is selected when you save then just that part will be saved, not the whole thing. If that's not what you want use Edit menu -> Clear selection to clear it.

  • Always have Video menu -> Direct stream copy selected or the clip will be re-encoded and the quality will degrade.

Joining two or more clips together

So you have several short clips you want to merge into one, or perhaps an entire feature film divided into chapters. You can quickly splice them together without loss of quality as long as the picture dimensions, frame rate, and audio sampling rate are the same for all the segments.

Load up the first clip, then go to the File menu and select Append AVI segment.... Just choose a file and it'll be added to the end of what you've already loaded. When you've got all you want save the whole thing under a new name (with Video -> Direct stream copy as usual).

  • Take care when this Audodetect additional segments box is checked! This is very handy when you have files like chap-01, chap-02 etc., but can be very confusing when you're just trying to add one file at a time.

Reduce file size by compressing the audio

AoA DVD Ripper produces AVIs with MP3 audio at 192Kbps. This is a good thing if you enjoy the music, but much more than is needed for most purposes. You can save 1MB of space per minute of video by using a 56Kbps rate. This gives a very useful reduction in file size for a low resolution clip, but may not be worthwhile if you are using higher resolutions.

Go to the Audio menu and select Full processing mode. Then Audio menu -> Compression. You'll see a list of codecs. Click one and choose the bitrate. I always use MPEG Layer-3 at 56Kbps (22050Hz), which is half the standard sampling rate.

Now save the entire clip (with Video -> Direct stream copy selected). Re-encoding just the audio doesn't take long.

  • Beware!, changing the sampling rate means you won't be able to join this clip with other AVIs that still have the old rate.

Saturday, 9 May 2009

Ripping an entire DVD


The unregistered shareware version of AoA DVD Ripper limits clips to just ten minutes. You can still rip an entire film as long as you do it chapter by chapter.

Select the title you want as normal, but at Stage 2 instead of clicking Movie Clip click Chapters. You'll be presented with a list of chapters - you may have to scroll down to see them all. Tick off the ones you want, make sure Save selected chapters into one file is selected, and press OK.

There's a trick here - you can keep on adding more chapters as long as the total time shows 10:00 minutes or less. This means that if all the chapters are exactly 10 minutes then you can actually rip 20 minutes in one go. If the total is 10 minutes or more when you click OK you'll get a warning - ignore it as long as the actual number of chapters shown is correct.

Click on Start to rip as normal, but remember to rename the output file before ripping more chapters or it'll be overwritten. And check the length of the clip as well as occasionally it stops short. When you've got them all you can play them all as a playlist or edit them into a single file.

Improving the results

Getting the best picture quality

Improved results, especially in reducing pixellation on scenes like water and fire, can be achieved by using two-pass encoding. Set this up in the Xvid Configuration dialog.

First choose Encoding type Twopass - 1st pass and encode the clip as usual. The result will be audio only.

Go back and choose Encoding type Twopass - 2nd pass and set the bitrate in the box below. Toggle the button to the left to choose either a target filesize or a desired bitrate. Something like 1000 is good for a full-size clip, 300 for half-size, but experiment and you may get away with much less.

Now encode the clip again for the finished result.

Dealing with interlace

The "combing" artefacts produced by interlaced encoding can be a nuisance. TV shows are usually interlaced, as are NTSC films (using the awful 2:3 pulldown). Interlaced PAL films are indistinguishable from progressive, unless (as too often happens) they've been upscaled from NTSC.

Coding the clip with exactly half (or a quarter) of the original lines deals with the problem, though that's rarely what you want. Using odd fractions of the original can give very weird results.

There's an option to de-interlace by getting rid of half the lines while keeping the horizontal resolution. Use the Settings dialog, select the Advanced Options tab, and check the Remove Interlace from Video box.

Coding for YouTube

YouTube prefers an odd resolution of 640 x 360 (16:9 - 480 x 360 for 4:3) and likes to re-encode the file after uploading. There are two extremes of dealing with this.

Either encode the clip at the ideal resolution and maximum bitrate and let the transcoder do its worst. Or encode at 640 x 360 to start with using a very low bitrate (336Kbs two-pass can be surprisingly acceptable) and hope it doesn't get messed with.

Changing the brightness

Clips often turn out too dark. There's an option to change the brightness in the Xvid Configuration dialog. Press the Other Options button at the bottom and select the Decoder tab. Adjust with the slider - the middle position is default. Don't forget to change this back afterwards.

Removing the black bars

Letterboxing (and pillarboxing) is ugly and unnecessary for a clip played on a PC. I don't know a way to crop them without using a separate program.

Fine tuning the start and end points

These can only be set to the nearest second. Sometimes this isn't good enough and results in clipped audio at the start and finish. All you can do is have the clip start/end five seconds earlier/later and edit it with a separate program.

Using less space for the audio

By default the MP3 encoder uses a bitrate of 192Kbs when for many clips something like 64K is enough. This would save about 1MB of space for every minute of video, a very useful 20% or more on a lo-res clip. But I can't find a way of changing this within AoA.

Configuring for ripping


So you've got the DVD in the drive and have found the start and end times (hours, minutes, seconds) of the clip you want. Start up AoA DVD Ripper and load the DVD as below. Select the drive and title from the list and click OK.


The listing will fill with the titles found on the DVD. Select the correct title and tick the box next to it. If it's a feature film it should be the longest and will be already selected. If it's a TV series as below then the episodes will usually but not always be in the correct order. You have to go by the running times to be sure. I'm selecting episode three here - episode one is listed twice, something that often happens.


Make sure AVI is selected in the Convert To box. Choose the language and subtitles you want. The Output Directory is the folder where your AVI file will end up. Normally you won't need to change these settings.


Step 2 is selecting the Movie Clip so click here:


Type in the start and end times of the clip in hours:minutes:seconds format - it's very fussy about this. The preview frames won't actually show up until you click the + or - buttons so do this a couple of times.

Now things can start to get awkward. The chances are the times used by AoA won't match those on your player so you're going to have to adjust them. Click the buttons until the correct start and end frames are showing.

Sometimes the preview frames will become corrupted. In this case there's nothing for it but to quit the program and restart.


Now you need to configure the output settings so click here:


The format of my test DVD is PAL 4:3 interlaced, and I only want a half-sized picture. Consulting the table in the previous post gives the settings for frame-rate and width / height. Choose the Xvid MPEG-4 Codec for the video and MP3 for the audio. These give excellent results and are the most widely compatible across different platforms.


Now click on the Configure... button. The choices you make here affect the picture quality and file size of the AVI clip.

The Encoding type should be Single pass. The Target quantizer determines the picture quality. Set it to 1 for the best results, with higher values being steadily worse. If you want a smaller file then a value of 5 is about the highest that is useful. A value of 2 is a good compromise if you want to post a fair quality clip online.


Everything's set now so click here to start ripping:


As it encodes AoA will display a preview frame and a progress report. When it's done you must hit Back before you can do anything else. Be warned that encoding video can take a long time depending on your system (several times longer than the clip itself runs) and often turns out wrong and has to be done over again. Use the thumbnail picture dimensions to save time here before moving on to full size.

The output folder should open automatically for you to find your AVI clip. Open it and test it. Any good? If something's gone wrong change some settings and try it again. A common problem is the clip ending too soon. This just happened with my test clip and I had to add six seconds to the ending time.

So here's my finished AVI clip playing with standard Media Player. It's just 2.5MB in size for 40 seconds running time with passable picture quality, but I'm still not too happy with it. The quality setting I chose was a bit low, the border is ragged, and the start and end times need tuning by a few fractions of a second. Later on I'll discuss how to fix these problems to get the (almost) perfect clip.

Download the clip from Rapidshare: Reeves and Mortimer Spot Skit

Identify your DVD


Before you start ripping you need to identify the format of the DVD to determine the best output settings. AoA won't tell you this. It can be PAL or NTSC, in 4:3 or 16:9, interlaced or progressive.

PAL or NTSC?

PAL is standard in Europe and most of the world, NTSC in the USA and Japan. If you're not sure look on the back of the DVD case. Don't have a case? Play the DVD (the feature you want to rip not just the menus) with VLC or similar, take a screenshot and find its dimensions with an image editor or the status bar in Explorer. PAL will be 576 pixels high, NTSC 480.

4:3 or 16:9?

Fullscreen (1.33:1 or 1.37:1) is 4:3 format, but just because it says "Widescreen" (1.66:1, 1.78:1, 1.85:1, 2.35:1 etc.) on the case doesn't mean it's actually in 16:9 format. Look for labels like "anamorphic" or "enhanced for widescreen TVs".

Interlaced or not?

Almost all film and TV DVDs are recorded in interlaced format, and this can be a problem. If you're not sure assume it is interlaced, unless it's a PAL cinema film in which case interlacing shouldn't be a problem.

Now you can choose the correct frame dimensions from the table. For best results only use these (though YouTube unfortunately prefers 640 x 360 - if you insist on using other sizes always choose multiples of 8). Normally you'll want full size, but half size saves disc space and ripping / uploading time and still looks acceptable. Thumbnail is for quick previews.

FormatFramesFull sizeHalf sizeThumbnail
PAL 4:325768 x 576384 x 288192 x 144
PAL 16:9251024 x 576512 x 288256 x 144
NTSC 4:329.97640 x 480320 x 240160 x 120
NTSC 16:929.97856 x 480424 x 240216 x 120

Note that these resolutions are for square pixels. The actual resolution of the image on the disc will be 720 (or 704) x 576 (or 480) whether it's "widescreen" or not. This would be the ideal output resolution, but these pixels are not square. There is no way of setting the aspect ratio in an AVI file, so unless you configure your player correctly for each clip then the image will be distorted.

What you need to rip an AVI clip from a DVD


A PC with a DVD drive is all you'll have to pay for, the rest is free.

If your Windows PC won't actually play DVDs go and download a free player. Either VLC Media Player or Media Player Classic will do. In fact get both as they each have their strengths and weaknesses.

Now you need the ripping program. This guide uses the shareware AoA DVD Ripper which is free as long as you'll only be taking clips up to ten minutes long.

The good thing about AoA is that it's Fisher-Price-simple to use with big shiny buttons for big clumsy mouse-cursors. The downside is that it's buggy and gives no guidance on the output settings you'll need to produce good quality clips. There are some good outline guides on the official website, but here I'm going to give some more in-depth advice on getting the best results with it.