TweetFollow Us on Twitter

September 94 - SOMEWHERE IN QUICKTIME

SOMEWHERE IN QUICKTIME

Media Capture Using the Sequence Grabber

JOHN WANG AND FERNANDO URBINA

[IMAGE 085-088_QuickTime_col._h1.GIF]


A very important and often overlooked feature of QuickTime is the standardization of media capture. Since its initial release, QuickTime has defined an API for capturing different types of media, including video and sound. This API, known as the sequence grabber, makes it possible to easily add media capture to any application.

Not only are applications that use the sequence grabber able to automatically support any QuickTime-compatible media capture hardware, but they also perform flawlessly and efficiently regardless of system configuration. This is not an easy task considering all the variations in hardware features and system configurations. In fact, we're even hesitant to say that the sequence grabber "supports video and sound capture" because the sequence grabber API also insulates the programmer from the actual media type being captured. The sequence grabber supports any media type, and, with the release of QuickTime 2.0, users can automatically capture the new music media type in addition to sound and video.

To demonstrate the proper use of the sequence grabber, we've included on this issue's CD a simple, but complete, sequence grabber application -- all in about 10K of compiled C code! If you're looking for a general all-purpose capture application that's efficient, reliable, and best of all, customizable, look no further. After a brief introduction to the sequence grabber, we'll discuss the sample code, and then end with some special considerations for media capture on Macintosh AV models.

WHAT IS THE SEQUENCE GRABBER?
The sequence grabber is actually a component of type 'barg' (read it backwards). Although the specification for the component is completely defined in Chapter 5 ofInside Macintosh: QuickTime Components , it's very unlikely that you'll ever want to implement your own 'barg' component. Instead, you'll be using this component specification as the API definition for the standard sequence grabber.

The sequence grabber component implements the basic functionality of media capture. For handling specific media-related functions, the sequence grabber calls on various sequence grabber channel components (as defined in Chapter 6 ofInside Macintosh: QuickTime Components ); there's one such component for each media type. Before QuickTime 2.0, the two standard channel components available were the video and sound sequence grabber channels, enabling the sequence grabber to capture video and sound media. QuickTime 2.0 includes the new music sequence grabber channel, allowing real-time capture of music from MIDI instruments.

Sequence grabber panel components (described in Chapter 7 ofInside Macintosh: QuickTime Components ) manage items in a settings dialog box that allows the sequence grabber to obtain configuration information from a user. Applications typically don't use sequence grabber panel components directly; instead, the sequence grabber automatically uses them for relevant sequence grabber component calls.

USING THE SEQUENCE GRABBER
Using the sequence grabber is as simple as opening the sequence grabber component and calling SGInitialize (complete error checking can be found in the sample code on the CD):

theSG = OpenDefaultComponent(SeqGrabComponentType, 0);
SGInitialize(theSG);

It's also important to call SGSetGWorld to set the window used for displaying any visual data.

SGSetGWorld((**myWindowInfo).theSG, (CGrafPtr) myWindow, nil);

Opening the channel components. Now it's a matter of calling SGNewChannel to open a sequence grabber channel component to access a particular channel media type. However, rather than hard- coding the media types into the sample application, as in the call

SGNewChannel(theSG, VideoMediaType, &videoChannel);

it's better to use the Component Manager to search for all the different sequence grabber channel components and open a connection to each one. This guarantees that the capture application can automatically support new media types such as the music media type in QuickTime 2.0.

For example, the following code compiles a list of sequence grabber channel components:

cd.componentType = SeqGrabChannelType;
cd.componentSubType = 0;
cd.componentManufacturer = 0;
cd.componentFlags = 0;
cd.componentFlagsMask = 0;
aComponent = 0;

for (i=0, done=false; i<kMAXCHANNELS && !done; i++) {
    aComp = FindNextComponent(aComp, &cd);
    if (aComp != 0) {
        // Get the channel name and type.
        gSGInfo.channelName[i] = NewHandle(4);
        GetComponentInfo(aComp, &theCD, 
            gSGInfo.channelName[i], nil, nil);
        gSGInfo.channelType[i] = theCD.componentSubType;
    } else
        done = true;
}

