|
|
|||||||||||
| Ultrashock Tutorials > Flash MX 2004 > Flash MX 2004 Professional Video | |||||||||||
|
|||||||||||
|
|
Flash MX 2004 Professional Video |
|
|||||||||
IntroductionFlash MX added true video support and now Flash MX 2004 adds several video enhancements. The most dramatic visual improvement is how the Flash player 7 can now maintain a higher video frame rate. In fact, it's even possible to play videos at a higher frame rate than your Flash document's frame rate. Performance improvements, however, are really just icing on the cake--you just accept the enhancements and enjoy it. In this article you'll learn about the improvements to your production workflow as well as the technical options now available when designing your Flash application. Specifically, this article covers:
|
Audio CompressionYou didn't see any audio compression options when importing the video because that's handled at the time you export the Flash movie. That is, your publish settings for Stream sounds is what gets used for an embedded video's audio. |
The import wizard is a mix of sophisticated options and convenience features to improve your productivity. Once the video is imported into Flash there's really not much new over how you use it. Basically, it's like a Graphic symbol because the timeline where the video resides needs enough frames to accommodate the entire duration.
Next we'll look at both how to create and play native .flv files. You can create .flvs with Flash MX Professional 2004 (and a supported video editor) or one of the other third party tools that create .flvs (such as Sorenson Squeeze with Spark Pro or Wildform Flix). In addition, Flash Communication Server will record live webcam videos as .flv. If you don't have any of these options you can export an .flv from the video you just imported in the tutorial above. Just find the video item in the library, double click, and then click the Export button. (This way you can still follow the tutorial below where we play an external .flv video.)
It turns out that you can still get the ultimate video quality using Sorenson Squeeze with Spark Pro. However a huge work flow improvement is now available to video professionals using tools including Avid Xpress/Media Composer, Apple Final Cut Pro, Adobe After Effects, Discreet Cleaner, and Anystream Agility. Basically, you can edit your video using any of these professional video editors and then export a Flash Video .flv file directly. The figure below shows the export dialog you'll see.
Many of the settings in the Flash Video Exporter dialog box are identical to those available when compressing using Flash. However, one notable addition includes the VBR (variable bit rate) encoding method. This will adjust the bit rate based on the nature of your video content. That is, a few spikes or dips in the bit rate can both support higher quality images as well as keep the file small. Two other options that you won't see in Flash's internal compressor is are the motion estimator and the deinterlace option. The motion estimator allows you to set the compromise between render speed and motion quality. The deinterlace option, on the other hand, is there to remove the interlacing present infor videos created for from television.
The fact you can easily play .flv files without ever importing them into Flash means that once the video stage is complete, the files are ready to display. The video person could just name the files and upload them for your application to display. If you use a tool like Sorenson Squeeze with Spark Pro you can still follow this basic sequence however there's one extra time consuming step: you You must first render the video and then compress it into an .flv file. It's nicer to let the video editor output .flv directly. However, two advantages of Squeeze is are the 2-pass VBR encoding (that which takes twice as long because it analyzes then compresses) and the additional audio compression options (including Fraunhofer MP3). Having said this, it's still way easier to use the new Flash Video Exporter.
Before I show you how to play external .flv files, I should mention that you can also import them into Flash. That is, you can still gain the extra features in the Flash Video Exporter but and still import into Flash. In such a case the .flv imports very quickly because Flash isn't compressing it. However, remember that because Flash compresses the audio at publish time, it's best to only import .flvs with little or no audio compression and adjust Flash's audio compression settings through the publish settings. (to avoid generation loss due to recompression).
You can play external .flvs using script or using the new Media Components. Besides eliminating one step in your production workflow, external .flvs will play at a frame rate independent of the movie that hosts them. We'll first look at scripting it by hand (something you can do in either version of Flash). It turns out Flash MX can play external .flv files too but only through the Flash Communication Server.
Streaming vs. Progressive Download (I should note, that without Flash Communication Server Flash can only do what's called progressive download--not "true streaming".this is still the only way to truly stream media as opposed to Flash's normal progressive download variation of streaming.) Progressive download is when you're able to watch the beginning of a video before the entire length has downloaded. The idea is that by the time you get to the end of the video it has had time to download. For example, traditional QuickTime as well as plain Flash animations play this way. Streaming requires a different protocol and dedicated server. It's possible for streaming servers to make adjustments as the video plays to adjust for changes in bandwidth. Other advantages of streaming include how you can seek to any position in a video as well as set up play lists that play one clip right after another. |
You'll see the code to play external .flvs in Flash MX 2004 is nearly identical to the code when using the Communication Server. Here's a quick tutorial to show you how to play .flvs.

