Learn More Contact Now Learn more about GeniusDV Video Training Classes - call toll-free: 866-566-1881

Scripting in DVD Studio, Part 5: Aspect Ratios and Advanced-ish Math

| | TrackBacks (0)

This time, we'll write a script to detect whether the DVD player is showing in widescreen (16:9 anamorphic) mode or standard (4:3) mode - and automatically play the video in the appropriate format.

I hope that this tutorial will be a practical one for those of you who are putting both regular NTSC-DV content and anamorphic on the same disc, but more importantly I hope that the introduction to bit math might be useful if you need to extract other characteristics from the bitwise SPRMs, like SPRM14 (Video Config), SPRM15 (Audio Config), and SPRM11 (Karaoke).

You'll have to excuse me for getting all technical up in here; "bitwise" just means that the single SPRM stores a lot of pieces of information in one number. Read on for what I promise will be a painless introduction ...

Before we do anything with bitwise math, we need to think quickly about how binary numbers work. The details aren't important - just think about it this way. Deep breath:

1. Position 1615 1413 1211 109 87 65 43 21
2. Binary Number 0 0 0 1 0 0 1 1 1 1 1 1 0 0 1 1
3. (multiply by) Value 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1
4. (=) Calculated Value 0+ 0+ 0+ 4096+ 0+ 0+ 512+ 256+ 128+ 64+ 32+ 16+ 0+ 0+ 2+ 1 =5105

  So Row #2 is our binary number. It's just like computer-speak in the movies: it's a series of ones and zeros. Now, for most of our SPRMs (DVD system variables), we're interested in the "real" number that those ones and zeros add up to (Row #4). But for bitwise SPRMs, each individual position in the binary number represents whether something is true or false.

For example, when you look up SPRM 14 (Video Configuration) in the DVD Studio Pro manual, it says that Bit 8 corresponds to Pan-And-Scan mode - so when the DVD player is in pan-and-scan mode, Bit 8 will be set (have a value of 1). For our purposes, we want to know whether the DVD player's aspect ratio is in 4:3 mode or 16:9 mode. The manual tells us that, in 4x3 mode, both Bit 10 and Bit 11 of SPRM 14 are unset (0) - while in 16x9 mode, Bit 10 and Bit 11 of SPRM 14 are both set.

Now remember - just like in the example above, there are a lot of other bits in SPRM 14, and each of them changes the calculated value (line 4) that we're dealing with in DVD Studio. So if we only want to measure Bit 10 and Bit 11, we need to reset all of the other bits. The easiest way to do this is called a bitwise AND operation - essentially, it takes two binary numbers, and multiplies them together at the individual ones-and-zeros level, like this:

1. Position 1615 1413 1211 109 87 65 43 21
2. Binary 1 (pretend it's SPRM14) 0 0 0 1 0 1 1 1 0 1 1 1 0 0 1 1
3. (AND/multiply) Binary 2 0 0 00 0 1 1 0 0 0 0 0 0 0 0 0
4. (=) Calculated Binary 0 00 0 0 1 1 0 0 0 0 0 0 0 0 0

See how the AND filtered out everything but the values in bits 10 and 11? Now, in order to test whether bits 10 and 11 are set, we just see if this result has the same numeric value as a binary number with only bits 10 and 11 - which you can calculate like we did in the first example above. Turns out that value is (1024 + 2048) = 3072 ... which is exactly the same as the binary we use to "AND" with in Line 3 above.

Now, as to coding up the example in DVD Studio: Since you've had some practice with coding scripts, let me show you the finished "Test Aspect Ratio" script, which you would simply set as a pre-script to the 4x3 version of your content:

DvdspSC5-Finished-Aspect-Ratio-Script.png

...Stumped? Here are the Script Inspector settings for each step:

DvdspSC5-Script-Inspector-Commands.png

This will be the end of my DVD scripting series for the time being - but if you have any questions, or you're interested in other DVD scripting tutorials, please do contact us!

track.backs

Listed below are 0 links to blogs that reference this entry: Scripting in DVD Studio, Part 5: Aspect Ratios and Advanced-ish Math.

TrackBack URL for this entry: http://www.geniusdv.com/weblog/mt-tb.cgi/871

Receive FREE Tutorials by email:

Online and On-Site Training available for most days. Call for available Schedule.

View Upcoming Training Events
Easy PHP Calendar
January 2009
S M T W T F S
28 29 30 31 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
1 2 3 4 5 6 7
Jan 9th
11:00 AM
  (FREE) Sorenson Squeeze Pro
Jan 9th
12:00 PM
  (FREE) Sawmill Professional
Jan 12th -- Jan 16th
9:00 AM - 5:00 PM
  Final Cut Studio Training
Jan 17th -- Jan 18th
10:00 PM - 6:00 PM
  Video Streaming Training (PC)
Jan 31st -- Feb 1st
10:00 AM - 6:00 PM
  Video Streaming Training (Mac)
Feb 2nd -- Feb 6th
9:00 AM - 5:00 PM
  Media Composer Training
Feb 16th -- Feb 20th
9:00 AM - 5:00 PM
  Final Cut Studio Training
Mar 2nd -- Mar 6th
9:00 AM - 5:00 PM
  Media Composer Training
Mar 16th -- Mar 20th
9:00 AM - 5:00 PM
  Final Cut Studio Training
Mar 30th -- Apr 3rd
9:00 AM - 5:00 PM
  Media Composer Training
Apr 27th -- May 1st
9:00 AM - 5:00 PM
  Final Cut Studio Training
 
Search Our Tutorials:
Find on-site Genius training in:
about.this

Brightcove Accelerates Expansion in Japan was the previous entry in this blog.

Converting Images to Fonts, Part 1: Preview is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.