This list of component types can then be used to open a connection to each of the media types with SGNewChannel, or SGNewChannelFromComponent if the channel component is already open.

Saving and restoring settings. We want the sample application to start up each time with the same channel settings and video compression settings as when the application was last used. To implement this, we use a preferences file to store these settings. The compression settings are restored with two sequence grabber calls:

SGSetVideoCompressorType(
    (**myWindowInfo).channel[videoChannel],
    gSGInfo.cInfo.compressorType);
SGSetVideoCompressor(
    (**myWindowInfo).channel[videoChannel],
    gSGInfo.cInfo.depth, nil,
    gSGInfo.cInfo.spatialQuality,
    gSGInfo.cInfo.temporalQuality,
    gSGInfo.cInfo.keyFrameRate);

The channel settings are restored by a simple call to SGSetChannelSettings with the settings retrieved from the preferences file:

SGSetChannelSettings(theSG, channel[i],
    channelSettings[i], 0);

Previewing. We're almost ready to begin previewing. But note that some sequence grabber channel components require additional calls before they can be used. For instance, spatial channels such as video require a call to SGSetChannelBounds to set the channel's display boundary rectangle. So, once the channels are created and the previous settings are restored as discussed above, we make a call to SGSetChannelBounds for the video media to set the video capture to encompass the entire window. We also call SGSetChannelUsage for all sequence grabber channels, which tells the sequence grabber that we want to preview and record every channel.

To start previewing, we simply call SGStartPreview. However, while we're previewing, any changes to the system must be handled with care. First, we'll pause the preview whenever an event that requires updating of the channel information occurs. For example, if the capture window is dragged, we'll pause the video, move the window, and then unpause the video. Likewise, if we resize the window, we'll want to pause the preview, resize the window, and then unpause the preview:

// Pause the sequence grabber before resizing.
SGPause((**myWindowInfo).theSG, true);

// Resize and then update the video channel.
SizeWindow(theWindow, width, height, false);
MyUpdateChannels(theWindow);

// OK. We can restart again.
SGPause((**myWindowInfo).theSG, false);

Notice the call to MyUpdateChannels. This is a routine in the sample application that updates the video bounds and channel usage by calling SGSetChannelBounds and SGSetChannelUsage.

The user configuration dialog. Another feature that needs to be handled in a capture application is the user configuration dialog for each of the different capture medias. This is actually one of the simplest things to deal with because the sequence grabber component handles everything. It even stores the settings internally. To retrieve the settings, we can simply call SGGetChannelSettings at a later time. In the sample application, we get the channel settings before we close the connection to the sequence grabber. Then we save the settings in the preferences file.

This is all the code necessary to display and handle the user configuration dialog:

SGSettingsDialog(theSG, theChannel, 0, nil, 0, nil, 0);

Recording. The last important part of the sample code is sequence grabber recording. Before recording can begin, we need to specify an output file with SGSetDataOutput so that the sequence grabber knows where to save the captured media data:

StandardPutFile("\PName of new movie:", "\pMovie", &reply);
if (!reply.sfGood)
    return;
SGSetDataOutput(mySG, &reply.sfFile, seqGrabToDisk);

Then we start recording by simply calling

SGStartRecord(theSG);

We loop and call SGIdle until the mouse button is pressed to stop recording. This is the most efficient way to record: we don't want to call WaitNextEvent, since that would give other processes time. Instead, we want to hog the CPU time until the recording process is done.

while (!Button() && !err) {
    err = SGIdle(theSG);
}

We stop recording and start previewing again as follows:

SGStop(mySG);
SGStartPreview((**myWindowInfo).theSG);

And, of course, just to be nice, we flush the mouse-down events so that no application switching takes place after the mouse button is pressed:

FlushEvents(mDownMask, 0);

That's really all there is to the sequence grabber sample application.

