Monday, September 22, 2008

Command Line DVD Authoring: Part 1

This is part of a multi-part series on creating DVDs manually from the command line. It is not expected that regular users will generally be performing video editing or DVD authoring from the command line. Rather, this guide is intended for programmers who may be wishing to build a front-end for DVD authoring, and don't want to sift through miles of documentaion just to get the basics. This guide makes use of command-line utilities already freely available, but is not meant to be a complete set of documentation for any of these utilities. Instead, consider it a primer. The parts in this series are:

Part 1: Editing a Video File with MPlayer
Part 2: Converting a Video to DVD Format
Part 3: Making a DVD Menu
Part 3.1: Extracting Audio From A Video
Part 4: Building a DVD .iso File

It should be noted that while the programs themselves should remain relatively the same between Linux distros, the name of the packages themselves are likely to change. This tutorial was written using Ubuntu 8.04 as the reference OS, so if you use a different distro, your mileage may vary.

Part 1: Editing a Video File with MPlayer

This part of the series assumes that you have a raw video file that needs editing. The only requirement on the format of the file is that it is something that MPlayer can read. There are two basic types of edits that can be used: skipping or muting video.

MPlayer uses a type of file called an "edit decision list" (edl). The concept of an edit decision list is not new. It has existed in several other pieces of software for years, and in fact really existed as entries on a piece of paper before video editing software even existed. In MPlayer this file specifies, in seconds and parts of a second, where the edit is to be made. The basic format of each line in an MPlayer edl file is:

<start point> <end point> <edit type>

The start and end points are specified in seconds, up to a few decimal points. The edit type can be 0 to skip the section of video, or 1 to just mute the section of video. A typical edl file may look like this:

0 68.201469 0
653.652954 833.749575 0
1374.589844 1619.768193 0
2079.794434 2350.648281 0
3169.433105 3466.679939 0
3669.048584 3815.461840 0

This file was generated from an hour-long television show that was set to start recording one minute early, and finish one minute after the show was expected to finish. I like to record my shows like this, since not all networks start and finish their shows the same way, or even at the same time. This edl file cut out the first minute and then some, took out a few commercial breaks, and then at the end of the show, cut out everything following the closing credits. Since I wasn't sure exactly what second the show ended at, I took out some insurance and added over a minute to the end time.

Originally, edl files were designed for editing language and content out of shows, not for cutting commercial breaks. This explains why they allowed such a high resolution to the start and end times. It may be that you only wish to mute a single word or phrase from a show. In this case, the amount of time between the start and end time will likely be less than a second, and the last value of the line will be 1, not 0.

There are two steps to dealing with edl files: you need to create the file, and then playback the video using the file. The mplayer command will accept the -edlout option to create a file while you watch the video. The -edl option will then playback a video using the file that you created. To start creating an edl file, the command will look something like this:

mplayer myvideo.mpg -edlout myvideo.edl

When using -edlout, there are some keystrokes that you can use to navigate the video, and then save start and end points to the edl file. Pressing 'i' once will tell mplayer to start an edit, and pressing it a second time will tell mplayer to end that edit and save it out to a file. By default, these edits will be saved as a skip (0), rather than a mute (1). If you have started an edit and mplayer finishs the video and exits before you end the edit, it will not be saved to the file.

Of course, it's difficult to watch a show and be able to time pressing the 'i' key perfectly every time. Pressing 'o' will toggle the on-screen display (OSD) modes. The first shows the time elapsed. The second also shows the total time of the video. The third will disable OSD altogether, and the fourth will re-enable it. By default, the mplayer command will start with OSD on, but nothing displayed. The gmplayer command will, by default, show the time elapsed and the total time.

If you miss a critical point where you would have pressed 'i' to mark a start or end point, you can just press 'i' anyway, and then go back into the file and fine-tune it later. Or there are a series of keys that you can used to navigate more quickly through a file. The left and right arrows will skip 10 seconds back or forward, respectively. The up and down arrows will skip 1 minute back or forward, respectively. And the page-up and page-down arrows will skip 10 minutes (or 15, depending on your system, I've seen both) back or forward, respectively.

Pressing or 'p' will pause or unpause the video. Pressing the period (.) will move one frame forward and then pause. Pressing the period repeatedly will continue to step one frame forward at a time. The nice thing is, when you step forward a frame, you can actually hear the snippet of audio for that frame. Then again, since a frame is so short in terms of time displayed, that may not be so helpful. If you press 'i' while the video is paused, it will mark the start (or end) point and then continue play.

When the video finishes playing, or you exit mplayer by pressing 'q', you will have an edl file ready for use, or for fine tuning. Chances are, even when you get good at pressing 'i' just at the right moment, you're still going to need to do some file tuning. Play back the video using a command that looks like this:

mplayer myvideo.mpg -edl myvideo.edl

Be careful that you don't accidentally type -edlout instead of -edl. The -edlout option will start a new, blank file, overwriting any that were there before. As you play back your video, it may be helpful to turn on the onscreen display. All of the same navigational keys work in this mode as well, and you will probably want to skip to each point to watch and verify your edit. If you skip past the start point, mplayer will not perform the edit. That means that if your edl file skipped three minutes of commercials, and you skipped over where the commercials started, mplayer will not know to just skip to the end of the commercials. But you can just skip back before the edit point, and it will still work as expected.

When I edit videos like this, I usually keep two terminal windows open: one with the edl file open in vim, and one in which to run the mplayer command over and over again. This is because once you have saved a change to the edl file, mplayer must be reloaded before it will pick up the new changes.

When you are finished creating your edl file, you can just use it for watching videos with mplayer (using the -edl option each time), or you can use it to make a second copy of the video, with all of the edits already in place. This is covered in Part 2: Converting a Video to DVD Format.

No comments:

Post a Comment

Comments for posts over 14 days are moderated