Thursday, January 7, 2010

Working with AS3 Video cuepoints

I have been working with cuePoints in flash video and so far have been unable to add actionscript cuePoints and then seek to them. (Update: see solution below)
  • Encode a video: "myVideo.flv" without embedded cuePoints
  • Attach the video to a FLV playback component "my_FLVPlybk"
  • Add cuepoints like this: my_FLVPlybk.addASCuePoint(15, "Cue1");
  • Set up an event Listener to see if the cuepoints are there:
my_FLVPlybk.addEventListener(MetadataEvent.CUE_POINT, cp_listener);

function cp_listener(eventObject:MetadataEvent):void {
trace("Elapsed time in seconds: " + my_FLVPlybk.playheadTime);
trace("Cue point name is: " + eventObject.info.name);
trace("Cue point type is: " + eventObject.info.type);
}

When you run the app, it all works expected. Once the cuepoints are reached it traces out each point. However when you try to go to the cuepoint using this method:

my_FLVPlybk.seekToNavCuePoint("Cue1");

It fails with this error:

VideoError: 1003: Invalid seek
at fl.video::FLVPlayback/seekToNavCuePoint()

Now, this last bit of code works fine if you embed navigation cuepoints in the video itself -- using Adobe Media Encoder (FLV only -- F4V seems not to support cuepoints--at least not well), but according to Adobe it should be possible to add the cuepoints and reference them through actionscript only. In this particular case its not a problem for me since its easier to add the cuepoints to the encoded video, but if anyone has come up with a solution, please post it!


***************************

Update: I found the solution on another forum (http://bit.ly/8EdgdN):

The answer is to locate the cuePoint using findCuePoint() -- which returns an associative array of the point -- and then get the value of "time". At this point you can just do a seek. The final code would be like this:

my_FLVPlybk.seek(my_FLVPlybk.findCuePoint("Cue4", CuePointType.ACTIONSCRIPT)["time"]);

Wednesday, December 16, 2009

Making sense out of MVC in Flex

Now that the video project is nearly out of the way, I'm anxious to get back more to Flex and to do this MVC is a top priority. Looking around the web there are a lot of tutorials but most focus on using frameworks like Cairngorm and PureMVC and very light info on the concepts of MVC and how they are implemented in AS3. Fortunately I stumbled upon this one--from the writers of an OReilly book on the subject -- and it's so good I'm thinking about buying the book:

http://www.as3dp.com/category/design-patterns/mvc/

Tuesday, November 10, 2009

Subtitle issues in DVD Studio Pro

After a lot of experimenting, we have settled on the following subtitle settings for the NTSC and PAL versions of the DVD.

PAL: Helvetica Bold 34pt
NTSC: Arial Bold 29pt

We found that when we used Helvetica Bold for the NTSC version, the lower case "w" was a lot smaller than the other letters and looked very odd. Also the dot on the lower case "i" was not clear so it looked more like an "l".

We also liked that the top stem of the "t" was angled down a bit, making it a bit easier to read. Going back we might have used Arial for the PAL version too but we didn't have the time to test it.

For Persian text we found that the only good way of getting subtitles to look good was to do them in Photoshop -- one by one. We used a black font with a bold yellow outline, saved it as a png and imported into DVDSP. This will show up as a white letter and black outline. Make sure the outline is thick enough.

To do this for both NTSC and PAL:

1. Create the subtitle at 1024x576 (PAL 16:9). White background, black letter, yellow outline. Make sure to create guides for the title safe and keep the subtitle within this area.

2. Keep the subtitles in a separate folder and save backups--you'll use this set of subs to create the compressed NTSC and PAL subtitles.

3. Once you have all of the subs do a batch convert of them and resize them to 720x576. This will give you the PAL subtitles.

4. The do another batch conversion of the original set and resize them to 720x480. This is the required size for NTSC.

As far as our timing between the subtitles, we used a 4 frame gap -- but in retrospect we could have used 3 or 2 if necessary. It was also a happy accident that we did all of this on the PAL timeline (at 25 frames per second) and we were able to use the exact same stl file for NTSC. We didn't test this but I'm pretty sure that DVDSP would cough up an stl file for a PAL project that used the 29 frames per second timing.

Friday, October 16, 2009

Keylistener failing in Flex with creationComplete

Just a quick note. It appears that the stage does not get initialized in a Flex app until the applicationComplete event is fired (not creationComplete).

So if you have an init() function that sets up the listener like this:

private function init():void{
stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDownHandler);
}

calling it from the application tag like this will fail:



but this will work:

AS3 writeUTF vs writeMultiByte with diacriticals, curly quotes and other special characters

I'm working on an Air app that allows a user to modify blocks of video subtitle timecodes. The user can open an stl file, splits the file into an arrayCollection and puts it into a datagrid. They can then select a block of timecodes and adjust them based on the modified start time. This will be a huge timesaver since the film we had completed required a re-edit and we have thousands of subtitles that will now need to be changed as a result.

In any event, when the work is done the user can save the file to the system. In the save process, I naturally used the writeUTF() method but found that although it's supposed to save using utf-8 encoding, things like diacritics, question marks, curly apostrophes and quotes were broken in the resulting file.

So what should have looked like this: “This is a quote”
Looked like this: “This was a quoteâ€o

However, if you use the writeMultiByte() method and set the encoding to utf-8 it works perfectly.

So instead of : fileStream.writeUTF(myText);
try: fileStream.writeMultiByte(myText,"utf-8");

Since Google came up empty for search for the answer to this problem I though I would post this. Maybe it will help someone else....

Wednesday, October 14, 2009

Great replaceAll in AS3

Simple and powerful. Found at:

http://snipplr.com/view/10998/replace-all/


var theContent:String = "Test String with lots of t's"
trace(replace(theContent, "t", "z"));

function replace(str:String, fnd:String, rpl:String):String{
return str.split(fnd).join(rpl);
}

Monday, September 28, 2009

"This PNG contains additional data for Adobe Fireworks, which will be discarded upon save."

This prompt appeared when I had modified a number of files with Fireworks and then tried to execute a batch command in Photoshop on the files:

"This PNG contains additional data for Adobe Fireworks, which will be discarded upon save."

And although I clicked ok for the first file, it appeared again for each one--rendering the batch process useless. I couldn't find a solution in Google, so it seems that the only logical way to solve the problem was to run the batch using a Fireworks command instead. And it is just as easy to create a "command" in FW than an "action" in PS:

1. Open a file in Fireworks
2. Open the History dialog box
3. Make sure the History list is clear
4. Go through whatever steps you wantto modify the image as needed
5. In the History panel, highlight the steps that you want to set as the command
6. In the History options drop down select "Save as Command"
7. Give your command a descriptive name
8. Select File>Batch Process
9. Select the files you want to run the command against
10. In the next step (Batch Process dialog) open the Commands list and select the command you made.
11. Run it
12. Done!