SPECIAL CONSIDERATIONS FOR AV MODELS
As mentioned earlier, one of the key features of the sequence grabber is its ability to work with all hardware and system configurations. This is not an easy task considering all the different types of video capture boards. For example, there are boards that are simply frame grabbers, and there are those that support on-board hardware video compression. To make every configuration work, the sequence grabber has to handle every case. Here we'll discuss the unique features of the Macintosh AV models and some steps you can take to improve their capture rate.

The video-in circuitry allows the AV models to display 16-bit color and 8-bit grayscale. And, although the hardware can't display video-in at 24 bits per pixel, you can capture video using YUV 4:2:2 compression and achieve an effective 24 bits per pixel. To capture in YUV, you must use the AV's video digitizer hardware compression feature, which you can do simply by selecting "Component Video - YUV" from the list of compressors in the Compression panel of the video settings dialog. You should also make sure that you haven't checked a "Post Compress Video" or similar checkbox in a movie-grabbing application. Selecting this checkbox would bypass the hardware compression, and the sequence grabber would grab the data in raw RGB format.

The AV circuitry can't display video when it's capturing the compressed data. The sequence grabber realizes that it needs to decompress the data into the capture window in order to give the visual feedback that's normally expected. This is fine and dandy, but since there's no hardware decompression in the system, the image decompression is completed in software. This degrades the capture rate.

Knowing that the decompression during recording is what's hurting the capture rate, you can easily rectify the problem by turning off preview during recording so that decompression into the capture window won't take place. To do this, you just call SGSetChannelUsage for the video channel with the seqGrabPlayDuringRecord flag set to 0. In the sample code, a menu selection allows you to turn off video playthrough during recording.

The downside of using YUV compression is that playback without hardware decompression isn't very smooth because of the high data rate and raw processing power needed to decompress each pixel. After capturing, you should recompress the movie using a compressor such as Cinepak or Video that provides a better playback rate.

GO MAKE A MOVIE
The sequence grabber obviously makes the job of media capture simpler. But there are many other factors that can play a part. Hard drive transfer rate, disk fragmentation, SCSI bandwith, sound settings, and AppleTalk activity all play an important part in limiting the maximum capture rate. You can also maximize the capture rate by rebooting with no AppleTalk connections. You should also experiment with the different sound sample rates, as these also affect the capture rate.

New additions to the sequence grabber in QuickTime 2.0 also help. Instead of capturing to a single movie file, it's now possible to specify a different file for each channel. For example, you can record video to a large and fast external hard drive and record audio to the internal hard drive. This optimization allows for better allocation of resources and better efficiency because each channel has higher bandwidth. Using the sample code, if QuickTime 2.0 is installed, you can select recording to separate files.

There are, of course, other optimizations that can be explored. With a bit of creativity and testing, you can achieve the optimal capture rates.

RELATED READING

  • Inside Macintosh: QuickTime Components , Chapters 5-7, and Inside Macintosh: More Macintosh Toolbox , Chapter 6, "Component Manager" (Addison-Wesley, 1993).
  • "Video Digitizing Under QuickTime" by Casey King and Gary Woodcock, develop Issue 14. About the sequence grabber and video capture.

JOHN WANG (AppleLink WANG.JY) While writing the sequence grabber sample code for this column, John watched the movie Top Gun so many times that he can now duplicate each and every air combat scene with his favorite flight simulator, FA/18 Hornet. John once aspired to become a private pilot, but that idea was quickly quelled once his significant others found out. As Skate so succinctly put it, "Woof woof wooof?" Translation: "Who's going to feed me if you kill yourself?"*

FERNANDO ("NANO") URBINA (AppleLink NANO) uses his Macintosh AV to capture the views of the Rockies from his home office in Colorado Springs. He still doesn't understand how it can thunder and snow at the same time, but thinks he'll be able to figure this out once he adjusts to the lack of oxygen. Nano suffers severe withdrawal from his favorite coffee shop near the Apple campus in Cupertino, but manages to get a fix about once a month when he returns there. He worked on the original AV models and is now a member of the second-generation AV team. *

Thanks to Peter Hoddie and Don Johnson for reviewing this column. *

 
AAPL
$116.47
Apple Inc.
+0.16
MSFT
$47.98
Microsoft Corpora
-0.72
GOOG
$537.50
Google Inc.
+2.67

