  
<div id="snippet_132" class="snippet">
  <h2><a href="/snippets/132-How-to-install-ffmpeg-mencoder-and-flvtool2-on-Mac-OSX-Leopard-convert-an-AVI-to-FLV-and-view-the-FLV-video-with-FlowPlayer" title="How to install ffmpeg, mencoder and flvtool2 on Mac OSX Leopard, convert an AVI to FLV, and view the FLV video with FlowPlayer - Shell Script (Bash) - ffmpeg, osx, leopard, flvtool2, flv, mencoder, h.264">How to install ffmpeg, mencoder and flvtool2 on Mac OSX Leopard, convert an AVI to FLV, and view the FLV video with FlowPlayer</a></h2>
  <div class="details">
    <a style="background-color: #FFFF94;" href="http://snippets.aktagon.com/languages/131-Shell-Script-Bash-">
      Shell Script (Bash)</a> posted over 2 years ago by christian
          
  </div>

  <div class="body">
    <p>This is a short tutorial on how to quickly get up to speed with  FLV  movie creation (transcoding) and viewing (Flash player).</p>


	<p>I tried to install ffmpeg using ports and fink, but had problems. The instructions I found <a href="http://www.macosxhints.com/article.php?story=20061220082125312">here</a> work though.</p>


	<p>The following is my adaptation of the instruction, where I show you how to install both ffmpeg and flvtool2.</p>


	<p>First, download ffmpegx, which contains ffmpeg from <a href="http://ffmpegx.com/download.html">http://ffmpegx.com/download.html</a></p>


	<p>Then, mount the .dmg file, navigate to the mounted disk, and control-click on the ffmpegX application (ffmpegX.app), choose Show Package Contents from the pop-up menu, and copy the ffmpeg binary to, for example, /tmp.</p>


	<p>Now execute the following commands in a terminal shell:
<pre class="active4d"><span class="line-numbers">   1 </span> <span class="LineComment"><span class="LineComment">#</span> Move ffmpeg to /usr/local/bin:</span>
<span class="line-numbers">   2 </span> sudo mv /tmp/ffmpeg /usr/local/bin/
<span class="line-numbers">   3 </span> 
<span class="line-numbers">   4 </span> <span class="LineComment"><span class="LineComment">#</span> Change owner and make executable</span>
<span class="line-numbers">   5 </span> sudo chown root:wheel /usr/local/bin/ffmpeg
<span class="line-numbers">   6 </span> sudo chmod 755 /usr/local/bin/ffmpeg
</pre></p>


	<p>You&#8217;re now ready to use ffmpeg; the following command lists all the supported input and output formats:</p>


	<p><pre class="active4d"><span class="line-numbers">   1 </span> ffmpeg -formats
</pre></p>


	<p>Use the following command to transcode an  AVI  to  FLV  (Flash video) format:
<pre class="active4d"><span class="line-numbers">   1 </span> fmpeg -i mymovie.avi -s 320x240 -ar 44100 -r 12 mymovie.flv
<span class="line-numbers">   2 </span> cat mymovie.flv <span class="Operator">|</span> flvtool2 -U stdin mymovie.flv
</pre></p>


	<p>To add metadata to the  FLV  file&mdash;such as video length, which is required for the Flash player progress bar&mdash;you need to install <a href="http://rubyforge.org/projects/flvtool2/">flvtool2</a>.</p>


	<p>This is done with the following command (note this requires Ruby and RubyGems, which are not part of all  OSX  Leopard installations):
<pre class="active4d"><span class="line-numbers">   1 </span> sudo gem install flvtool2
</pre></p>


	<p>Now add the metadata to the  FLV  file:
<pre class="active4d"><span class="line-numbers">   1 </span> flvtool2 -UP mymovie.flv
</pre></p>


	<p>To test the  FLV  movie you just created, download and extract <a href="http://flowplayer.org">FlowPlayer</a>  to your folder of choice. Now create a page that loads your  FLV  movie; note that you need to update the paths:
