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.