<?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>Nito &#187; RGB</title>
	<atom:link href="http://blog.pirelenito.org/tag/rgb/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pirelenito.org</link>
	<description>Thoughts dump yard</description>
	<lastBuildDate>Tue, 20 Jul 2010 02:18:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Java movie playback: JOGL + Fobs4JMF</title>
		<link>http://blog.pirelenito.org/2008/08/java-movie-playback-jogl-fobs4jmf/</link>
		<comments>http://blog.pirelenito.org/2008/08/java-movie-playback-jogl-fobs4jmf/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 23:37:45 +0000</pubDate>
		<dc:creator>nito</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[fast]]></category>
		<category><![CDATA[Fobs4JMF]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[JMF]]></category>
		<category><![CDATA[JOGL]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[RGB]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[VideoRenderer]]></category>

		<guid isPermaLink="false">http://blog.pirelenito.org/?p=12</guid>
		<description><![CDATA[Recently I had to integrate video playback on my job&#8217;s Java OpenGL engine, which uses JOGL. Java has a support to media playback through it&#8217;s Java Media Framework, which unfortunately, on it&#8217;s current version (2.1.1e) does not support many formats for video playback. So I quickly looked for alternatives, including IBM Toolkit for mpeg4, that [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I had to integrate <strong>video playback</strong> on my job&#8217;s <strong>Java OpenGL</strong> engine, which uses <a href="https://jogl.dev.java.net/" target="_blank">JOGL</a>.</p>
<p>Java has a support to media playback through it&#8217;s <a href="http://java.sun.com/javase/technologies/desktop/media/jmf/" target="_blank">Java Media Framework</a>, which unfortunately, on it&#8217;s current version (2.1.1e) does not support many <a href="http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/formats.html" target="_blank">formats for video playback</a>.</p>
<p>So I quickly looked for alternatives, including <a href="http://www.alphaworks.ibm.com/tech/tk4mpeg4" target="_blank">IBM Toolkit for mpeg4</a>, that hadn&#8217;t a sufficient production performance I was looking for, and didn&#8217;t offer an easy option for frame grabbing or plugin extensions as JMF does.</p>
<p>Next was <a href="http://fobs.sourceforge.net/" target="_blank">Fobs4JMF</a>, which is <a href="http://java.sun.com/javase/technologies/desktop/media/jmf/" target="_blank">JMF</a> + <a href="http://ffmpeg.org/" target="_blank">ffmpeg</a>. This solution was much more interesting, since it offers a <strong>wide variety of codecs</strong> (ogg, mp3, m4a, divx, xvid, h264, mov, etc) and is based on the solid ffmpeg solution to decode audio and video.</p>
<p>My implementation, uses the plug-in capabilities of JMF to extend a custom renderer that does a pixel type conversion and rendering to a texture:</p>
<div style="text-align: center;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="src" value="http://www.youtube.com/v/-zh6yDyasSo&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/-zh6yDyasSo&amp;hl=en&amp;fs=1" allowfullscreen="true"></embed></object></div>
<p><span id="more-12"></span></p>
<p>This custom renderer works with RGB textures, a type I seemed to made work on my two test machines:</p>
<ul>
<li>MacBook with a Integ GMA x3100 &#8211; Leopard;</li>
<li>PC with a Radeon x600 &#8211; Debian.</li>
</ul>
<p>You might wanna try different pixel types to increase the performance on different target machines.</p>
<p>First, lets describe <strong>how the Renderer works:</strong></p>
<p>It got to be an implementation of a <em>javax.media.renderer.VideoRenderer</em> since it will be installed as a <strong>plugin on JMF</strong>.</p>
<p>For the different methods we need to implement, there are a few we need to take proper care of:</p>
<ul>
<li><strong>process</strong>: this is the method JMF calls passing the movie&#8217;s current frame buffer, here we process the buffer so that we can latter render it in OpenGL;</li>
<li><strong>getSupportedInputFormats</strong>: we return RGBFormat, our target texture format;</li>
<li><strong>setInputFormat</strong>: here we simply tell JMF that the format it chooses is the one we want. Since RGB was the only one we returned as supported, there is not much to do here as well.</li>
<li><strong>getName</strong>: returns the renderer neat name!</li>
</ul>
<p>Next we need a way to access this renderer outside of the JMF world, so that we can get the texture to render it on the teapot. For this purpose our class must also be a <em>javax.media.Control,</em> then we can easily get it through an <em>getControl</em> call, such as:</p>
<blockquote><p>player.getControl(&#8220;javax.media.renderer.VideoRenderer&#8221;);</p></blockquote>
<p>So we implement:</p>
<ul>
<li><strong>getControl</strong>: returns it&#8217;s instance;</li>
<li><strong>getControls</strong>: returns an array containing only it&#8217;s instance as a valid control.</li>
</ul>
<p>The renderer implementation is <em><a href="http://github.com/pirelenito/MovieGL/blob/master/src/org/pirelenito/multimedia/jmf/plugin/RGBGLTextureRenderer.java">org.pirelenito.multimedia.jmf.plugin.RGBGLTextureRenderer</a></em>.</p>
<p>And also, to make further development easy, there is an <a href="http://github.com/pirelenito/MovieGL/blob/master/src/org/pirelenito/multimedia/jmf/plugin/IGLTextureRenderer.java">IGLTextureRenderer</a> interface with the public methods called by the Canvas:</p>
<ul>
<li><strong>render</strong>: that plots the buffer on the texture surface;</li>
<li><strong>getTexture</strong>: to retrieve the texture instance.</li>
</ul>
<p>Last but not least important, you will need to <strong>register the renderer</strong> on JMF, this is done through the <em>JMFRegistry</em> application. The easiest way to start it is inside Eclipse, where our custom renderer is already on the class path:</p>
<ul>
<li>Create a new run configuration;</li>
<li>Set the main class as: JMFRegistry;</li>
<li>Start it, and go to the Plugins tab, then Renderer;</li>
<li>Add the org.pirelenito.multimedia.jmf.plugin.RGBGLTextureRenderer;</li>
<li>Move it to the top of the list;</li>
<li>Push Commit, and you are good to go!</li>
</ul>
<p>To test it out there is also a <a href="http://github.com/pirelenito/MovieGL/blob/master/src/org/pirelenito/multimedia/jmf/MoviePlayer.java">helper class</a> to instantiate the movie player, and a <a href="http://github.com/pirelenito/MovieGL/blob/master/src/org/pirelenito/movieGL/Main.java">Main</a> class which is an OpenGL canvas used to render the teapot with the texture on its surface.</p>
<p>I am not very experienced with OpenGL, so there might be <strong>more effitient ways</strong> to do this using, for instance, <strong>PBO</strong> (Pixel Buffer Object). If you have any question or suggestions on how to improve this solution, don&#8217;t hesitate on drooping a comment!</p>
<p><a href="http://github.com/pirelenito/MovieGL">Here is the project&#8217;s repository</a>. You will need to download a few dependencies, so check the Readme file for more information.</p>
<p><span style="text-decoration: line-through;"><strong>Update:</strong> I wasn&#8217;t properly initializing the Texture. and since I want to add support for more pixel formats, it is easy for you to checkout the updated Eclipse project at: <a href="http://labs.pirelenito.org/experiments/svn/java/MovieGL/" target="_blank">http://labs.pirelenito.org/experiments/svn/java/MovieGL/</a><del datetime="2008-08-21T20:34:00+00:00"> latter this afternoon</del> now.</span></p>
<p><span style="text-decoration: line-through;"><strong>Update 2:</strong> Added the <a href="http://labs.pirelenito.org/experiments/svn/java/MovieGL/" target="_blank">repository link</a> on the image above.</span></p>
<p><span style="text-decoration: line-through;"><strong>Update 3:</strong> I&#8217;ve migrated my server to a new location, and the Subversion wasn&#8217;t up until today. Sorry.</span></p>
<p><strong>Update 4:</strong> Small review on the post.</p>
<p><strong>Update 5:</strong> Moved the repository to <a href="http://github.com/pirelenito/MovieGL">github</a>.</p>
<p>Cheers! <img src='http://blog.pirelenito.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pirelenito.org/2008/08/java-movie-playback-jogl-fobs4jmf/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
	</channel>
</rss>