<pre class="active4d"><span class="line-numbers">   1 </span> <span class="Operator">&lt;</span>html<span class="Operator">&gt;</span>
<span class="line-numbers">   2 </span> 	<span class="Operator">&lt;</span>head<span class="Operator">&gt;</span>
<span class="line-numbers">   3 </span> 		<span class="Operator">&lt;</span>script type=<span class="String"><span class="String">&quot;</span>text/javascript<span class="String">&quot;</span></span> src=<span class="String"><span class="String">&quot;</span>../flowplayer/html/swfobject.js<span class="String">&quot;</span></span><span class="Operator">&gt;</span><span class="Operator">&lt;</span>/script<span class="Operator">&gt;</span>
<span class="line-numbers">   4 </span> 	<span class="Operator">&lt;</span>/head<span class="Operator">&gt;</span>
<span class="line-numbers">   5 </span> <span class="Operator">&lt;</span>body<span class="Operator">&gt;</span>
<span class="line-numbers">   6 </span> 	<span class="Operator">&lt;</span>div id=<span class="String"><span class="String">&quot;</span>flowplayerholder<span class="String">&quot;</span></span><span class="Operator">&gt;</span>
<span class="line-numbers">   7 </span> 		This will be replaced by the player. 
<span class="line-numbers">   8 </span> 	<span class="Operator">&lt;</span>/div<span class="Operator">&gt;</span>
<span class="line-numbers">   9 </span> 	
<span class="line-numbers">  10 </span> <span class="Operator">&lt;</span>script type=<span class="String"><span class="String">&quot;</span>text/javascript<span class="String">&quot;</span></span><span class="Operator">&gt;</span>
<span class="line-numbers">  11 </span> // <span class="Operator">&lt;</span><span class="Operator">!</span>[CDATA[
<span class="line-numbers">  12 </span> var fo = new SWFObject(<span class="String"><span class="String">&quot;</span>../flowplayer/FlowPlayerDark.swf<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>FlowPlayer<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>468<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>350<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>7<span class="String">&quot;</span></span>, <span class="String"><span class="String">&quot;</span>#000000<span class="String">&quot;</span></span>, true)<span class="Operator">;</span>
<span class="line-numbers">  13 </span> 	// need this next line <span class="Keyword">for</span> local testing, it<span class="String"><span class="String">'</span>s optional if your swf is on the same domain as your html page</span>
<span class="line-numbers">  14 </span> <span class="String">	fo.addParam(&quot;allowScriptAccess&quot;, &quot;always&quot;);</span>
<span class="line-numbers">  15 </span> <span class="String">	fo.addVariable(&quot;config&quot;, &quot;{ countryCode: <span class="String">'</span></span><span class="Keyword">fi</span><span class="String"><span class="String">'</span>, playList: [ {overlayId: <span class="String">'</span></span>play<span class="String"><span class="String">'</span> }, { url: <span class="String">'</span></span>/mockup/mymovie.flv<span class="String"><span class="String">'</span> } ], initialScale: <span class="String">'</span></span>scale<span class="String"><span class="String">'</span>,  fullScreenScriptURL: <span class="String">'</span></span>fullscreen.js<span class="String"><span class="String">'</span> }&quot;);</span>
<span class="line-numbers">  16 </span> <span class="String">	fo.write(&quot;flowplayerholder&quot;);</span>
<span class="line-numbers">  17 </span> <span class="String">// ]]&gt;</span>
<span class="line-numbers">  18 </span> <span class="String">&lt;/script&gt;</span>
<span class="line-numbers">  19 </span> <span class="String">&lt;/body&gt;</span>
<span class="line-numbers">  20 </span> <span class="String">&lt;/html&gt;</span>
</pre></p>


	<p>I&#8217;ve <a href="http://www.macosxhints.com/article.php?story=20060923203722112&#38;query=dec">been told</a> that <a href="http://www2.mplayerhq.hu/MPlayer/releases/">mencoder</a> produces higher quality  FLV  videos, so lets compare the mencoder output to ffmpeg by first downloading and extracting mencoder to /tmp.</p>


	<p>Now move mencoder to /usr/local/bin:</p>


	<p><pre class="active4d"><span class="line-numbers">   1 </span> sudo mv /tmp/mencoder /usr/local/bin/
<span class="line-numbers">   2 </span> 
<span class="line-numbers">   3 </span> sudo chown root:wheel /usr/local/bin/mencoder
<span class="line-numbers">   4 </span> sudo chmod 755 /usr/local/bin/mencoder
</pre></p>


	<p>Next transcode the video to  FLV  format using mencoder:
<pre class="active4d"><span class="line-numbers">   1 </span> mencoder mymovie.avi -ofps 12 -o mymovie.flv -of lavf -lavfopts \
<span class="line-numbers">   2 </span> i_certify_that_my_video_stream_does_not_use_b_frames -oac lavc -lavcopts \
<span class="line-numbers">   3 </span> acodec=mp3:abitrate=32 -srate 22050  -ovc lavc -lavcopts vcodec=flv:\
<span class="line-numbers">   4 </span> vbitrate=100:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:predia=2:dia=2:\
<span class="line-numbers">   5 </span> vmax_b_frames=0:vb_strategy=1:precmp=2:cmp=2:subcmp=2:preme=2:qns=2 \
<span class="line-numbers">   6 </span> -vop scale=360:240
</pre></p>


	<p>View the video in the Flash player; you should notice the difference in quality&#8230;</p>


	<p>For even higher quality encode the videos using the H.264 format, which FlowPlayer also supports; instructions can be found <a href="http://www.brad-x.com/2007/05/19/yet-another-linuxnix-video-h264-howto/">here</a>.</p>
  </div>

  <div style="font-size: 0.8em;margin:0.5em;">
    
      Tagged <a href="/tags/24-ffmpeg">ffmpeg</a>, <a href="/tags/198-osx">osx</a>, <a href="/tags/337-leopard">leopard</a>, <a href="/tags/28-flvtool2">flvtool2</a>, <a href="/tags/21-flv">flv</a>, <a href="/tags/338-mencoder">mencoder</a>, <a href="/tags/339-h-264">h.264</a>
    
    
  </div>
</div>






