<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Unreal Expectations &#187; nginx</title>
	<atom:link href="http://unrealexpectations.com/blog/category/nginx/feed/" rel="self" type="application/rss+xml" />
	<link>http://unrealexpectations.com/blog</link>
	<description>That actually worked??!??</description>
	<lastBuildDate>Wed, 23 Jun 2010 04:32:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Video, from Camcorder to Nginx Flash Streaming</title>
		<link>http://unrealexpectations.com/blog/2010/01/video-from-camcorder-to-nginx-flash-streaming/</link>
		<comments>http://unrealexpectations.com/blog/2010/01/video-from-camcorder-to-nginx-flash-streaming/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 06:44:28 +0000</pubDate>
		<dc:creator>mleo</dc:creator>
				<category><![CDATA[mac wizardry]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://unrealexpectations.com/blog/?p=36</guid>
		<description><![CDATA[<p>About two years ago before my daughter was born I talked my wife into the value of having a video camera to record all those wonderful moments that kids are supposed to have.  At the time I was a fan of Sony products and we ended up purchasing the Sony HDR-SR5 High Definition Camcorder. [...]]]></description>
			<content:encoded><![CDATA[<p>About two years ago before my daughter was born I talked my wife into the value of having a video camera to record all those wonderful moments that kids are supposed to have.  At the time I was a fan of Sony products and we ended up purchasing the <a href="http://www.sonystyle.com/webapp/wcs/stores/servlet/ProductDisplay?catalogId=10551&#038;storeId=10151&#038;langId=-1&#038;productId=8198552921665089060">Sony HDR-SR5</a> High Definition Camcorder.  I have actually had no complaints with the operation of the camera itself and didn&#8217;t give much thought to the need to pull video off the camera and what I would do with it once I did pull it off.</p>
<p>My daughter came and we filmed various moments early on and my first attempt to pull the video off the camera did not go so well.  I had a copy of Adobe Premiere Elements 4 or something.  It was purchased along with Adobe Elements that I mainly use for organizing all the digital photos of my daughter.  Much to my dismay, I quickly discovered that Premiere Elements did not support <a href="http://en.wikipedia.org/wiki/AVCHD">AVCHD</a>, Sony&#8217;s format format for encoding video on their camcorders.  While I liked Sony hardware and they offered some software for dealing with AVCHD, I don&#8217;t care for OEM software included with hardware as it is often feature limited with a horrible user experience and included purely to ensure there is some way to access the content the user has created.  I don&#8217;t envy the developers who have to put those applications together as they are probably given next to no time to work on it and lack adequate numbers of competent developers to get it complete.  </p>
<p>So eventually the disk on the camcorder was starting to get full and I needed to pull the video off of the drive.  I had purchased a Mac Mini for use in the kitchen to play DVDs, iTunes Videos, and access <a href="http://www.foodnetwork.com/recipes/paula-deen/crab-cakes-with-lemon-dill-sauce-recipe/index.html">recipes</a> off the web.  I finally discovered that iMovie &#8216;08 has support for AVCHD and could import the videos off the camera.  Initially it was more about getting the videos off the camera and freeing the camera&#8217;s hard disk more than making them available in any sort of way to anyone.</p>
<p>On a recent client engagement for work we are working with a music company that is rebuilding their eCommerce platform from the ground up.  Part of the solution we designed and built incorporated videos that are streamed using Akamai fronted by Flow Player.  We ran into some of the oddest issues with missing files and integrating the Akamai streams.<br />
As I was setting up nginx recently to get this site running, I revisited the details that nginx has built-in support for FLV HTTP Streaming. This doesn&#8217;t provide any real protection of the stream, but does provide an ability for users to quickly start watching the video and forward to any point in the video without needing to download everything up to that point.  In thinking about the possibility of incorporating this, I finally found a reason to do something fun with the videos and make them available to family to view.  The following is a list of the steps I did to get this enabled.</p>
<h2>1. Importing the Video From Camera</h2>
<p>This was a pretty simple process with iMovie.  The only problem I ran into is that it seems iMovie needs to be up and running when the camera is set to computer mode otherwise iMovie doesn&#8217;t seem to recognize it as a camera.  When not running, the camera would connect in MacOS X and appear as a hard drive that could be opened and have images pulled from, but when iMovie started, it does not see it.  What tripped me up most before I realized this is that I tried it on a Mac Book Pro (with iMovie running) and it came right up for importing, but when I tried with my Mini (without iMovie running) it did not appear.</p>
<p>So step one was to connect the camera while iMovie was running and import the appropriate clips into an iMovie event.  </p>
<p><a href="http://unrealexpectations.com/blog/wp-content/uploads/2010/01/imovieimport-1.png" rel="lightbox[36]"><img src="http://unrealexpectations.com/blog/wp-content/uploads/2010/01/imovieimport-1-300x179.png" alt="" title="iMovie &#039;09 Import From Camera" width="300" height="179" class="alignnone size-medium wp-image-39" /></a></p>
<h2>2. Create the Movie</h2>
<p>I won&#8217;t get into the details on how to create the project from the imported movie, but suffice it to say, iMovie makes it easy to select parts or all of the imported video and create titles and transitions and apply effects to the movie.  Once the project is ready, go to Share>Export Movie&#8230; to open a dialog.  I exported the movie as Medium and time yet will tell if that is too large for friends and family to view.  </p>
<p><a href="http://unrealexpectations.com/blog/wp-content/uploads/2010/01/imoveimport-2.png" rel="lightbox[36]"><img src="http://unrealexpectations.com/blog/wp-content/uploads/2010/01/imoveimport-2.png" alt="" title="iMovie &#039;09 Share Menu" width="289" height="300" class="alignnone size-full wp-image-40" /></a></p>
<p><a href="http://unrealexpectations.com/blog/wp-content/uploads/2010/01/imovieimport-3.png" rel="lightbox[36]"><img src="http://unrealexpectations.com/blog/wp-content/uploads/2010/01/imovieimport-3-300x188.png" alt="" title="iMovie &#039;09 Export Movie" width="300" height="188" class="alignnone size-medium wp-image-41" /></a></p>
<p>One additional point before leaving iMovie is the creation of still image to use as title slide before the movie starts.  When the flash video player loads, it doesn&#8217;t start playing the movie unless the user actively clicks the play button.  It can be configured to start automatically, but I personally find sites that do that annoying as I am sure many other people do as well.  Since the player doesn&#8217;t start loading the video automatically, there is no way for the player to present a frame of the video as place holder.  To provide a better experience to users, a still frame should be produced and provided to the flash player to use at startup.  With it specified, the player will present the image with a play button in place.<br />
To generate the a still image from iMovie is not the most obvious thing to do, though once the process is understood, it is not difficult to do.  I eventually found the information on how to do this <a href="http://imovie08.blogspot.com/2007/08/how-to-capture-still-image-from-clip.html">here</a>.  The short information on the process is to create a project with a small clip including the frame you want to capture and then use Share>Export using Quicktime.  </p>
<p><a href="http://unrealexpectations.com/blog/wp-content/uploads/2010/01/imovieimport5.png" rel="lightbox[36]"><img src="http://unrealexpectations.com/blog/wp-content/uploads/2010/01/imovieimport5.png" alt="" title="Export Using Quicktime" width="272" height="286" class="alignnone size-full wp-image-45" /></a></p>
<p>This will bring up the &#8220;Save export file as&#8230;&#8221; dialog box with two drop downs.  In the first, Export, choose &#8220;Movie to Image Sequence&#8221;</p>
<p><a href="http://unrealexpectations.com/blog/wp-content/uploads/2010/01/imovieimport6.png" rel="lightbox[36]"><img src="http://unrealexpectations.com/blog/wp-content/uploads/2010/01/imovieimport6-300x93.png" alt="" title="Export Movie as Image Sequence" width="300" height="93" class="alignnone size-medium wp-image-46" /></a></p>
<p>In the second drop down, make a choice on how the export should occur and image format used with the export.</p>
<p><a href="http://unrealexpectations.com/blog/wp-content/uploads/2010/01/imovieimport7.png" rel="lightbox[36]"><img src="http://unrealexpectations.com/blog/wp-content/uploads/2010/01/imovieimport7-300x180.png" alt="" title="Export Movie as Image Sequence Settings" width="300" height="180" class="alignnone size-medium wp-image-47" /></a></p>
<p>Depending on how long the clip is and how many frames per second are set on export, a few images will be generated that need to be sifted through to find the right one.</p>
<h2>3. Convert to Flash Video</h2>
<p>Once the movie is exported, the next step is to convert it into flash video.  In order to perform this transcoding I used <a href="http://www.ffmpegx.com/">ffmpegx</a> that provides a graphical user interface to several utilities that perform the actual encoding.    The <a href="http://www.ffmpegx.com/download.html">download</a> page has all the details on how to install and initially configure the application.  There are specific notes on the page on how to enable the FLV encoding.</p>
<p>Once it was up and running it was nearly as dragging and dropping the source movie,  choosing the output encoding, and clicking Encode.  The only added effort was making changes to the output size and settings.  Once set, click Encode and wait for the computer to do the dirty work.</p>
<p><a href="http://unrealexpectations.com/blog/wp-content/uploads/2010/01/imovieimport-4.png" rel="lightbox[36]"><img src="http://unrealexpectations.com/blog/wp-content/uploads/2010/01/imovieimport-4-300x250.png" alt="" title="ffmpegX user interface" width="300" height="250" class="alignnone size-medium wp-image-42" /></a></p>
<p>ffmpegX is licensed as shareware.  So far I have only encoded a small number of videos but could easily see doing more and paying the shareware fee.</p>
<h2>4. Enable nginx Flash Streaming</h2>
<p>The video is encoded as flash video and now it is time to ensure nginx is configured to stream the file over HTTP.  In the server block for the given virtual host, just adding an additional location block is all that is needed.</p>
<p><pre><code>
    location ~ \.flv$ {
      root   /home/mleo/www/public/;
      flv;
    }
</code></pre></p>
<p>The <a href="http://wiki.nginx.org/NginxHttpFlvStreamModule">flv</a> directive ensure the necessary meta data is sent with an flv file response and incoming requests with file seek data are handled properly and the data is sent back as requested.</p>
<h2>5. Embed the Flash Video in Page</h2>
<p>I&#8217;ll skip over the step on copying the flv file from local computer to the server and move on to the final step of configuring a flash video player to consume the video, splash image, and stream via http.  In my case I chose to use <a href="http://www.longtailvideo.com/">JW Player</a> which offers a non-commercial license which can be used on sites with no advertising (like this one).   Once the package is downloaded and installed on the server, minimally consisting of the swfobject.js, player.swf and some supporting files, one can use the <a href="http://www.longtailvideo.com/support/jw-player-setup-wizard?example=201">setup wizard</a> to initially configure the settings.  Most of the defaults are fine, but the most immediate settings to change include:</p>
<ul>
<li>height: The video dimension height</li>
<li>width: The video dimension width</li>
<li>file: The path to the flv file</li>
<li>image: The path to the splash image</li>
<li>provider: Set to &#8220;http&#8221; in order to enable http streaming</li>
</ul>
<p>The following is the sample code for the video embedded  below.</p>
<p>These few settings are all that is needed to embed the video player and have it function.  JW Player offers all sorts of additional plugins and skins, but for simple video sharing that isn&#8217;t really needed.</p>
<p><pre><code>
&lt;script type=&#039;text/javascript&#039; src=&#039;/media/swfobject.js&#039;&gt;&lt;/script&gt;

&lt;div id=&#039;mediaspace&#039;&gt;This text will be replaced&lt;/div&gt;
 
&lt;script type=&#039;text/javascript&#039;&gt;
  var so = new SWFObject(&#039;/media/player.swf&#039;,&#039;mpl&#039;,&#039;640&#039;,&#039;360&#039;,&#039;9&#039;);
  so.addParam(&#039;allowfullscreen&#039;,&#039;true&#039;);
  so.addParam(&#039;allowscriptaccess&#039;,&#039;always&#039;);
  so.addParam(&#039;wmode&#039;,&#039;opaque&#039;);
  so.addVariable(&#039;file&#039;,&#039;/media/SampleVideo.flv&#039;);
  so.addVariable(&#039;image&#039;,&#039;/media/SampleVideo.png&#039;);
  so.addVariable(&#039;provider&#039;,&#039;http&#039;);
  so.write(&#039;mediaspace&#039;);
&lt;/script&gt;
</code></pre></p>
<h3> Sit back and enjoy streaming video</h3>
<p>The following video is of my daughter&#8217;s day care holiday show. It is the first of my videos to be imported, encoded, and streamed.</p>
<p><script type='text/javascript' src='/media/swfobject.js'></script></p>
<div id='mediaspace'>This text will be replaced</div>
<p><script type='text/javascript'>
  var so = new SWFObject('/media/player.swf','mpl','640','360','9');
  so.addParam('allowfullscreen','true');
  so.addParam('allowscriptaccess','always');
  so.addParam('wmode','opaque');
  so.addVariable('file','/media/SampleVideo.flv');
  so.addVariable('image','/media/SampleVideo.png');
  so.addVariable('provider','http');
  so.write('mediaspace');
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://unrealexpectations.com/blog/2010/01/video-from-camcorder-to-nginx-flash-streaming/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Nginx, FastCGI, Wordpress Permalink &amp; &#8220;No Input file specified&#8221;</title>
		<link>http://unrealexpectations.com/blog/2010/01/nginx-fastci-wordpress-no-input-file-specified/</link>
		<comments>http://unrealexpectations.com/blog/2010/01/nginx-fastci-wordpress-no-input-file-specified/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 04:25:58 +0000</pubDate>
		<dc:creator>mleo</dc:creator>
				<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[slicehost]]></category>

		<guid isPermaLink="false">http://www.unrealexpectations.com/blog/?p=17</guid>
		<description><![CDATA[<p>If you have spent any time recently look into the state of web servers then you know that nginx is getting recommended as the replacement for apache left, right and center.  Apache has a rich history, platform extensive, and highly extensible, and while these are great traits it&#8217;s 15 years of legacy code hasn&#8217;t seemed [...]]]></description>
			<content:encoded><![CDATA[<p>If you have spent any time recently look into the state of web servers then you know that nginx is getting recommended as the replacement for apache left, right and center.  Apache has a rich history, platform extensive, and highly extensible, and while these are great traits it&#8217;s 15 years of legacy code hasn&#8217;t seemed to keep pace with some of the modern design patterns such non-blocking i/o and simple configuration.  To apache developers&#8217; credit it is built to support a wide array of architectures and operating systems.</p>
<p>There is definitely a fair amount of information out there on how to get nginx running with Wordpress via FastCGI.  Slicehost, my current hosting provider, offers a wealth of <a href="http://articles.slicehost.com/nginx">articles </a>on setting up nginx along with a rails cluster. I followed several other <a href="http://codeintensity.blogspot.com/2008/08/wordpress-nginx-subdirectories-and.html">articles</a> in getting FastCGI working through spawn-fcgi with requisite<a href="http://saturnboy.com/2008/10/nginx-init-script/"> init scripts</a> to ensure everything starts up properly.  Everything was working great until I enabled <a href="http://codex.wordpress.org/Using_Permalinks">pretty permalinks</a> and then got the unfortunate error:</p>
<p><code>No input file specified.</code></p>
<p>I understood this to mean FastCGI could find the script attempting to be called, but couldn&#8217;t immediately see why that was the case.  In the end it was something simple and obvious.</p>
<p>My initial configuration server configuration looked something like:</p>
<p><pre><code>
server {
  listen   80;
...
  location / {
    # this serves static files that exist without running other rewrite tests
    if (-f $request_filename) {
      expires 30d;
      break;
    }

    # this sends all non-existing file or directory requests to index.php
    if (!-e $request_filename) {
      rewrite ^.+?(/.*\.php)$ $1 last;
      rewrite ^ /index.php last;
    }
  }

  location ~ .php$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;

    fastcgi_param SCRIPT_FILENAME /var/www/html/www/public$fastcgi_script_name;

    root /var/www/html/www/public;
  }
}
</code></pre></p>
<p>And searching there were other suggestions for the rewrite as:</p>
<p><pre><code>
    # this sends all non-existing file or directory requests to index.php
    if (!-e $request_filename) {
      rewrite ^(.+)$ /index.php?q=$1 last;
    }
</code></pre></p>
<p>Which made no difference in the error condition.  As I said in the end, the problem was something obvious.  In my configuration, the wordpress installation is not at the root of the web server, rather it is in a subdirectory called <strong>blog</strong>.  Therefore, with the initial configuration when a path could not be found, rather than call the wordpress index.php script located at /blog/index.php, it was calling just /index.php which initially didn&#8217;t exist.  Had it existed, I probably would have quickly see which file was getting called and how to address.  The change was to set up the wordpress rewrite information in the correct location block.  The updated configuration became:</p>
<p><pre><code>
  location /blog {
    # this serves static files that exist without running other rewrite tests
    if (-f $request_filename) {
      expires 30d;
      break;
    }

    # this sends all non-existing file or directory requests to index.php
    if (!-e $request_filename) {
      rewrite ^.+?(/.*\.php)$ $1 last;
      rewrite ^ /blog/index.php last;

    }
  }
</code></pre></p>
<p>I haven&#8217;t yet configured out the &#8220;No Input file specified&#8221; when a bad php url is used, but that will probably be done shortly.</p>
]]></content:encoded>
			<wfw:commentRss>http://unrealexpectations.com/blog/2010/01/nginx-fastci-wordpress-no-input-file-specified/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
