Archive

Posts Tagged ‘simplecdn’

Use SimpleCDN for Silverlight streaming

October 2nd, 2009

Microsoft’s Smooth Streaming use standard http protocol, so it is possible to use simplecdn mirror bucket for delivering.

Here is my step by step to use open source software and simplecdn for HD video delivering.

Step 1: Server
Even though the Microsoft has opened spec for a while, there is current only 1 open source smooth streaming server code-shop.com.

It has a few server plugins including apache and nginx. I choose nginx as my backend server. You can download the nginx plugin from code-shop.com. It has two parts, a nginx module and a small utiility mp4split which converts mp4 files to fragmented format.

Nginx doesn’t use dynamic linked library, so you have to recompile the entire binary. I compiled the smooth streaming module on nginx-0.7.62 without any problem.

Step 2: Encoding
The entire process is documented on here. It require avisynth and a few other windows utilites.

If you need to do it on linux, here is how:
You will need both ffmpeg and x264. I have tried use ffmpeg alone, but it can not accept stats file from a different bit rate setting which is required step.

Direct pipe through ffmpeg and x264 also doesn’t work, because x264 can’t recognize file type, so you need a named pipe.

mkfifo video.y4m

This file can be reused many times.

Pass 1:

ffmpeg -i big_buck_bunny_720p_h264.mov -an -f yuv4mpegpipe - > video.y4m & \
x264 --threads auto --profile high --level 3.2 --preset slow --no-mbtree --b-pyramid  --min-keyint 24 --keyint 96 --pass 1 --bitrate 2524 -o /tmp/bbb_2524.mp4 video.y4m

You can also run these two commands under 2 different console windows. Setting –no-mbtree is important.

Pass 2:
If everything go ok in pass 1, you can now run pass 2 for multiple bitrate

ffmpeg -i big_buck_bunny_720p_h264.mov -an -s 256x144 -f yuv4mpegpipe - > video.y4m & \
x264 --threads auto --profile high --level 3.2 --preset slow --no-mbtree --b-pyramid  --min-keyint 24 --keyint 96 --pass 2 --bitrate 260 -o /tmp/bbb_260.mp4 video.y4m

Repeat this step with your desired resolution, bitrate and filenames.

The output mp4 file from x264 cannot be streamed, you will need a small utility qt-faststart to fix them.

Problem: I can’t encode playable audio file. If I include audio, the player simply stop.

Now following the rest step described here to split your mp4 files.

Step 3: Player
Unfortunately there’s no working open source player can do smooth stream. Code-shop’s website mentioned openvideoplayer can be updated by replaced with smoothstreaming dll, but I can not find where to put the file.

So I duplicated code-shop’s demo page.

Step 4: SimpleCDN
The simplest step, make a mirror bucket and point it to your webserver.

Result:

Here is my 720p video streaming through simplecdn.
sstreaming

No audio yet. It looks exactly like every other demo page, but it stream through my nginx server and simplecdn. Microsoft’s player use additional query parameters to speedup playback, but simplecdn will strip them away.

Other thought:
I think it is possible to split fragmented mp4 files to real files, so you probably need not a special server module.

Bookmark and Share  
 

Yejun Web , , ,

How to use SimpleCDN with WordPress

February 15th, 2009

Update 2/24/2009: This method is deprecated. I wrote a plugin to rewite urls.
Update again: SimpleCDN is slower comparing to CloudFront, I moved all my link to CF. If you have problem copying files to S3, you can read this post.

WordPress is my favorite bloging software, with many builtin features and powerful plugins. WordPress.com, the blogging platform by automattic, has been using CDN for a long time. However there is no public available solution to make self hosted WordPress to use a CDN as well. Fortunately the php code itself is very clean to read, so it took me about 5 minutes to find where I should modify to fully integrate my new CDN address.

Before you proceed, please read my previous posts on how to use CNAME with SimpleCDN and how to process javascript and css files for WordPress. Make sure your SimpleCDN’s CNAME and bucket working properly. I used a mirror bucket which points to my blog address, that is probably the simplest way to mirror your static assets. And use ‘-s1′ pre-url to insure client side cache working, because SimpleCDN does not use 304 not modified http header at all. I used bucket name ’s.mudy.info’ for my own blog.

Once your DNS full propagated, open your favorite text editor open following 3 files.

wp-includes/class.wp-scripts.php‘: near line 75, change

$src = $this->base_url . $src;

to

$src = 'http://yourcdnbucketname' . $src;

There is no trailing slash after your bucketname. If you want to make sure client browser always use cached version, you can also comments out the following line.

// $src = add_query_arg('ver', $ver, $src);

But this change may break WordPress upgrade.

wp-include/class.wp-styles.php‘: near line 79, do the same change as above.

wp-include/theme.php‘: near line 504, change

return apply_filters('theme_root_uri', content_url('themes'), get_option('siteurl'));

to

return 'http://yourcdnbucketname/wp-content/themes';

That’s it. Now clean your cache and test your blog.

Bookmark and Share  
 

Yejun Web , , ,

SimpleCDN CNAME Confusion

February 9th, 2009

I am using SimpleCDN to serve some static scripts and images of WordPress on my website.

Not like AWS CloudFront, Amazon’s CDN service, which only allows expiration date carried from S3 file meta. SimpleCDN supports fine tuning Expiration, P3P and gzip encoding through something called Pre-URL. Which look like these

http://s.mudy.info.simplecdn.net/
http://s.mudy.info-s1.simplecdn.net/
http://s.mudy.info-e7.simplecdn.net/

Here ‘-s1′ means special 1 with expire and gzip; ‘-e7′ means 10 years expire without gzip. And a lot more with different combo effects.

SimpleCDN also supports CNAME to any of these urls. Because there is not a lot document on how to use simplecdn. I mistakenly CNAMEed ’s.mudy.info’ to the first URL

s.mudy.info.simplecdn.net

Run my website through Yslow, I got a lot F score due to lack of expire headers and non-gzip on static files. I realize I have to use these different Pre-URLs in order to get http headers, so I substitute ’s.mudy.info’ in WordPress with ’s.mudy.info-s1.simplecdn.net’ or ’s.mudy.info-e7.simplecdn.net’. Originally very simple urls’ become long and urgly.

Due to some DNS setting error, I accidentally pinged 2 different SimpleCDN pre-urls. The results are 2 different IPs. I reallized I made another mistake today, these pre-urls are supposed to be used as CNAME to get different http headers and gzip encoding, because these hostname all has their own IPs. A quick testing I CNAME ’s.mudy.info’ to

s.mudy.info-s1.simplecdn.net

which gives nicely gzipped files with correct expiration settings.

This design is what I initially did not expect. Because traditional CDN usually use HTTP hostname to distinguish objects, so I normally would think I have to use different hostnames. However SimpleCDN use anycast , so they use same IP block on on all edge servers, which make it possible to use different IP addresses to distinguish requests.

Bookmark and Share  
 

Yejun Web , ,