Video Capture Interview Application using Flash and Flash Media Server Clone

Client asked me:

I am working on this new project involving testimonies. I already made a video of interviews that I roughly edited, but I want to extend the project “to the world”, digitally. So I thought that you could help me with the creation of a basic computer program with which people can answer questions while being recorded in a computer. I would take this program to many venues and cultures and then, I would put together the answers in video films. What do you think?

So the program would do something like this:

– The person sits in front of a computer and the computer presents him/her with the following options (I am improvising here):

1. Please, adjust you image to the camera and say your name and place of origin.

2. Say your birth date (optional).

3. Please, read the following authorization release. This is only for the purpose of the project… (this can be place at the end of the recording….

4. Please, click on the questions below and answer them at your own pace.

etc…

Client is a Macintosh user, and so am I, so I started looking at my options:

  • Applescript Quicktime Player?
  • Flash?
  • Xcode
  • Java App?

It’s been months since I first started his assignment, so I don’t recall in what order I examined solutions and either discarded or investigated more closely and why. But I finally ended up with XCode. I figured it would be a good learning experience.

And it was — to a point. Found some good tutorials that got me started, and I was able to get a feed from my iSight on the screen in fairly short order. And then got stuck. Figured the camera would be the hard part, but in fact it was the text box where the question would appear that stumped me. Banged my head against it n and of for several weeks, slowly forgetting everything I learned at the star of the project, until I finally backburnered it indefinitely.

Finally the client called me and asked how’s it going. Not, I said, but I would look again. Revisited the same options, this time encouraged by the YouTube and Facebook use of Flash. Tried to pirate their Flash apps, but they wouldn’t work outside the context of their own web pages.

I liked the idea of a web based plug-in of sorts for the camera, since once that was done all the text and interaction stuff would be easy, known territory. So now I tried to become an ActionScript programmer.

[Side observation: large IT corporations should not be allowed to develop programming languages. Visual Basic sucks. AppleScript sucks. ActionScript sucks. Java sucks. I long for the days of ANSI Fortran or even C.]

Anyway, masterful googling revealed some examples in the Adobe ActionScript on-line documentation that got me started. I slowly learned that Flash would only send it’s captured video back to a Flash Media Server. I discovered Red5 and Wowza. I discovered to my dismay that Flash would only use the Sorenson H.263 Spark video codec and the Nellymoser audio codec. I really wanted h.264. Too bad. I really wanted MP4, too, but all I could get was FLV. Drat!

My final frustration and triumph was getting the sound and video to sync when viewing the resulting FLV files in QuickTime Player with the Perian universal codec package. The audio track was consistently shorter duration than the video, and seemed to be missing a second or so at the start. Yet when viewed in VLC player or in my Wowza Videorecording Example derived ActionScript code, the first second or so of video seen in Quicktime player was cut off, thus rendering the audio in sync.

I finally hit upon the cure (combination of dumb luck, trial and error, intuition derived from 25+ years of experience): insert a small delay, about 2.5 seconds seemed to work well, between my calls to nsPublish.attachCamera, nsPublish.attachAudio, and nsPublish.publish:

nsPublish.attachCamera(camera);
nsPublish.attachAudio(microphone);
nsPublish.bufferTime = 30;
Wait.text=”Wait for my signal……”;
Wait.opaqueBackground = 0xFF0000;
myTimer.start();

function timedFunction(eventArgs:TimerEvent) {
myTimer.stop();
nsPublish.publish(nameStr.text, (AppendCheckbox.selected?”append”:”record”));
Wait.text=”Start talking!”;
Wait.opaqueBackground = 0x00FF00;
}

Worked like magic.

So the Flash App is written to by default capture 30FPS 640×480 standard definition video at maximum quality and bitrate and send it to a flash media server running on localhost. FPS, width, height, quality settings, and IP address of remote FMS can be configured by FlashVars in calling HTML.

Full example at http://www.uvm.edu/~waw/archives/tina

About Wesley Wright

Born on a mountain top near New York City, Craziest state in the land of the pretty. Raised in the woods so's he knew every tree, Killed him a bear when he was only three.
This entry was posted in Projects. Bookmark the permalink.