How to http stream to iphone/ipad with dynamic bitrate

I’ve been working on setting up dynamic streaming for the iphone. Since the iphone not only support normal h.264 encoded video streaming but also dynamic streaming based on available bandwidth I thought I set it up in four profiles.

I started with a very low profile (It’s a requirement if you want to submit a streaming app for the App Store), this profile is audio only but you can add a image that’s showing when you play. My low profile is set at 32kbit/s audio, I used the Advanced Audio Codec (AAC).

My other three profiles are 192kbit/s, 600kbit/s and 1500kbit/s. The 1500kbit version will probably come handy if you have Wifi or really good 3G connections. And the video looks really good on the Ipad. These profiles are all coded with Advanced Video Codec (AVC). I use 480×272 in resolutions on the two lower versions and 720×400 in the high one.

When you choose resolution for encoding you want the resolution should be possible to devide with 4, 8 or 16. The higher the better the video will look. I would have choosen 408 intead of 400 (on the higher bitrate version) but I followed a specification from a another person so I had to adapt. Adobe have given out a great tool for this called the bitrate calculator. Their calculator is for flash video (FLV/F4V) but works the same on other formats. If you follow that your web video will look even better.

To stream material to mobile phones you should wrap your video in the 3GP container. This container works on almost all phones. Newer phones like the iphone or android phones can also play mp4 files (h.264). But I prefere to encode all mobile material in H.264 and wrap it in the 3GP container.

We then need to use a couple of tools that Apple have created. Media Stream Segmenter (This is used if you stream live content and not VOD content), File Stream Segmenter, Media Stream Validator and Varient Playlist Creator. All these tools are included with Mac OS X, version 10.6 (Snow Leopard) and later. They can be found in the /usr/bin/ directory. This directory is hidden from the finder, but is accessible from the Terminal application. You can also download them if you are a member of either the iPhone or Mac Developer Program. One way to navigate to the tools is to log onto connect.apple.com, then click either iPhone or QuickTime under the Downloads heading.

Media Stream Segmenter
The mediastreamsegmenter command-line tool takes an MPEG-2 transport stream as an input and produces a series of equal-length files from it, suitable for use in HTTP Live Streaming. It can also generate index files, encrypt the media, produce encryption keys, optimize the files by reducing overhead, and create the necessary files for automatically generating multiple stream alternates. For details, type man mediastreamsegmenter from the terminal window.

File Stream Segmenter
The filestreamsegmenter command-line tool takes an encoded media file as an input, wraps it in an MPEF-2 transport stream (unless it is already encapsulated in one), and produces a series of equal-length files from it, suitable for use in HTTP Live Streaming. The file stream segmenter behaves very much like the media stream segmenter, but it works on existing files instead of streams coming from an encoder. For details, type man filetreamsegmenter from the terminal window.

Media Stream Validator
The mediastreamvalidator command-line tool examines the index files, stream alternates, and media segment files on a server and tests to determine whether they will work with HTTP Live Streaming clients. For details, type man mediastreamvalidator from the terminal window.

Varient Playlist Creator
The variantplaylistcreator command-line tool creates index files, or playlists, for alternate streams from the output of the media stream segmenter (the media stream segmenter must be invoked with the -generate-variant-info argument to produce the required output for the playlist creator). For details, type man varientplaylistcreator from the terminal window.

I will not go in any further on these programs other then I will show you how to use them. But if you want to read more about the protocols and so on you can find the information here at Apple Developer.

To get started:
Choose your videofiles, in this example I will use three files low-chi-phi.3gp/mid-chi-phi.3gp/high-chi-phi.3gp these files have been created in advanced and will not be further explained in this post. Also choose one image that will be used for the stream with only audio.

Open the terminal window on your Mac (write “terminal” in finder if you don’t know how to start it).
Go to the folder where you will put your files, I’ve choosen to save them in /Users/niklashammarstrom/Sites/testfiler

Create four different folders to save the mediafiles in, this will make it easier to keep track of your material. (I’ve created low/mid/high/audio)
mkdir low
mkdir mid
mkdir high
mkdir audio

After that you need to decide where you going to put these files on the web, since the playlist we’re going to create have hardcoded web url’s. I’ve choosen to put my testfiles at http://www.niklashammarstrom.com/iphone/ (You can change this url to fit your server url in the example below.

We start by creating the audio only stream.
/usr/bin/mediafilesegmenter –audio-only –meta-file /Users/niklashammarstrom/Desktop/bild.PNG –meta-type picture -f audio/ low-chi-phi.3gp -b http://www.niklashammarstrom.com/iphone/testfiler/audio -I -i audio-sport.m3u8 -l iphone.log

