Demos
- AS3 Particle Node Sequencer
- ARP O Matic
- Theramin with Tonfall
- Image/Pixel translation with Flashamaphone (sorry it’s in AIR, not on the web)
- Tone Matrix with Tonfall
- Mobile piano with Flashamaphone
{ creative developer }
Filed in development | flash/flex | flex | music | web Leave a comment
Demos
Filed in development | flash | flash/flex | flex | html5 | ios | javascript | ui | video | web Leave a comment
Lets face it, Apple really stuck us in a bad situation. While HTML5 is really slick on the desktop (in supported browser with supported file types), its pretty clunky on iOS. And Flash is ALSO really slick on the desktop, but doesn’t work at all on iOS.
So what we are left with are 2 things that work really well on the desktop, but no common thing that works well on Android, iOS, and the desktop.
What can we do?
Native iOS
Simply the best option on iOS now is to sign up for a developer’s license and make an app. iOS offers two different video player frameworks MPMoviePlayer and AVPlayer. MPMoviePlayer is the simplest to get started with, and offers you playback through the Quicktime UI. AVPlayer is harder to get started with and you are forced to create your own UI, but you have more control over video playback.
AIR for Mobile
What may be the best solution is to build a Flash player with HLS streams on iOS and normal HTTP or RTMP streams on Android or the desktop. While it’s true that Flash isn’t supported on iOS, Flash Builder 4.5 can compile your existing project out to iOS and Android applications. All Flash video is supported in AIR, Mobile AIR and the web Flash player – except for iOS. So you’ll need the two different streams.
Corona and other 3rd Party Packagers
Corona seems to be a very popular way to create cross platform mobile apps these days. There are other packagers as well like Titanium, Appcelerator and more. Last I looked they don’t handle video, or don’t handle video very well. Probably the best is Corona which does allow video to play, but it needs to launch the video in a modal window or fullscreen, and you have little control over it. As cool as these solutions are, I don’t believe that they handle video all that well.
Filed in development | flash | flash/flex | flex | html5 | ios | javascript | ui | video | web Leave a comment
Before we conclude this series, I should mention something nobody likes – but they are an absolute necessity if content producers are going to put their video online in the first place.
Those things are ads and reporting.
Content owners want to monetize their video, and be able to track many aspects of it’s usage to make better decisions about video you’re watching.
With Hulu, Netflix, and many networks putting first run television online it seems that web video is gaining on what we watch on cable TV, and we may see a day soon when the web is significant enough to eat into cable tv’s revenue model such that we’ll networks and content producers who want to thrive can’t afford to just be on one or the other.
As ad revenue from cable tv and network broadcasts are shifted, owners will want to make sure this money is JUST shifted and not lessened. So even today, folks are experimenting with longer ad breaks to see if they can get away with the same video experience you see on TV.
To accomplish this, we need some good 3rd party libraries from ad companies and reporting companies, as well as decent support on the actual device, browser, or plugin to facilitate these advanced needs. If we can’t come up with creative solutions to accommodate ads and reporting, companies will simply not come – and this can make or break a platform’s usefulness for serving video.
3rd Party Library maturity
I’ve been working with Flash video extensively for a few years now, and in that time I’ve seen 3rd party frameworks and libraries delivered to us from various ad and reporting companies (many revisions in fact). Flash seems to have a lock on maturity of 3rd party libraries for handling these things. Flash has almost maniacal support for every aspect of playing video – something you won’t see from HTML5, or even iOS (from what I’ve seen so far). In truth, this is why Flash is difficult to work with for video newcomers. But, at the same time it offers extreme control to allow almost anything we need. We can offer midrolls, prerolls, postrolls, companions, overlays and more. We can also track video buffering events, stream transitions, and many more minute details.
HTML5 video, on the other hand doesn’t have this level of control – especially in iOS given the playback obstacles we’ve discussed. Given this – many 3rd party libraries are still figuring out how to offer the same level of ads and reporting we can obtain from Flash players.
One company I work with just recently started offering midroll ads, where before their Javascript/HTML5 video solution wasn’t mature enough to do this. They seem to be coming along just fine, but won’t be caught up to Flash anytime soon! See part 6 for my experiences working with mid roll ads.
Advertising with MP4 – At Least that’s Easy!
I’ve talked about iOS streaming for long-form content. It uses Apple’s HLS, and is pretty much incompatible with Flash or Silverlight. As a result, content owners will need to completely re-encode their streams for Apple devices – that is IF they want it to be streaming.
Many advertisers these days, however, will serve up their ad creatives as mp4 files encoded with h264. This works on Flash, and it ALSO works on iOS, Chrome, and IE. This means that if these advertisers wanted to use their same ads on iOS, they’re free to do so without have to re-encode the files!
Companion Ads and Banners
The same can’t be said for companion ads, however. Companion ads are static or animated images that you see outside the video player area (usually in another div on the page). The problem is that these ads, in my experience, aren’t static images and usually animated Flash. This means that advertisers and content producers need to work together to create new companion creatives and serve them up appropriately for Flash or iOS.
Filed in development | flash | flash/flex | flex | html5 | ios | javascript | ui | video | web Leave a comment
So we talked about how Apple supports both progressive and streaming video with their HTML5 video tag. We also briefly discussed how Flash Media Server serves up its OWN streams. What about Apple’s HTTP Live Streaming? What kind of magic is that?
Turns out that its quite simple. Take a video file, after encoding it for HLS you’ll end up with a directory of files. First off there is a table of contents file. This table of contents files points to MORE table of contents files, and these point to video file segments.
The video segments are most likely h264 encoded segments. Each one has a “ts” file extension (myfile.ts). ”TS” stands for transport segment. Each segment will most likely be small, about a megabyte or so and contain several seconds worth of video (this is entirely left up to the encoder settings).
The table of contents files sound a little hacky, but they work well. Apple has gone ahead and adopted m3u8 playlist files for streaming video. What’s that you ask? What’s m3u8? Well, if you crack open Winamp or iTunes, you can create a music playlist. Both m3u and pls files are pretty standard for holding playlists of songs. The m3u8 spec is an enhanced version of this (and still used for music playlists!). It makes sense though, you’re really just assembling a playlist of video segments.
I also mentioned playlists in playlists didn’t I? Well, the master m3u8 file will typically hold several different bitrate references (for if a user wants high definition, low definition, or anything in between). This file will hold references to other m3u8 files and list what their bitrates are in bytes per second.
The reference m3u8 files will be the ones that actually list the segments, examples are listed below.
First is an m3u8 file referencing OTHER m3u8 files for the different bitrates:
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=200000
http://ALPHA.mycompany.com/lo/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=200000
http://BETA.mycompany.com/lo/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=500000
http://ALPHA.mycompany.com/md/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=500000
Next up is an example of the actual m3u8 file that holds all of our file references.
#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10, no desc
fileSequence0.ts
#EXTINF:10, no desc
fileSequence1.ts
#EXTINF:10, no desc
fileSequence2.ts
#EXTINF:10, no desc
fileSequence3.ts
#EXTINF:10, no desc
fileSequence4.ts
#EXTINF:10, no desc
…..
#EXT-X-ENDLIST
Live Playback Limits on HLS
In the example above, notice the line #EXT-X-ENDLIST. This command marks the end of the file. This an important piece of info! It tells Quicktime that there will be no more segments after this, and what we have in the file is the entire stream.
What if this line didn't exist? Well, it turns out that the absence of this line indicates to Quicktime that the m3u8 file is a live stream. In this regard, the file has no end. With a VOD (video on demand) stream, Quicktime only needs to query this table of contents once, and the player is secure in it's knowledge that there is nothing else to load. For a live stream, the m3u8 file is repeatedly queried to find out what the latest segments are so the player can keep up with the most recent segments.
This is a nifty little system - but there's a problem. Typically, a live event will allow the end user to watch in a 30 minute or so sliding window. The user can't seek backwards more than 10 minutes or so. These older segments are dropped from the m3u8 file such that the m3u8 file only contains a handful of segments.
The problem is if you need a long stream. My last project had a need to run clips from a large 14 hour stream. When playing through HTML5 on a web page, the stream broke down after it grew to 40 minutes or so. The problem was that the growing number of entries referencing transport segments made the file grow exceptionally large after a while. If I recall correctly, a 10 hour stream's m3u8 file was around 600kb for me. Multiply that by 3 for the other bitrates I had. So eventually, Quicktime was constantly querying over a megabyte of playlist info - and it had trouble keeping up with playback!
I came up with the solution of having our encoding team put a fake end on the m3u8 file even though it was live. This caused the file to only be loaded once even though the live stream was continually playing. It doesn't work for a lot of situations since you're not able to play the most recent stuff since you loaded the file, but it worked for our specific needs with our site!
Miraculously, it seems that this is only a problem in HTML5, and not a problem if you're just running Quicktime natively or in an app.
Other Streaming Services
I don't have any experience with Silverlight, but IIS's Smooth Streaming functions pretty much the same way. Instead of an m3u8 file, Smooth Streaming has an XML format for it's table of contents.
We discussed how Flash Media Server worked in a previous post in this series - but to recap, it can generate these segments on the fly and serve them over RTMP, HTTP and for Flash or iOS.
Playback in Flash doesn't have the same length issues that iOS HTML5 has for live streams. It plays things back fairly well! HLS and SmoothStreaming though, have a pretty important feature on Flash - bitrate switching happens automatically between the server and the player. You don't need to program anything extra in your code to make bitrate switching work - and it does work very smoothly! You'd be hard pressed to notice the transition.
Flash recently implemented a smooth stream switchover as well. You as a developer, must measure bandwidth and make the switch yourself (though OSMF will do this automatically for you). Once you call the "play2" command, it will START making the switch, but it will wait until the next video keyframe to make the switch so its as seamless as HLS and Smooth Streaming make it.
Filed in development | flash | flash/flex | flex | html5 | ios | javascript | ui | video | web Leave a comment
We’ve discussed in part 4 of this series that Flash can get a little complicated. It’s true, but it mostly boils down to the different video formats you can play. Let’s talk about those formats.
Progressive Video
If you are clueless about what the difference is between streaming and progressive video – chances are the video you know and love is said to be “progressive”. What does this mean?
Well, if you hit a single video file on a server somewhere and start downloading it, you can actually watch the video before it finishes downloading. You are using it “progressively” in that you are watching it while download is in progress. This happens in much the same way as if you had an image loading on a slow connection and you see it start at the top and fill in as it gets loaded.
One of the problems I’ve seen from progressive video files (at least when playing from Flash) is when the MOOV Atom is placed at the end of the file by the video encoder. Think of the MOOV Atom as a block of data in the file that holds info about your video…like duration, bitrate, frame rate, encoding specs, etc. If this is place at the end of the file, the player doesn’t know the details of your video file, and won’t play it UNTIL it gets this block of data. Since it’s at the end of the file, users need to wait until the entire video file is downloaded so that the video player knows exactly what it’s playing.
Streaming Video
So, speaking progressively, video is one large video file that you download and cache to your computer (or at least that’s whats happening behind the scenes in your browser) for playback.
On the other side of the coin, we have streaming playback. Typically a streaming file will be served from some sort of media playback server as a lightweight container file that serves as a table of contents for many smaller video segment files. The lightweight container file will be loaded once up front (or continually if it is often updated like when you are connected to a live stream). Your player will then be smart enough to know what segment files are needed to playback video. It will go out and grab these segments, and then throw them away when you’re done. A player will keep a “buffer” that may or may not be able to be set by the player of how many seconds of video to keep (and therefore how many video segments). If you have video buffered, you can easily seek back and forth to these points instantaneously. If on the other hand, you seek outside the buffer, the player will have to read the table of contents container and lookup which video segments to fetch and buffer for you.
The Flash Media Server will hide all the complexities from you, though. Usually, you’ll just connect to a path that starts with rtmp:// and ends with myfile.mp4. For all YOU know it’s just a file, not chunked up into tiny segments. And actually it sort of IS one big file. Flash Media Server will just tranform this file into a stream for you on demand, so its easy to manage and still works like a stream.
Flash Media Server, in recent days, has actually started supporting streams over HTTP for Flash and iOS. This means that if your company doesn’t want to deal with serving stuff over RTMP, you can just use HTTP streams and Flash 10.1 (and OSMF if you don’t want to program support yourself). You can use your same server and files to send a stream to iOS! Kind of a timesaver if you need to support both, instead of managing all 2 separate servers/encoders.
Use Cases for Each
Why use streaming vs progressive? Well the major reason is what we in the business call “long-form video”. Long form video is typically 20 minutes to a few hours long, while ”short-form video” is under a minute or a few minutes long. YouTube clips are perfect examples of short form video. And they are also decent examples of why the overhead of having a streaming service and player is completely unnecessary. If it’s only a few megabytes, then it really doesn’t take long to load and cache the whole video does it? And in the end, when you close your browser you’ll only have a few MB from it in your cache or in your memory.
Long-form, on the other hand, can be several hundred megabytes or even a couple of gigabytes depending how long the video is and what quality it was encoded at. Not only will you be left with a behemoth of a file in your RAM or cache, but it you can’t seek forward to skip over pieces until that much has been downloaded.
Another benefit of streaming is the ability to switch between bitrates or cameras. If your video player thought that it was having difficulty keeping up with your HD file, ideally, you’ll switch to a lower resolution video. It’s REALLY difficult and pointless to do this on a progressive file. You’d have to latch on to a different file, and then seek to the position you left off at….which means you’d have to progressively download the file up to the point where you left off which could take several minutes! With a stream, all you have to do is tell the server to start sending you different file segments. It will do so, and the player will never be the wiser, cause all it sees is new segments coming in – it doesn’t really matter if they are from a different source file.
So that coupled with a server’s ability to offer DRM is a huge reason why TV shows and movies are all streaming. While there are many DRM solutions available, one fact is that when you segment all your files like this (even without DRM), its a pain in the butt to download and assemble them all if you were so inclined to steal content. Flash Media Server obfuscates the stream even more by serving it over RTMP. Since it’s an entirely different protocol than HTTP, most standard web dev tools won’t even see the files come through and its even more difficult to steal!
Contrast this with YouTube. Most of the time, I can go in and open up my Chrome developer tools, watch a big file come in, and copy the source URL. I can then download the file and rename to a mp4 or flv file and then play it on my desktop. BAM! I just stole content and it took 30 seconds.
Something in between (pseudo-streaming)
You may have noticed recently in YouTube, where it shows you a red line in your progress bar to indicate your downloaded buffer. In years past, you couldn’t seek beyond this. Well, now you can! How is this possible?
It’s do-able because many servers (even if just a simple Apache server running PHP) allow the browser request to specify a byte range. Typically when you make a file request from your browser you ask for the file, and it ASSUMES you want all the bytes of the file starting at the beginning of the file. What pseudo streaming does is to ask for the file, but ask for the bytes at a certain position in the file and not to start at the beginning.
What’s Possible in HTML5 vs Flash
Pseudo Streaming is actually very popular these days because the HTML5 video tag supports it natively. To use it, you as a developer don’t have to do a thing beyond allowing your user to seek (as well as having a server that supports byte ranges). Contrast this with Flash – where you’d need to jump through hoops to get this working. Flash doesn’t support byte ranges with video or audio, which means you’d have to load the bytes MANUALLY, and then append the bytes onto the active video stream. Not only does this suck to code, but appending bytes to a stream wasn’t even supported until Flash Player 10.1.
Of course, progressive is supported in both HTML5 and Flash. Flash supports a few different encoding types including mp4/h264 just like HTML5 normally does (depending on the browser).
Here’s the bombshell though…HTML5 does not support actual streaming, and there is no official proposed spec for it! I bet you don’t believe me because of a certain large, fruity corporation. It’s true though! More on that in the next part. But the long story short here, is that I can’t imagine recommending HTML5 for long form content, doing 2 hour movies with a progressive download would be beastly (note that there may be clever ways, I just don’t know what they would be beyond artificially breaking up the video files and leaving gaping holes in playback while loading the next segment).
Filed in development | flash | flash/flex | ui | Uncategorized | video | web Leave a comment
The interesting thing about Flash is that before some recent projects, it was much harder to get a basic player going. Video playback is composed of three basic elements: the NetStream, the NetConnection, and the Video object.
To start playback, you’d need to create a NetConnection, connect to a server if streaming or null if a normal progressive file, start a new NetStream with the NetConnection, and finally attach a the NetStream to a video object.
connection = new NetConnection();
connection.connect(null);
stream = new NetStream(connection);
stream.client = this;
video = new Video();
video.attachNetStream(stream);
stream.play("myfile.mp4");
addChild(video);
Not only that, but you’ll need to add the video to the stage, and manage the aspect ratio of the video properly. You’ll also need to publish a SWF, and embed it on the page.
It’s a heck of a lot more complicated than a simple HTML video tag, isn’t it?
Adobe’s Open Source Media Framework
A couple of years ago, Adobe set out to make things less complicated – to create a framework that can simplify video playback as well as provide an easy plugin architecture for ads, reporting, and more. This framework can handle any video type that Flash can handle without you needing to worry about what type of video you’re playing.
Let’s check out how to get a simple video up and running:
playerSprite = new MediaPlayerSprite(); playerSprite.media = new VideoElement( new URLResource( "myvideo.mp4" ) ); addChild( playerSprite );
You’ll still need to compile and embed on a page as well. This is only 3 lines of code as opposed to the 8 without OSMF. Its not necessarily the amount of lines of code I’m concerned with, it’s that to really know what’s going on, you need to know what the NetStream, NetConnection, and Video objects all do. It can take a bit of research to put all those pieces together! In other words, OSMF is more intuitive to me – you create a playback sprite, and then assign some media to it
The extra good thing is that we can handle most file types. We’ll get back to this in a bit, but as you use streaming media, worry about hooking up a control bar, things get exponentially more difficult. OSMF makes this nice and tidy for you. I must warn you though, as you start doing weird things with your video playback, you’ll need to learn the language and architecture of this framework. Normally though, things are quite simple to use through the framework’s API.
Strobe and Flash Media Playback
Can it get easier maybe? Answer is yes! All levels of ease seem to be taken care of – from the insanely detailed and comprehensive to having a ready made SWF pre-compiled for you and ready to use!
The next level here is the Strobe Media Playback project. This project is already compiled and ready to go…ready to be embedded on a page. It comes with some external configuration and external skinning options if you need to change anything around. In addition to the compiled SWF, it comes with all the source code to the player as well – so if there’s anything you need to change with code, you’re welcome to make the change and compile again!
Can it get easier? Yes! There’s Flash Media Playback. If you follow the link, Adobe brands it as “Instant Video Playback on your Website”. Flash Media Playback is an extension of Strobe Media Playback – however, you don’t download any files. Adobe hosts the player, you simply grab the embed code and perhaps make your own configuration file that you point it too to handle the customization aspects you need. Adobe offers a configuration and test playback page for you to get started.
Other 3rd Party Players
There are plenty of players out there in the same vein as Flash Media Playback, and most have probably been around longer! The most popular ones that I’m aware of are JWPlayer, FlowPlayer, and the BrightCove (which has an entire video publishing platform)!
Typically you’ll embed these on your page and pass in one or several “flashvars” to tell it what video to play. I don’t have much experience with these 3rd party players, but most cost money if you’d like to use them commercially.
As you can see, using video in Flash can range from drop dead simple to mind boggingly complex. More on why this is in the next part of this series. What’s good is that there are several projects you can take advantage of to get simple playback on your website with no or minimal Flash experience….without even having to buy or touch a compiler even!
Filed in development | flash | flash/flex | html5 | video | web Leave a comment
Simple playback
Simple playback is just that! Simple. This can be a very good thing. Offering a video up via the tag allows for easy playback. Easy for the user, and easy for the page developer!
<video width="640" height="360" controls src="myvideo.mp4"></video>
See that?! It’s just like an image tag! Put a source, height, and width on that tag, and you’ve got video!
Native vs Custom Controls
I avoided mentioning the part of that tag that reads “controls” when I was laying out the video tag above. Basically the presence of this tag means that you’re telling the browser: “Yes I would like you to displayo your standard video player controls”. Many times developers will write controls=”controls”, controls=”true”, etc. All mean you want the browser’s native video controls on your video.
Normally, these controls include play and pause buttons – as well as a volume slider and progress/seek slider. These controls will look different as you bounce between Chrome, Safari, Firefox, IE, and devices.
So, if a consistent look/feel across devices and browsers is in your customers best interest, its time to ditch the native controls. Likewise, if your customer has additional buttons that they would like to add to the control bar, such as an “information about this video” button, it might be time to ditch the native controls.
Basically, once ANY customization is required to the players control bar, you’ve crossed into building everything yourself.
What’s involved in doing custom controls? Well, now we’re talking about creating individual buttons and sliders ourselves. These buttons and sliders need to hook into the video tag’s Javascript API. After creating our controls, we’ll need to stylize them with CSS to overlay them over the video and act like a real control bar.
This isn’t necessarily a bad thing, the video tag has a pretty decent API. It’s a little bit of work, but you didn’t think you were getting a custom skin for free right?
Javascript API
CSS is beyond the scope of this post – but needless to say, you’ll most likely be relatively or absolutely positioning your control bar and making sure the z-order is higher than that of the video. You’ll also probably use some nice jQuery animation for when the user mouses over the video area to auto-show the control bar.
Once you’ve fleshed that out, you’ll be wiring up your buttons!
Obviously your play button would call video.play(); Or would it? What if the video was already playing – it might call video.pause() instead! Play/pause buttons are usually grouped together in a playback toggle button. You’ll need to handle this logic yourself as well as update any buttons to show the appropriate icon.
Whether the video is playing or paused can be checked via the video.paused property. You can check this boolean to determine the status.
Handling your volume control should be pretty easy if you just wanted to use a slider. The value of the slider could effect the video.volume property. The volume could be anything between 0.0 and 1.0.
Next up is the current time of the video and the ability to seek/scrub anywhere in the video. Again, you could start with a simple slider. You can get the duration by asking for the video.duration property, and the current playback time of the video by asking for the video.currentTime.
The video.currentTime is also a settable property. Setting this to a specific number (in seconds) will cause the video to seek to that time.
Be careful though! If your video is just beginning to load, it may not be seekable. You can find out what parts of your video are seekable by using the video.seekable property. You can test this by using the “TimeRange” object that the seekable property gives you back when you ask for it. Testing if your desired seek time falls before video.seekable.end is a good indicator that your seek will work as advertised. I actually like to test if the seekable object returns an object with a length over zero just to make sure it’s not empty and not even initialized enough to tell me if it’s seekable.
The video.buffered property will also return a “TimeRange” object and if you’re doing anything advanced, knowing what video is buffered could be very useful info!
Next up we have events! You may have thought that you can get the video.currentTime to find the time of the video and update the playback slider to the correct position. But should you include a Javascript timer to poll the current time to see if it changes? That’s not necessary because you can add an event listener on the video object to listen for “ontimeupdate”.
There are several other events you can listen for that will help you out…but first, I’d like to save you an hour of banging your head on the desk!
When placing the event inside the tag itself, you use “ontimeupdate”, like so:
<video width="640" height="360" controls src="myvideo.mp4" ontimeupdate="myFunction()"></video>
However, when adding an event listener, the event type doesn’t contain the “on”, like so:
video.addEventListener("timeupdate", funtion() { my script } };
Like I said, there are a few other events you can listen for. The event type of “onplaying” can alert other parts of your application when the video starts to play. The event type of “oncanplay” will tell you when the video is ready to start playback. The event type of “onloadeddata” is another good one – it indicates that the data for the current frame is loaded, just not necessarily that we can continue playback. Another good event type is “onerror”. You can listen to this error when the video can’t be played, and show something nice to the user to redirect them to something else.
Some shortcomings
As far as simple playback goes, the video tag is simple…and it works. It’s actually pretty decent and comprehensive for many situations.
Are there any problems? Well, yes.
Using the tag as defined by the W3C is easy, but it’s not reliable! The W3C spec defines using a video file for playback – it talks about how you can interact with the video and what events you can listen to from the video.
Problem is, the spec doesn’t actually indicate what TYPE of video the tag can play. Browser makers are left to fend for themselves when it comes to implementing video playback for any given video format.
Flash popularized the h264 specification. Many argue its the most compact and efficient. Problem is that it’s patented by MPEG-LA, a group of companies who all hold various patents on the standard. The group is comprised of Apple, Microsoft, Panasonic, Sony, and 22 other patent holders.
To use h264 encoding or decoding, users must pay a license fee to the MPEG-LA group. Since the Flash plugin has h264 decoding (and now encoding) built in, it’s Adobe’s responsibility to pay royalties on the specification. Many speculate that the code to implement h264 encoding is the reason why Adobe can’t release the whole flash player source code publicly.
Anyway, the point is, that each browser must pay up if they want to use h264. Internet Explorer, Chrome, and Safari do. Chrome was threatening to pull the plug on it any day now in favor of their VP8 codec that they open sourced such that anyone can use it. Ogg is ALSO free and open source, which is why it’s the only format that Firefox supports.
With Google backing VP8, and Adobe implementing it in Flash, it seems the most promising unless everyone just decides to continue paying MPEG-LA.
So now we have a problem – how do we tell our video tag to play multiple formats based on the browser/device? Luckily, the video tag supports multiple source tags:
<video width="640" height="360" controls > <source src='video.mp4' type='video/mp4'> <source src='video.ogv' type='video/ogg'> </video>
This solves the playback problem, but we still have to encode our videos twice over! Or 3 times over if Google ever decides to drop h264 and go with VP8…then we’re encoding h264, VP8, and ogg.
Additionally, we’re stuck using only those browsers that support the video tag in the first place. This issue is becoming less of a problem with IE being the real drag since only IE9 supports it.
Let’s talk about the reality of this sticky situation in the next post!
Filed in development | flash | flash/flex | html5 | video | web Leave a comment
A Little History of Web Video
Let’s go down memory lane a little bit. RealPlayer, Quicktime, and Windows Media Player were the big web video players. The problem with these options, though, was that you didn’t really own the video as a site creator. All of them seemed to impose their own UI on people, and video was in a box that you couldn’t do well to brand or easily bring to the web.
Each technology didn’t dominate the marketplace, so it was hard for someone that wanted to create video to know whether to create their content in wmv, mov, or….whatever realplayer was.
Back around 2000 or so, I personally saw RealPlayer as a trainwreck…always crashing, bad at buffering, installing extra spyware, etc. Windows Media was decent, but since I was a cross platform CD-ROM developer at the time, Quicktime was the best to author in since there were players on Windows and Mac.
In March 2002, Macromedia’s Flash Player 6 came out. Suddenly web video was a reality in a big way – and not only that, but it didn’t require any plugins beyond Flash itself. Folks could even put video in a project and do whatever they wanted with it. They could make their own controls, and use video itself in an interactive way. We weren’t limited to playing our video through someone else’s player.
Flash Player version 5 at the time had 98% penetration numbers, so Macromedia was bringing video to a plugin that virtually everyone already had (they just needed to upgrade). So, virtually overnight, us video creators had a ubiquitous platform that anyone could use.
Director had given us something similar earlier in the form of the Shockwave plugin, however that plugin never really had the install base of Flash, especially given that it was widely used for CD-ROM development and wasn’t really able to shake it’s place in life and get traction on the web. The other problem with Shockwave was that it still required a plugin (plugin to the plugin) to play video. We had options to play video in whatever format suited us, and in my experience, Quicktime was the most popular. Video wasn’t as moldable as Flash though. If I remember correctly, it was still standard to see the controls on the player, and we weren’t as free to do what we wanted. Additionally, the video plugin didn’t layer the video like Flash did. It really just created a graphical hole in your browser, and the video would play in this rectangular hole, and things could not be overlaid on top of it.
Yay Flash Video!
In just 3 short years after Flash Player 6 was launched, a little company called YouTube was formed. YouTube, though, is just a good example of what Flash 6 did to pave the way for a revolution of online video. It enabled technology to get out of the way, and get brand owners to do what they wanted with their own video!
Macromedia rode the popularity surge and created more products around the Flash platform including media encoders and media servers. Folks could now do actual streaming video with Flash Media Server released shortly after Flash Player 6.
An ability to stream on demand and live video led to an even bigger explosion of live events and long-form video content. With several DRM offerings on top of this, folks could start to see popular movies and tv shows streamed on the web.
Despite any objections to Flash recently, I do think that it’s hard to argue that Flash accelerated public consumption of online video in a big way.
Enter the Video Tag
You may have heard of several “Flash Killers” come along since 2002. In this, I mean the ability to deliver rich media on the web (including video). Microsoft’s Silverlight released in 2007 was probably the most formidable competitor. It’s “Smooth Streaming” server side component was most likely the reason why the 2008 NBC coverage of the Olympic games used Silverlight, and why Netflix uses Silverlight today.
The reason Smooth Streaming was so awesome was for a few reasons. First, streams would upgrade and downgrade depending on the user’s bandwidth all on the server side, and was a completely smooth experience (not requiring client side logic to handle this). Secondly (and this is big), streaming was done over HTTP, something that large organizations are better equipped to deal with over Flash Media Server’s RTMP protocol.
Despite the fact that Netflix still uses Silverlight, the buzz has significantly died down – not least of which due to Microsoft’s handling of it!
The buzz picked right back up in April 2010 with Steve Jobs’ infamous “Thoughts about Flash” memo. It launched a sort of web “arms race” gearing up for the still unfinished specification that was HTML5.
In the unfinished specification, was the notion of the video tag. On the surface, a video tag sounds simple – just like putting an “img” tag in the browser to display an image. Underneath though, the video tag is more complicated as folks fight out the underlying video codecs.
In 2010, we weren’t NEARLY ready for the video tag. A year later, we still have the same problems, but given recent browser support and all the hype, we’ve been rocketed into a position where the video tag is a viable solution in many ways – but still overhyped enough that people think it’s as robust as the Flash ecosystem and ends up failing when people try to use it in these advanced ways.
Filed in development | flash | flash/flex | javascript | music | web Leave a comment
At the heart of all our audio generation lies one simple Flash feature – the sample data event.
Can we find things outside of Flash that will let us do similar things?
The answer is….of course! People have been writing desktop audio and music synthesizer software for years. Flash and AIR offers some decent functionality on the desktop, but writing something in C++ would blow Flash away of course.
The reason is that Flash has only been in the generative audio game for a few years, while people writing C++ have been at this for decades. As such, they have access to ready made filters, libraries, etc.
Take, for example, Node Beat – written with OpenFrameworks
http://forum.openframeworks.cc/index.php?topic=6070.0
Objective-C for doing iPhone development has the nice benefit of access to core libraries that Apple OSX Cocoa developers have had access to for years. The basic AudioUnit in Cocoa or Objective-C gives you the low level access you need to make things like Mobile Synth:
http://code.google.com/p/mobilesynth/
Or even a simple tone generator:
http://cocoawithlove.com/2010/10/ios-tone-generator-introduction-to.html
Basically though, you’ll find that anything that gives you low-level audio access will give you what you need. Speed is the key here, number crunching needs to be done in an instant. Flash can keep up OK, and gives you the bare minimum of what you’d need to generate sound.
What about Javascript? Well, sort of! The Web Audio API has been defined and implemented on the developer version of Chrome and there’s also a Audio Data API draft in Firefox. The basics are the same as Flash, but many more goodies are offered to help you along.
So, in the end we need speed and some basic API hooks. On the web, Flash seems the most reliable, but it sounds like Chrome and Firefox are nipping at Flash’s heels with some very cool stuff coming up!
And in the mobile world, just like the desktop world, it seems this sort of base level audio access is standard as well.
Filed in development | flash/flex | flex | music | ui Leave a comment
So far, we’ve discussed how to create tones, notes, and chords. We’ve also gone into several different algorithms to change how a digital instrument sounds. Changing how our digital instrument sounds is a lot more than simply changing the algorithm that defines your sound wave! You may have noticed that given the several algorithms we covered in part 2 of this series, the sounds didn’t change all that much.
What can we do to create some more variety?
Attack, Decay, Sustain, Release
In electronic synthesizers, there are the concepts of “attack”, “decay”, “sustain”, and “release” (commonly abbreviated ADSR). The easiest way to explain this is to imagine yourself hitting a key on a piano.
The moment you hit the key, the string is hit by the hammer by the piano. This initially creates a loud tone. The initial tone is much louder than anything that happens moments after. This initial loudness is called the “attack”. As the initial loudness wears off, the sound draws down to the normal volume as you hold the piano key. This drawdown is known as the “decay”, and for the rest of the duration that you’re holding the key is known as the sustain.
Once you release that piano key (on a real piano), there would be a small amount of sound coming out as the string is still vibrating. This will eventually fade away – but this period is known as the “release” period.
Envelopes
Attack, Decay, Sustain, Release is a type of envelope. At a basic level, an envelope is controls volume on a waveform as the cycles continue. There are more types of envelopes, but the ADSR envelope is the most commonly known.
Some synthesizers break up the phases even more. Consider the DAHDSR envelope. This starts with a delay phase. This is the phase before the attack – a phase where you don’t hear any audio, or much at all, in the initial lead up to the loudness that is the attack phase.
Then comes the “hold” phase. This is meant to prolong the time between the attack and release. It keeps the volume high!
And then the rest continues with the decay, sustain, and release.
Different types of synthesizers take different envelope approaches. Some even let you create your own – however it seems that the simple ADSR is the most common.
Shortening the Sustain
One thing I’ve found is that a sustain that keeps going and going and going while you press a key, sounds kind of unnatural. It might be appropriate for something like a pipe organ, but if you’re trying to replicate the percussiveness of a piano or a bass guitar pluck, you don’t want something that goes on forever.
Keeping it short and sweet is the perfect key to making something sound natural! I’m still experimenting with envelopes to try to accomplish this effect without just cutting off the waveform. Overall though, I’ve found that limiting a sustain to a few hundred milliseconds is the perfect solution to making a more natural sounding instrument – especially if you want something percussive like a bass pluck or piano key.
Harmonic Overtones and other Imperfections
Imperfections in the note quality are a good way to make a computer generated note sound more natural. Perhaps the tone could be off a couple steps in the frequency, however there are other ways!
One such way is to give a note a harmonic overtone. Remember back in part 4 when we went into note relations? We talked about octaves, where an octave higher will produce the same key/tone, but is at a higher pitch. An octave higher or lower is in perfect harmony with the root note.
With harmonic overtones, we layer several octaves on top of the note. This gives a more natural sound. Many instruments in the real world will have the first 2 overtones be in perfect harmony. In this regard, starting at middle A of 440hz, we’d have overtones of 880hz, 1320hz, and 1760hz. All these notes playing at the same time to produce something more natural!
Another factor in real world instruments is that these overtones (especially the third and fourth) may not be exactly the same key in an octave, not in absolute harmony. These higher overtones might be a little sharp or a little flat. These nuances contribute to the instruments unique sound. In fact, if you’ve ever seen the flare on the end of the trumpet, it’s not to get more volume, but to correct the harmonic overtones to be closer to absolute harmony.
We can absolutely replicate this in our digital instruments! We can mix harmonic overtones together when playing a single note, and even make variations to avoid absolute harmony and give our instruments some character.
Filters, Modulations, and more
We’ve only scratched the surface of creating new and exciting voices for our instruments. We can pass our tone through a filter, do frequency modulation, and more. I’m still exploring, so this is best left for another time!