my_nc = new NetConnection();
my_nc.connect(null);
my_ns = new NetStream(my_nc);
my_video.attachVideo(my_ns);
my_ns.play("my_movie.flv");
The my_nc is an instance of the NetConnection object and it is used
when creating the my_ns NetStream instance in line 3. That is, all NetStreams
are channels within a NetConnection. Line 2 is a bit funky as it connects
to null. In an actuallya Flash Communication Server app you'd specify
the address of your server. Finally, line 4 associates the my_video
instance with any media that plays through the my_ns NetStream. Lastly,
the play() method starts the video.You'll find several other methods available to the NetStream object. The only catch is that many of the methods are designed for the Communication Server. They work in Flash too, but sometimes you need to make sure the file is entirely downloaded. For example, if you issued my_ns.seek(45) it would attempt to jump to 45 seconds into your video. But this only works if the video is downloaded.
In order to get more information about the NetStream, there's an onStatus event that triggers and gives you detailed status information. You can use the following code (anywhere about above the play() method in line 5 above) to monitor what's going on:
my_ns.onStatus = function(info) {
for (var i in info){
trace(i+" = "+info[i]);
}
};
For example, I saw this in my output window when the video was done playing:
level = status
code = NetStream.Buffer.Empty
That means, if I wanted to trap this event I could use code like the following:
my_ns.onStatus = function(info) {
if(info.code=="NetStream.Buffer.Empty"){
//display a play button because the video is done
}
};
It turns out that you really have to wait for both the status "NetStream.Play.Stop" as well as "NetStream.Buffer.Empty" but they come at separate times. In the downloadable file, you'll see a much more reliable approach that hides and displays the play button properly.
You'll see in the following section on the Media Components how you can manually add cue points (that get triggered when the video plays). Flash Communication Server (FCS) already has a way to embed string event names while you record a video stream. The reason I mention this here is that those embedded events will also trigger when you play the .flv without FCS. To see this you need to do two things: use FCS record an .flv while embedding events at key moments in time; and, set up a script that responds to those events when you playback the .flv. For example, you can watch a video guided tour at my website (www.phillipkerman.com). You'll see and hear the video, but also--because I embedded events that included my mouse position and mouse clicks--you'll see a cursor graphic that moves around exactly as it did while I recorded the video.
Here's the basic code to embed events into a recorded stream. Note: You need Flash Communication Server to record .flvs this way (the free Developer version works fine.)
//generic FCS connection, stream, and publish
my_nc = new NetConnection();
my_nc.connect("rtmp:/app_name");
my_ns = new NetStream(my_nc);
var my_mic = Microphone.get();
var my_cam = Camera.get();
my_ns.attachVideo(my_cam);
my_ns.attachAudio(my_mic);
record_btn.onPress=function(){
my_ns.publish("myRecordedStream","record");
}
stop_btn.onPress=function(){
my_ns.publish(false);
}
//extra stuff to embed events while recording owner=this;
owner.onMouseDown=function(){
my_ns.send("onClick");
}
owner.onEnterFrame=function(){
my_ns.send("onMoveMouse",_xmouse, _ymouse);
}
Note that I used onEnterFrame instead of onMouseMove to reduce the total
number of events added to the stream. Also, note that I just came up with
two event names "onClick" and "onMoveMouse". You can
add as many as you want--just use the send() method. Finally, notice that
I'm passing two parameters (_xmouse and _ymouse) with with the second
send().
Take video file named "myRecordedStream.flv" (from inside your
"app_name" folder and you can use Flash MX 2004 to play it back
along with the embedded events. Here's the code:
my_nc = new NetConnection(); my_nc.connect(null); my_ns = new NetStream(my_nc);
my_ns.onMoveMouse=function(x,y){
mouse_mc._x=x;
mouse_mc._y=y;
}
s=new Sound(this);
s.attachSound("mouseClickSound");
my_ns.onClick=function(){
s.start();
}
my_video.attachVideo(my_ns);
my_ns.play("myRecordedStream.flv");
You'll need a sound in your Library with the linkage "mouseClickSound"
as well as a clip instance named "mouse_mc" to see this work.
Although using ActionScript to play .flvs is powerful, it's still just
a tad bit more work than necessary. That is, if you have the Media Components
that ship with Flash MX Professional 2004. We'll look at those next.
The Media Components provide the code and graphics to make a complete device for your users to play .flv or .mp3 files. You can populate their parameters manually or access advanced controls using script. In addition, there are sophisticated features such as clear displays of both the current position and the percentage downloaded.

The three Media components include the complete MediaPlayback component
plus broken out parts for just the MediaDisplay and just the MediaController.
So, I suppose it's really just one component that you can break apart
as needed. For example, you could put the controller on the other side
of your screen or display a video with no user controls.
The following simple example demonstrates how to play the .flv video used
earlier. Later we can look at the advanced options.

There are several additional features of the Media Components. Here you'll
explore synchcue points as well as using the MediaDisplay and MediaController
independently.
Sync Cue points let you trigger scripts when an exact point in a video
plays. For example, you might want to synchronize closed captioning to
display every sentence the actor says. There's are two parts to using
sync cue points: sSetting them and using them. Actually, you can add one
step in front of those two: collecting synchcue points. That is, you may
need a system to first determine where synchcue points should occur. We'll
look at the entire process from gathering to inputting to triggering scripts.
Along the way we'll discover a few of the hidden properties and methods
built in to the Media components. Ideally you can find an .flv that's
longer than 5 seconds to use in the following exercise.
_root.onMouseDown=function(){
trace(myMedia.playheadTime);
}
The idea is that we can watch the video and click at the key moments
where we want our sync cue points. The output panel will display the
times that we can then copy into the MediaController's sync cue point
list. You'll have to judge your own video content to pick logical synchcue
points. For example, if I have a video of someone counting I might want
to display a large graphic numeral in synchsync with each number read
aloud. The point is you need to go gather a few synchcue points and
the playheadTime property will help you gather them. 
myObj=new Object();
myObj.cuePoint=function(p){
trace("received sync cue point named: "+ p.target.name);
}
myMedia.addEventListener("cuePoint", myObj);
This code sets up an event listener that responds to the cuePoint event
(built into the MediaController component). (For more information about
this new way components work check out the article xxx on version 2
components.[provided you have such an article]) Notice that the parameter
received (p) has a target property with itselfwhich, in turn, has a
name property. That name will match the names you filled in for synchcue
points. (If you want to dig through other properties received just use
a for-in loop like from step x in the xx exercise above.)contentClip.gotoAndStop(p.target.name);or
someTextField.text=p.target.name;The point is, you now have a way to know when the cue points are reached and it's up to you to decide what to do with that information.
This tutorial answers the question "what do you do for an encore?" That is, video was great in Flash MX but now it's even better. You saw how the import process is improved with a wizard and a way to save profiles; how you can play native FLV files natively without needing to import into Flash; and (if you have Flash MX Professional 2004) how you can use third party video editors to create FLVs plus the set of new media components you get to play external videos in Flash.
By the way, think of this tutorial as a starting point -- not the last word. There's way more you can do to optimize video and additional capabilities of the media components have additional capabilities not covered here. Look for more advanced articles on these subjects soon.
| - discuss this tutorial - |