Some explanations to the above
-I in tells the system that you which to create a dynamic bitrate file that you will use with variantplaylistcreator later.
-i gives you the possibility to set your own name on the index file. Default is prog_index.m3u8
-l tells the system to log everything in a file called iphone.log
-f is just to indicate the path to where you want to store your media files.

Next we create the low version
/usr/bin/mediafilesegmenter -f low/ low-chi-phi.3gp -b ttp://www.niklashammarstrom.com/iphone/testfiler/low -I -i sport.m3u8 -l iphone.log

And then the mid and high version
/usr/bin/mediafilesegmenter -f mid/ mid-chi-phi.3gp -b http://www.niklashammarstrom.com/iphone/testfiler/low -I -i sport.m3u8 -l iphone.log
/usr/bin/mediafilesegmenter -f high/ high-chi-phi.3gp -b http://www.niklashammarstrom.com/iphone/testfiler/low -I -i sport.m3u8 -l iphone.log

Once this is done you should be able to a lot of small files in the folders named low/mid/high. You will also see files called *.plist in the same folders as original 3gp files are stored.

The next thing we need to do is to created the dynamic playlist so the iphone will know what file to choose. This is done by the variantplaylistcreator.

/usr/bin/variantplaylistcreator -o iphone-sport.m3u8 http://www.niklashammarstrom.com/iphone/testfiler/low/sport.m3u8 testfiler/low-chi-phi.plist http://www.niklashammarstrom.com/iphone/testfiler/mid/sport.m3u8 testfiler/mid-chi-phi.plist http://www.niklashammarstrom.com/iphone/testfiler/high/sport.m3u8 testfiler/high-chi-phi.plist

This will create a playlist called iphone-sport.m3u8 that knows of all the other video bitrates.

If you have done this right your iphone-sport.m3u8 should look something similiar to this when you open it up in a text editor.

#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=79358

http://www.niklashammarstrom.com/iphone/testfiler/audio/audio-sport.m3u8

#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=79358

http://www.niklashammarstrom.com/iphone/testfiler/low/sport.m3u8

#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=621958

http://www.niklashammarstrom.com/iphone/testfiler/mid/sport.m3u8

#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1533985

http://www.niklashammarstrom.com/iphone/testfiler/high/sport.m3u8

You can now try to open the url in your browser on your iphone and test it.

Good luck.

If you have any questions please leave your name on blog and I will get back to you.

A new start

I been thinking on what to do with this blog. I haven’t written anything at all since I started working on Viasat. My main issue have been time, I haven’t had that much free time. I’ve been working a lot with the projects here and therefor haven’t had time for anything else.

I will try to write more on this blog. Unfortantly I lost my domain name nickeluli.com due to a mailing problem. I had registered an old email at my domain provider and they sent the invoice to that old mail so I didn’t pay in time so some crashy domain spammer stole it.

I will focus on this domain now, so please update your old links if you had any to the old the site.

Thanks

My new challenge online

As of today I’m working as project manager for Viasat on demand. It’s a VOD service initially focused in the countries where Viasat broadcast TV. We will aggregate free-tv content from all the Viasat channels, inkl TV3, TV6, TV1000 and Viasat Sport. Each month we stream several hundred live sports event on the web, we also have catch-ups from our free-tv platforms.

Trying to make a custom Magento theme

This must be one of the hardest tasks I’ve tried so far. With my small e-commerce project I needed a CMS in the background and wanted to continue my testings of the Magento eCommerce platform.

Before I started the new project I had the design for the entire site coded in perfect CSS/xHTML and thought it would be easy to just hock it up to Magento. But boy was this a misstake, I have now read several hundred pages of the online documentation for Magento and so far I haven’t managed to get my new design working ontop of the CMS.

The biggest problem so far is the way the entire design is structured with XML and small snippets of HTML. Basically you store your HTML skeleton in the app/design/frontend/theme/default/template under different sub-categories. And then you have the rest of the structured in the app/design/template/frontend/theme/default/layout as blocks of XML that are calling for the html files.

It looks like this,
<block type=”page/html_notices” name=”global_notices” as=”global_notices” template=”page/html/notices.phtml” />

<block type=”page/html_header” name=”header” as=”header” template=”page/bimp/header.phtml”>
</block>

Okey it gets even weird’er when it comes to css and images, since they are stored in a different part of the three structured and called through a lot of different sets of rules.

I’m not a coder, I haven’t written a single line of code for more then three years. I should probably leave this to the professionals. So I will probably post this a new project on GAF if I don’t solve these issues before the weekend.

Internet dating humor

Found a really funny video about online dating.

Project progress

Things are finally progressing. It took a while to get the designer to make a design for my new project but now it’s finally in the hands of the CSS/xhtml coder and I will get all the pages back on monday. I’ve been thinking about making this a affiliate project, but now I can tell you it will be a 100% e-commerce project.  I’ve established contact with a good supplier within the EU, that will drop ship to my customers.