MacTech Search:
Community Search:

Software Updates via MacUpdate

Cobook 3.0.7 - Intelligent address book....
Cobook Contacts is an intuitive, engaging address book. Solve the problem of contact management with Cobook Contacts and its simple interface and powerful syncing and integration possibilities.... Read more
StatsBar 1.9 - Monitor system processes...
StatsBar gives you a comprehensive and detailed analysis of the following areas of your Mac: CPU usage Memory usage Disk usage Network and bandwidth usage Battery power and health (MacBooks only)... Read more
Cyberduck 4.6 - FTP and SFTP browser. (F...
Cyberduck is a robust FTP/FTP-TLS/SFTP browser for the Mac whose lack of visual clutter and cleverly intuitive features make it easy to use. Support for external editors and system technologies such... Read more
Maya 2015 - Professional 3D modeling and...
Maya is an award-winning software and powerful, integrated 3D modeling, animation, visual effects, and rendering solution. Because Maya is based on an open architecture, all your work can be scripted... Read more
Evernote 6.0.1 - Create searchable notes...
Evernote allows you to easily capture information in any environment using whatever device or platform you find most convenient, and makes this information accessible and searchable at anytime, from... Read more
calibre 2.11 - Complete e-library manage...
Calibre is a complete e-book library manager. Organize your collection, convert your books to multiple formats, and sync with all of your devices. Let Calibre be your multi-tasking digital... Read more
Herald 5.0.1 - Notification plugin for M...
Note: Versions 2.1.3 (for OS X 10.7), 3.0.6 (for OS X 10.8), and 4.0.8 (for OS X 10.9) are no longer supported by the developer. Herald is a notification plugin for Mail.app, Apple's Mac OS X email... Read more
Firetask 3.7 - Innovative task managemen...
Firetask uniquely combines the advantages of classical priority-and-due-date-based task management with GTD. Stay focused and on top of your commitments - Firetask's "Today" view shows all relevant... Read more
TechTool Pro 7.0.6 - Hard drive and syst...
TechTool Pro is now 7, and this is the most advanced version of the acclaimed Macintosh troubleshooting utility created in its 20-year history. Micromat has redeveloped TechTool Pro 7 to be fully 64... Read more
PhotoDesk 3.0.1 - Instagram client for p...
PhotoDesk lets you view, like, comment, and download Instagram pictures/videos! (NO Uploads! / Image Posting! Instagram forbids that! AND you *need* an *existing* Instagram account). But you can do... Read more

Latest Forum Discussions

See All

Ubisoft Gives Everyone Two New Ways to E...
Ubisoft Gives Everyone Two New Ways to Earn In-Game Stuff for Far Cry 4 Posted by Jessica Fisher on November 21st, 2014 [ permalink ] | Read more »
Golfinity – Tips, Tricks, Strategies, an...
Dig this: Would you like to know what we thought of being an infinite golfer? Check out our Golfinity review! Golfinity offers unlimited ways to test your skills at golf. Here are a few ways to make sure your score doesn’t get too high and your... | Read more »
Dark Hearts, The Sequel to Haunting Meli...
Dark Hearts, The Sequel to Haunting Melissa, is Available Now Posted by Jessica Fisher on November 21st, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Meowza! Toyze Brings Talking Tom to Life...
Meowza! | Read more »
Square Enix Announces New Tactical RPG f...
Square Enix Announces New Tactical RPG for Mobile, Heavenstrike Rivals. Posted by Jessica Fisher on November 21st, 2014 [ permalink ] With their epic stories and gorgeous graphics, | Read more »
Quest for Revenge (Games)
Quest for Revenge 1.0.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0.0 (iTunes) Description: The great Kingdom of the west has fallen. The gods ignore the prayers of the desperate. A dark warlord has extinguished... | Read more »
Threadz is a New Writing Adventure for Y...
Threadz is a New Writing Adventure for You and Your Friends Posted by Jessica Fisher on November 21st, 2014 [ permalink ] In the tradition of round-robin storytelling, | Read more »
SteelSeries Stratus XL Hardware Review
Made by: SteelSeries Price: $59.99 Hardware/iOS Integration Rating: 4 out of 5 stars Usability Rating: 4.5 out of 5 stars Reuse Value Rating: 4.25 out of 5 stars Build Quality Rating: 4.5 out of 5 stars Overall Rating: 4.31 out of 5 stars | Read more »
ACDSee (Photography)
ACDSee 1.0.0 Device: iOS iPhone Category: Photography Price: $1.99, Version: 1.0.0 (iTunes) Description: Capture, perfect, and share your photos with ACDSee. The ACDSee iPhone app combines an innovative camera, a powerful photo... | Read more »
ProTube for YouTube (Entertainment)
ProTube for YouTube 2.0.2 Device: iOS Universal Category: Entertainment Price: $1.99, Version: 2.0.2 (iTunes) Description: ProTube is the ultimate, fully featured YouTube app. With it's highly polished design, ProTube offers ad-free... | Read more »

Price Scanner via MacPrices.net

Save up to $400 with Apple refurbished 2014 1...
The Apple Store has restocked Apple Certified Refurbished 2014 15″ Retina MacBook Pros for up to $400 off the cost of new models. An Apple one-year warranty is included with each model, and shipping... Read more
New 13-inch 1.4GHz MacBook Air on sale for $8...
 Adorama has the 2014 13″ 1.4GHz/128GB MacBook Air on sale for $899.99 including free shipping plus NY & NJ tax only. Their price is $100 off MSRP. B&H Photo has the 13″ 1.4GHz/128GB MacBook... Read more
Apple Expected to Reverse Nine-Month Tablet S...
Apple and Samsung combined accounted for 62 percent of the nearly 36 million branded tablets shipped in 3Q 2014, according to early vendor shipment share estimates from market intelligence firm ABI... Read more
Stratos: 30 Percent of US Smartphone Owners t...
Stratos, Inc., creator of the Bluetooth Connected Card Platform, has announced results from its 2014 Holiday Mobile Payments Survey. The consumer survey found that nearly one out of three (30 percent... Read more
2014 1.4GHz Mac mini on sale for $449, save $...
 B&H Photo has lowered their price on the new 1.4GHz Mac mini to $449.99 including free shipping plus NY tax only. Their price is $50 off MSRP, and it’s the lowest price available for this new... Read more
Check Apple prices on any device with the iTr...
MacPrices is proud to offer readers a free iOS app (iPhones, iPads, & iPod touch) and Android app (Google Play and Amazon App Store) called iTracx, which allows you to glance at today’s lowest... Read more
64GB iPod touch on sale for $249, save $50
Best Buy has the 64GB iPod touch on sale for $249 on their online store for a limited time. Their price is $50 off MSRP. Choose free shipping or free local store pickup (if available). Sale price for... Read more
15″ 2.2GHz Retina MacBook Pro on sale for $17...
 B&H Photo has the 2014 15″ 2.2GHz Retina MacBook Pro on sale for $1799.99 for a limited time. Shipping is free, and B&H charges NY sales tax only. B&H will also include free copies of... Read more
New Logitech AnyAngle Case/Stand Brings Flexi...
Logitec has announced the newest addition to its suite of tablet products — the Logitech AnyAngle. A protective case with an any-angle stand for iPad Air 2 and all iPad mini models, AnyAngle is the... Read more
Notebook PC Shipments Rise Year-Over-Year as...
According to preliminary results from the upcoming DisplaySearch Quarterly Mobile PC Shipment and Forecast Report, the global notebook PC market grew 10 percent year-over-year in Q3’14 to 49.4... Read more

Jobs Board

*Apple* Solutions Consultant (ASC)- Retail S...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Project Manager, *Apple* Financial Services...
**Job Summary** Apple Financial Services (AFS) offers consumers, businesses and educational institutions ways to finance Apple purchases. We work with national and Read more
*Apple* Store Leader Program - College Gradu...
Job Description: Job Summary As an Apple Store Leader Program agent, you can continue your education as you major in the art of leadership at the Apple Store. You'll Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.