Say you want to burn your series episodes you got lying on your hard disc to a DVD to enjoy them on your big TV screen or just archive them and free some space on your hard disc. For Mac OSX there are a lot of commercial (Roxio's Toast), and free programs (like iDVD) out there, that will help you accomplish that task. But, most of them will not let you fit more than around 2 hours on a regular DVD+/-R for quality reasons. For series with 20 or more episodes, on the other hand, I'm willing to sacrifice some quality for space efficiency. The amount of video you can put on a DVD depends on the bitrate used for compressing the video. A lower bitrate comes at the price of lower video quality. But unless you have a high definition TV, compression settings for 7-10 hours still give you more than acceptable quality. In the following I will describe how you can achieve that with only open source quality on your mac. I'm gonna highlight some pitfalls I had on my MacBook Pro with OS X 10.6.2.
I make use of the following open source command line tools.
Converting Video
First, you will need to convert your videos to the right mpg format used on DVDs. On a Video DVD MPEG2 and MPEG1 are possible, but need to have certain resolutions and parameters to be standard compliant. ffmpeg to the rescue: the neat program has a dvd target which takes care of all the right parameters. In it's simplest form you could just let it do all the work for you with the default parameters:
ffmpeg -thread 8 -target dvd -i INPUT.AVI OUTPUT.mpg
This will take the INPUT.AVI file and convert it to MPEG2 format with AC3 sound. With more threads you can achieve higher FPS for recoding. The default parameters will only fit around 2 hours on a DVD. What you wanna do is tweak bitrate and resolution.
ffmpeg -thread 8 -target ntsc-dvd -aspect 4:3 -s 352x480 - b 1100k -acodec mp2 -ab 224000 -ac 2 -i INPUT.AVI OUTPUT.mpg
This will give you around 7 hours per 4.7 GB DVD. Let's look at the parameters. First, ntsc-dvd should be used when you deal with ntsc content (29,7 fps). Aspect ratio is forced to 4:3 because the video is in 4:3 format. I use half resolution and a lower bitrate. Instead of AC3 stereo (2 audio channels) mp2 with 224kbs is used here. It is advisable to use lower resolution with lower bitrates. 1MB/s as in my setup is a pretty low bitrate compared to 4-5 MB/s found on commercial DVDs. But when combined with lower resolutions you can still achieve acceptable quality. According to this Wikipedia article here, the following resolutions are possible on a DVD.
To batch encode a bunch of episodes use a for loop on the bash compatible shell:
for i Episode-{01,02,03,04,05,06,07}.avi; do ffmpeg -threads 8 -i $i -target ntsc-dvd -aspect 4:3 -acodec mp2 -ab 224000 -ac 2 -b 1000k -s 352x480 mpg/${i%.avi}.mpg;
done
This will encode the avi files Episode-01, Episode-02, ... Episode-07 and save them into a mpg subfolder. If you have all files converted you are ready for authoring a DVD.
Author DVD
For authoring a DVD, the `dvdauthor` program is used. Since DVD authoring is quite a complex task, an XML file can be generated with all the menus, titles and whistles. But if you all you wanna have is the movie on the DVD, you can just supply command line parameters like this
dvdauthor -o MY_DVD -t -f Episode-01.mpg -f Episode-02.mpg -f Episode-03.mpg -f Episode-04.mpg -f Episode-05.mpg -f Episode-06.mpg -f Episode-07.mpg
dvdauthor -o MY_DVD -T
to author a DVD in the folder MY_DVD with a single title (-t) and episode being accessible as a different chapter on the DVD. Putting each episode in it's own title would be possible, but on most DVD remotes players switching titles is either not possible or cumbersome, whereas skipping chapters is always possible. The -T command will create the table of contents and complete the DVD authoring. The MY_DVD folder contains an AUDIO_TS and VIDEO_TS folder.
Burn the DVD
The last step is burning your authored DVD. A Video DVD is not a Data DVD. So simply using the mac os function `burn folder to DVD` is not what you want because it will create a data DVD. Instead make use of the dvdrw-tools.
growisofs -dvd-compat -dvd-video -Z /dev/rdisk1 ./MY_DVD
Will burn the contents from the MY_DVD as Video DVD. The DVD drive on my mac is /dev/rdisk1. If you go to disk utility you might see `/dev/disk1` instead, but you will not have permissions to use that drive on the command line. So use `/dev/rdisk`.
Watch your DVD
You should end up with a standard conform Video DVD that is playable on virtually all DVD players. Holding a lot of video content you can save some discs and money. Although the quality is not as good as on commercial DVDs, it is still very watchable on regular TV sets. Even more so for series, where you watch an episode usually only once.
Outlook
It should be no problem to create a small shell or ruby script to automate above steps. I might even write one and publish it here on my blog some time later. Especially automation of the bitrate calculation would be very helpful as I used a lot of trial and error in my first attempt to fit the desired number of episodes on one DVD.
I make use of the following open source command line tools.
- ffmpeg: helps you convert your videos to DVD mpg
- dvdauthor: authors a DVD file structure from DVD mpgs
- dvdrw-tools: helps you burn DVD images to a physical DVD; builds on cdrtools
- cdrtools: should contain the `mkisofs` program that creates iso CD/DVD images. But for whatever reason, the mac port didn't include the mkisofs program! After several hours I gave up and took the mkisofs found in the Burn package.
Converting Video
First, you will need to convert your videos to the right mpg format used on DVDs. On a Video DVD MPEG2 and MPEG1 are possible, but need to have certain resolutions and parameters to be standard compliant. ffmpeg to the rescue: the neat program has a dvd target which takes care of all the right parameters. In it's simplest form you could just let it do all the work for you with the default parameters:
ffmpeg -thread 8 -target dvd -i INPUT.AVI OUTPUT.mpg
This will take the INPUT.AVI file and convert it to MPEG2 format with AC3 sound. With more threads you can achieve higher FPS for recoding. The default parameters will only fit around 2 hours on a DVD. What you wanna do is tweak bitrate and resolution.
ffmpeg -thread 8 -target ntsc-dvd -aspect 4:3 -s 352x480 - b 1100k -acodec mp2 -ab 224000 -ac 2 -i INPUT.AVI OUTPUT.mpg
This will give you around 7 hours per 4.7 GB DVD. Let's look at the parameters. First, ntsc-dvd should be used when you deal with ntsc content (29,7 fps). Aspect ratio is forced to 4:3 because the video is in 4:3 format. I use half resolution and a lower bitrate. Instead of AC3 stereo (2 audio channels) mp2 with 224kbs is used here. It is advisable to use lower resolution with lower bitrates. 1MB/s as in my setup is a pretty low bitrate compared to 4-5 MB/s found on commercial DVDs. But when combined with lower resolutions you can still achieve acceptable quality. According to this Wikipedia article here, the following resolutions are possible on a DVD.
At 25 frame/s, interlaced (used in regions with 50 Hz image scanning frequency):Keeping a high resolution with a low bitrate will give you a lot of encoding artifacts (blocks). So for very long content it's best to go with the lowest resolution. If you have hardcoded subtitles in the video (like in many asian dramas), it's better to keep a high vertical resolution. That's why I am going with the HALF-D1 resolution in above's example.
- 720 × 576 pixels MPEG-2 (Called full D1)
- 704 × 576 pixels MPEG-2
- 352 × 576 pixels MPEG-2 (Called Half-D1, same as the China Video Disc standard)
- At 29.97, interlaced (used in regions with 60 Hz image scanning frequency):
The following formats are allowed for MPEG-1 video:
- 720 × 480 pixels MPEG-2 (Called full D1)
- 704 × 480 pixels MPEG-2
- 352 × 480 pixels MPEG-2 (Called Half-D1, same as the China Video Disc standard)
To batch encode a bunch of episodes use a for loop on the bash compatible shell:
for i Episode-{01,02,03,04,05,06,07}.avi; do ffmpeg -threads 8 -i $i -target ntsc-dvd -aspect 4:3 -acodec mp2 -ab 224000 -ac 2 -b 1000k -s 352x480 mpg/${i%.avi}.mpg;
done
This will encode the avi files Episode-01, Episode-02, ... Episode-07 and save them into a mpg subfolder. If you have all files converted you are ready for authoring a DVD.
Author DVD
For authoring a DVD, the `dvdauthor` program is used. Since DVD authoring is quite a complex task, an XML file can be generated with all the menus, titles and whistles. But if you all you wanna have is the movie on the DVD, you can just supply command line parameters like this
dvdauthor -o MY_DVD -t -f Episode-01.mpg -f Episode-02.mpg -f Episode-03.mpg -f Episode-04.mpg -f Episode-05.mpg -f Episode-06.mpg -f Episode-07.mpg
dvdauthor -o MY_DVD -T
to author a DVD in the folder MY_DVD with a single title (-t) and episode being accessible as a different chapter on the DVD. Putting each episode in it's own title would be possible, but on most DVD remotes players switching titles is either not possible or cumbersome, whereas skipping chapters is always possible. The -T command will create the table of contents and complete the DVD authoring. The MY_DVD folder contains an AUDIO_TS and VIDEO_TS folder.
Burn the DVD
The last step is burning your authored DVD. A Video DVD is not a Data DVD. So simply using the mac os function `burn folder to DVD` is not what you want because it will create a data DVD. Instead make use of the dvdrw-tools.
growisofs -dvd-compat -dvd-video -Z /dev/rdisk1 ./MY_DVD
Will burn the contents from the MY_DVD as Video DVD. The DVD drive on my mac is /dev/rdisk1. If you go to disk utility you might see `/dev/disk1` instead, but you will not have permissions to use that drive on the command line. So use `/dev/rdisk`.
Watch your DVD
You should end up with a standard conform Video DVD that is playable on virtually all DVD players. Holding a lot of video content you can save some discs and money. Although the quality is not as good as on commercial DVDs, it is still very watchable on regular TV sets. Even more so for series, where you watch an episode usually only once.
Outlook
It should be no problem to create a small shell or ruby script to automate above steps. I might even write one and publish it here on my blog some time later. Especially automation of the bitrate calculation would be very helpful as I used a lot of trial and error in my first attempt to fit the desired number of episodes on one DVD.

No comments:
Post a Comment