I feel that I can’t give you the entire business yet, but since it will be online before the end of June I promise I will write more about it during next week. Last year I made some tests on the Magento platform and until last week I had plan to use that for this project. But a friend of mine introduced me to Shopify that already have a great working platform with everything you need to a good price. And the best thing is that you can style it any way you want.

Drop shipment or Lead marketing?

So, I’ve started working on one of my new projects this week. I will be a mix between a regular e-commerce site and a lead generating site. Today I’ve been sitting at the office with the designer and made a really good looking layout for the webpage.

Next thing is to get the page coded in perfect CSS/XHTML and thanks to previous work I have good connections for that in South America. Hopefully it will be finished by the time I wake up tomorrow. After that I will start doing the back-end coding in PHP.

I’ve also contacted some potential partners for this project. The project will be two sites, one English for UK and one Swedish. The will have different content but almost the same design.

Since I’m going to sell things on the site but don’t want to handle a large stock of products, I think I will solve this with Drop shipments. That means you don’t have to keep all the products in stock, you have someone else keeping the goods for you. And they ship the products to your customers. One other way that I’ve been talking to friends about would be to link to other e-commerce sites that have affiliate programs. I haven’t decided what way to go yet, but I will before the end of the week.

I will have these two projects up before the end of June.

New challenges ahead

The summer is on it’s way and with that comes all these questions on what fun things to do during the summer. I was thinking on going on a road trip with some of my friends, we haven’t managed to decied where we’re going. But I was thinking of driving down through Denmark, Germany and try to reach the eastern part of Europe. I’ll write more about this later…

The biggest news at the moment is that I’ve left Testfreaks. The economic recession and the fact that people don’t buy as much consumer electronic products as before have gotten our trafic and conversion to go down. The company therefor decieded to let 5 people go inkl yours truly to cut some of it’s costs.
My task when I got to Testfreaks was to found a operations team outside of Sweden that  could provide high quality work at a resonable price per month. And this I have been doing with a fantastic achievement. We started working with a Ukrainian company that have evolved into a very good relation. We do also work with Chinese, Philippines, Russians, Brasilians and Indians to mention some of the other people working with Testfreaks.
When I left Testfreaks my operationsteam was a well oiled team with 25 people working close together with Skype, msn, gtalk, YahooIM and other communication plattforms, to make Testfreaks the largest and best review site in the world. .I will still keep my stocks in the company and I’m still convinced that the company will do great online.

Due to the recenssion and the fact that the company needed to save money I figure they will cut the spending on some of these workers and therefor they also thought it would be best if I left as well. I’ve done a great work and have the best recommendations from our CEO but now it’s time for me to do something else. The big question is what?

Currently I’m working together with an old friend of mine with his new mobile application that will be release on the techcrunch meet up in Stockholm in the end of may. I promise you it’s a great product. Available on almost all platforms except Windows mobile. (The iPhone app is really great).

I’m also evaluating the possibility to either take a new job or create my own company. I’ve also had a thing for e-commerce. I think there’s still big potential for e-commerce in Europe and especially in Sweden. I haven’t found any e-commerce site that have done what I want to do regarding design and functions. This is also why I’ve started experimenting with a Magento which I think is a great back-end system for e-commerce.

When I was working with Testfreaks I couldn’t find the time for all my small projects that I been wanting to tryout for several years. What I have done during these 2.5 years I’ve worked with Testfreaks is to write these idéas down and bought some domains for it. Now is the time to start working on these idéas.

I’ve gotten an office space in central Stockholm (Kungsholmen) thanks to my friend Per at Grandriver. So I will use that space three days a week and the other two days I will work with the mobile application company that I wrote about above. But you don’t become a great entreprenuer by just working 5 days a week. So you will probably see me with my laptop on coffee house during the weekends as well.
If someone with a great idéa or company are reading this and would like to hire me either for work or for something else don’t hesitate to contact me. I’m available on this blog name @ gmail.com. You can also take a look at my Linkedin profile or follow me on Twitter.

Cut my Amex gold in pieces

Just cut my American Express in pieces. I’ve been using it on and off for the last year. I mainly use it to pay for transactions online. They wanted me to pay an anual fee of 1250SEK (150$) to continue using the card. Why would I pay to be a customer, when there are a million other companies offer the same product for free. And I don’t even need a credit card, I have money in the bank. I think it’s greedy of them to both charge the customer and the merchant that accept AMEX in his/her store.

No more American Express for me!

Where are we going?

Where are we going? I got a link over Twitter today from a guy that I’ve been following for a while. I don’t know him, but still I like to follow certain people on Twitter. Some twitter about work, other about their live and some about something else. But thanks to him I saw this great video on Youtube. Check it out it’s about the technical evolution.