Sunday, February 28, 2010

How to archive series on a Video DVD with your mac

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.
  • 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.
Having above program infrastructure you are ready to create your DVD.

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):
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):
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)
The following formats are allowed for MPEG-1 video:
  • 352 × 288 pixels MPEG-1 at 25 frame/s, progressive (Same as the VCD Standard)
  • 352 × 240 pixels MPEG-1 at 29.97 frame/s, progressive (Same as the VCD Standard)
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.

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.

Friday, February 26, 2010

Some useful Firefox plugins

Recently I have been playing with several browsers on my computer. There's the new Safari on my MacBook, Internet Explorer 8 on my virtual machine and finally the all new and lightning-fast Google Chrome browser. I had been a hardcore Firefox user before playing with those new browsers, but since all the browsers become more similar with every version (Tabbed browsing, smart address bar, etc.) I didn't miss my Firefox browser that much.

Now I have come back to Firefox, though. The main reason for that is the huge number of useful plugins (or extensions as Firefox calls them) out there. I figured it might be a good thing to share which plugins I am currently using,  and maybe get some suggestions for other awesome plug-ins out there.

First off are extensions that provide for a better browsing experience:
  • Adblock Plus frees web sites from nagging advertisements
  • Delicious Bookmarks best bookmark management plugin imho
  • feedly puts a sleek newspaper design around your google reader and integrates more social  functionality.
  • Quickdrag assigns functions and shortcuts to drag actions.
  • Addto Search Bar lets you extend the search bar by a simply right clicking the search box on a search site.
  • NoScript protects you by allowing only white listed sites to execute java script code
  • CoolPreview provides quick previews for links so that you don't have to clutter your browser with more tabs. It's called Picture-in-picture Browsing.
  • SkipScreen skips annoying screens on suspicious download sites like rapidshare.com
For social networking I have found useful:
  • TwitterBar let's you twitter right from your address bar. 
  • ScribeFire let's you write blogentries like for blogger.com
    Now plugins for a better multimedia experience:
  • DownloadHelper helps you download and convert videos from all the famous flash video sites.
  • DownThemAll is a very useful add-on for downloading galleries from web sites or any other linked mass files - a huge time saver
  • fire.fm integrates gives you last.fm radio and functionality for free right beneath your address bar.
    And for development:
  • Elasticfox gives you a GUI to your amazon EC2 services. very useful and time saving if you work with Amazon cloud services.
  • Similarly S3Fox facilitates management of Amazon's Simple Storage Service (Not working with Firefox 3.6 yet, though) 
    Those extensions make up my current selection on my Firefox installation. Although Chrome might be a little faster than Firefox, it is the amount of useful extensions and highly customizability that make  Firefox  my browser of choice once again.