tag:blogger.com,1999:blog-38115738508914675262024-02-19T11:17:12.514-08:00psx h4x0rz in teh wiredRamblings about jPSXdec and PlayStation multimediaUnknownnoreply@blogger.comBlogger37125tag:blogger.com,1999:blog-3811573850891467526.post-71951935692427407042021-04-01T18:13:00.002-07:002021-04-01T18:16:11.331-07:00Open the nExt Translation Project!<p>In 2014 the <a href="http://psx.lain.pl/"><i>Serial Experiments Lain PSX Game Translation Project </i></a>completed, culminating in a 695 page translation reference that gave English speakers the first real window into the game's story. Unfortunately its lofty goal to integrate the translation back into the game was never realized, and the translation had a number of errors.</p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc5L5qgwN2_r8uLzsos8nPwGYQsDG3hFJti5nyLhJ8je7SgmJBCFbV8TKZLyYSsj6pAaVNi2P8LPAZWriAe4KRTshok0gzaIUxp95UdboOkMLuopUzKHMEwNI2CcTvL-oap2eSVqmR89M/s1168/Lain.jpg" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" data-original-height="1168" data-original-width="744" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc5L5qgwN2_r8uLzsos8nPwGYQsDG3hFJti5nyLhJ8je7SgmJBCFbV8TKZLyYSsj6pAaVNi2P8LPAZWriAe4KRTshok0gzaIUxp95UdboOkMLuopUzKHMEwNI2CcTvL-oap2eSVqmR89M/w204-h320/Lain.jpg" width="204" /></a></div><p>But what if I told you that with the Close of that World, a new one would eventually Open? Maybe you wished you could play the actual game but with subtitles? Maybe you wanted a better translation?</p><p>In fact, a brand new team of dedicated Lain fans have taken it all to the nExt level. They've created a near complete re-creation of the PlayStation game that runs in your web browser! All media plays with English subtitles.</p><p>Check it out! <a href="https://3d.laingame.net/">https://3d.laingame.net/</a> It's a little rough around the edges, so if you find an issue be sure to report it.<br /></p><p>And here's the source code for the devs out there <a href="https://github.com/ad044/lainTSX">https://github.com/ad044/lainTSX</a></p><p>Having worked with several members of the team, I must say they have some extremely talented and dedicated people making it all possible.
</p>Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-3811573850891467526.post-58048953546183363642016-07-30T13:29:00.004-07:002017-01-14T00:05:50.016-08:00PlayStation audio and exceptional video quality<p>I'm still learning about audio in PlayStation games (<a href="http://problemkaputt.de/psx-spx.htm">Nocash Playstation Specifications</a> is amazing!). The XA ADPCM audio format, frequently seen with STR videos, is what I'm most familiar with. But the PlayStation also has a Sound Processing Unit (SPU) that is used to play all other audio you hear in the game.</p>
<p>XA audio is easy to identify and convert. SPU audio, often referred to as "VAG" ("Very Audio Good"), isn't so easy. The easiest clips to identify are simple sound effects that are played and then end. It gets a little more difficult with audio clips that need to loop. Where it gets impossible to identify is when multiple audio clips are combined to form unique sounds in real-time. I believe this is called "SEQ" and is how a lot of background music is done in games. Each instrument is actually little sound clips being played at different frequencies. This brings up another challenge with all SPU audio: clips can be played at any frequency, and there isn't any way to know what it is.</p>
<p>One case where a game used instrumental audio along with STR video is the Valkyrie Profile opening FMV. jPSXdec can only identify the video clip, but has no way to recreate the music. Thankfully, diligent people have put a lot of effort into extracting these instrumental kinds of audio. These are stored in what's known as <a href="https://en.wikipedia.org/wiki/Portable_Sound_Format">PSF</a> files. Lo and behold, someone has taken the time extract the Valkyrie Profile instrumental music into PSF files.</p>
<p>With my growing knowledge around PlayStation audio, I thought it would be fun to create a very high quality conversion of the Valkyrie Profile opening. I assume using a PSF converter could produce better quality audio than what you can get on hardware or emulators. jPSXdec can extract the video with the best possible quality which can be made even better with other tools.</p>
<p>Tools used:</p>
<ul>
<li><a href="http://www.bannister.org/software/ao.htm">Audio Overload 64-bit</a></li>
<li><a href="http://www.virtualdub.org/">VirtualDub</a></li>
<li><a href="http://avisynth.nl">Avisynth 2.6</a></li>
<li><a href="http://avisynth.nl/index.php/Nnedi3">nnedi3</a></li>
<li><a href="http://avisynth.nl/index.php/DGDecode">DGMPGDec</a></li>
<li><a href="https://ffmpeg.zeranoe.com/builds/">32-bit static ffmpeg</a></li>
</ul>
<p>Steps:</p>
<ol>
<li>Extracted Valkyrie Profile opening video with jPSXdec in avi:jyuv format. This is YUV using the [0-255] component range.</li>
<li>Downloaded Valkyrie Profile psf audio clips.</li>
<li>Used Audio Overload to convert opening video PSF to wav.</li>
<li>Used VirtualDub to mux the video and audio into a single avi, with a 1 second audio delay to sync them up correctly.</li>
<li>
<p>Created an Avisynth script to upscale the video to HD quality and convert to RGB. DGMPGDec plugin was used for deblocking and nnedi3 plugin for scaling.</p>
<div class="codehilite" style="background: #f8f8f8; border: 1px solid silver; background: #f4f4f4; padding-left: 0.5em; word-wrap: normal; overflow-x: auto; overflow-y: hidden"><pre style="line-height: 125%"><span style="color: #8f5902; font-style: italic"># VALKYRIE.BIN[0]HD.avs</span>
<span style="color: #8f5902; font-style: italic"># For deblocking</span>
<span style="color: #000000">LoadPlugin</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">"DGDecode.dll"</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #8f5902; font-style: italic"># For scaling</span>
<span style="color: #000000">LoadPlugin</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">"nnedi3.dll"</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #000000">AviSource</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #4e9a06">"VALKYRIE.BIN[0]jyuv+audio.avi"</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #000000">pixel_type</span><span style="color: #ce5c00; font-weight: bold">=</span><span style="color: #4e9a06">"YV12"</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #8f5902; font-style: italic"># Deblocking</span>
<span style="color: #8f5902; font-style: italic"># quant is the strength between 1 and 31</span>
<span style="color: #8f5902; font-style: italic"># The quant=31 removed the maximum blocking issues</span>
<span style="color: #8f5902; font-style: italic"># Didn't seem to blur anything else</span>
<span style="color: #000000">BlindPP</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">quant</span><span style="color: #ce5c00; font-weight: bold">=</span><span style="color: #0000cf; font-weight: bold">31</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #8f5902; font-style: italic"># Scale up by 4x for a final resolution of 1280x900</span>
<span style="color: #8f5902; font-style: italic"># The results of nnedi3 appeared slightly better than Spline64Resize</span>
<span style="color: #000000">nnedi3_rpow2</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">rfactor</span><span style="color: #ce5c00; font-weight: bold">=</span><span style="color: #0000cf; font-weight: bold">4</span><span style="color: #000000; font-weight: bold">)</span>
<span style="color: #8f5902; font-style: italic"># Avisynth has the unique ability to choose the matrix</span>
<span style="color: #8f5902; font-style: italic"># and ChromaInPlacement when converting to RGB (available since Avisynth 2.6)</span>
<span style="color: #8f5902; font-style: italic"># matrix="pc.601" indicates input is in [0-255] component range</span>
<span style="color: #8f5902; font-style: italic"># ChromaInPlacement="MPEG1" is the chroma placement used by PSX</span>
<span style="color: #000000">ConvertToRGB32</span><span style="color: #000000; font-weight: bold">(</span><span style="color: #000000">matrix</span><span style="color: #ce5c00; font-weight: bold">=</span><span style="color: #4e9a06">"pc.601"</span><span style="color: #000000; font-weight: bold">,</span> <span style="color: #000000">ChromaInPlacement</span><span style="color: #ce5c00; font-weight: bold">=</span><span style="color: #4e9a06">"MPEG1"</span><span style="color: #000000; font-weight: bold">)</span>
</pre></div>
</li>
<li>
<p>Used ffmepg and this script to convert to an uncompressed/RGB/DIB AVI (5 GB file!):</p>
<div class="codehilite" style="background: #f8f8f8; border: 1px solid silver; background: #f4f4f4; padding-left: 0.5em; word-wrap: normal; overflow-x: auto; overflow-y: hidden"><pre style="line-height: 125%"><span style="color: #000000">ffmpeg</span> <span style="color: #ce5c00; font-weight: bold">-</span><span style="color: #000000">i</span> <span style="color: #000000">VALKYRIE</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">BIN</span><span style="color: #000000; font-weight: bold">[</span><span style="color: #0000cf; font-weight: bold">0</span><span style="color: #000000; font-weight: bold">]</span><span style="color: #000000">HD</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">avs</span> <span style="color: #ce5c00; font-weight: bold">-</span><span style="color: #000000">acodec</span> <span style="color: #000000">copy</span> <span style="color: #ce5c00; font-weight: bold">-</span><span style="color: #000000">vcodec</span> <span style="color: #000000">rawvideo</span> <span style="color: #000000">VALKYRIE</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">BIN</span><span style="color: #000000; font-weight: bold">[</span><span style="color: #0000cf; font-weight: bold">0</span><span style="color: #000000; font-weight: bold">]</span><span style="color: #000000">HD</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">avi</span>
</pre></div>
</li>
<li>
<p>That looked good, so then compressed to an almost lossless mp4</p>
<div class="codehilite" style="background: #f8f8f8; border: 1px solid silver; background: #f4f4f4; padding-left: 0.5em; word-wrap: normal; overflow-x: auto; overflow-y: hidden"><pre style="line-height: 125%"><span style="color: #000000">ffmpeg</span> <span style="color: #ce5c00; font-weight: bold">-</span><span style="color: #000000">i</span> <span style="color: #000000">VALKYRIE</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">BIN</span><span style="color: #000000; font-weight: bold">[</span><span style="color: #0000cf; font-weight: bold">0</span><span style="color: #000000; font-weight: bold">]</span><span style="color: #000000">HD</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">avi</span> <span style="color: #ce5c00; font-weight: bold">-</span><span style="color: #000000">pix_fmt</span> <span style="color: #000000">yuv420p</span> <span style="color: #ce5c00; font-weight: bold">-</span><span style="color: #000000">c:v</span> <span style="color: #000000">libx264</span> <span style="color: #ce5c00; font-weight: bold">-</span><span style="color: #000000">qp</span> <span style="color: #0000cf; font-weight: bold">1</span> <span style="color: #ce5c00; font-weight: bold">-</span><span style="color: #000000">preset</span> <span style="color: #000000">veryslow</span> <span style="color: #ce5c00; font-weight: bold">-</span><span style="color: #000000">c:a</span> <span style="color: #000000">aac</span> <span style="color: #ce5c00; font-weight: bold">-</span><span style="color: #000000">strict</span> <span style="color: #000000">experimental</span> <span style="color: #ce5c00; font-weight: bold">-</span><span style="color: #000000">b:a</span> <span style="color: #0000cf; font-weight: bold">192</span><span style="color: #000000">k</span> <span style="color: #ce5c00; font-weight: bold">-</span><span style="color: #000000">ac</span> <span style="color: #0000cf; font-weight: bold">2</span> <span style="color: #000000">VALKYRIE</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">BIN</span><span style="color: #000000; font-weight: bold">[</span><span style="color: #0000cf; font-weight: bold">0</span><span style="color: #000000; font-weight: bold">]</span><span style="color: #000000">HD</span><span style="color: #ce5c00; font-weight: bold">.</span><span style="color: #000000">mp4</span>
</pre></div>
</li>
</ol>
<p><a href="https://youtu.be/Bl5zIM159tc">The result turned out pretty good.</a></p>Unknownnoreply@blogger.com6tag:blogger.com,1999:blog-3811573850891467526.post-31143038316841547832012-03-13T03:40:00.003-07:002012-07-10T22:56:46.910-07:00In The NewsIt might be a time for celebration because I've finally bumped jPSXdec into 'beta' status. It's pretty much feature complete now. At worst there may be a redesign of a couple modules as I've recently been hit with the <a href="http://smf.mameworld.info/?p=12">infamous</a> Judge Dredd which breaks some assumptions. I also think the GUI leaves much to be desired (thank you user-testing!).<br /><br />During the life of jPSXdec I've always been really interested in what people were using jPSXdec for.<br /><br />In recent news, a <a href="http://omnicide.legacy-of-kain.ru/dev-en">project to recreate the game Blood Omen: Legacy of Kain</a> looks to be <a href="http://omnicide.legacy-of-kain.ru/dev-en/200-the-distinct-chronicles">using jPSXdec to help upsample the videos.</a><br /><br />I was going to link to a recently posted, and possibly related HD version of the Blood Omen videos, but to my surprise, <a href="http://www.youtube.com/user/Boulotaur2024">Boulotaur2024's YouTube account</a> has been terminated. He's been posting HD versions of several game videos, utilizing jPSXdec for most of the PlayStation ones. It was great because he found a few games that jPSXdec had problems with. Guess <em>Media Interactive Inc.</em> and the <em>Record Industry Association of Japan</em> didn't appreciate his work.<br /><br />The great ScummVM project has made use of my awesome documentation to add a <a href="https://github.com/scummvm/scummvm/commits/master/video/psx_decoder.h">PlayStation video player</a> so it could utilize the PSX videos from Broken Sword 1 and 2. They've written up <a href="http://wiki.scummvm.org/index.php/HOWTO-PlayStation_Videos">a few instructions</a> on how to get your videos ready to play in the emulator.Unknownnoreply@blogger.com7tag:blogger.com,1999:blog-3811573850891467526.post-67394565183746182032011-08-13T08:47:00.000-07:002011-08-13T09:15:03.505-07:00ReplicateOn a whim, I ran one of the unique identifiers in the Lain game through Google which led me to a couple interesting sites.
<br />
<br />A <a href="http://lain.xq3.ru/">very impressive Russian site</a> is trying to recreate most of the game's content for browsing on the web. What impressed me even more is the creator managed to reverse-engineer some of the game's data types before I did. He kindly gave jPSXdec a <a href="http://lain.xq3.ru/about.html">shout out</a> since it was used heavily to extract nearly everything on the site.
<br />
<br /><a href="http://www.geocities.co.jp/Playtown/3444/lain.html">This very old Japanese site</a> I've seen before, but did a good job of documenting the game's content as well.
<br />
<br />Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-3811573850891467526.post-83686966094123144402011-08-05T06:28:00.000-07:002011-08-05T08:38:38.881-07:00Translation HackingThere's been a bit of activity with the translation lately, so I've been working more on the translation tools. Here's real video of the proof-of-concept I <a href="http://jpsxdec.blogspot.com/2008/02/nihongo-niban.html">posted previously</a>.<br /><br /><iframe width="425" height="349" src="http://www.youtube.com/embed/T-9XW_OoCEQ" frameborder="0" allowfullscreen></iframe><br /><br />I figured it would be a bit rough to use this approach. Unfortunately, anything more than this would multiply the amount of work many times.<br /><br />I've also discovered there are 34 images on the game discs that don't seem to ever appear in the game. They're not particularly interesting, however.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1AYRb51-c4WDS1QVGrm2OFlBrBC0LkPbFLnv4MlRK0I4S5awhUXjjAwQHmDP8Y1zeA1bYhJQfs8djmar-UyKBBF9ZFaryTyO-kg64NyNhcHm0D0dD-njGtQ3yHGwQXDTk2069PNPdq9Y/s1600/LainUnused.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 314px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1AYRb51-c4WDS1QVGrm2OFlBrBC0LkPbFLnv4MlRK0I4S5awhUXjjAwQHmDP8Y1zeA1bYhJQfs8djmar-UyKBBF9ZFaryTyO-kg64NyNhcHm0D0dD-njGtQ3yHGwQXDTk2069PNPdq9Y/s400/LainUnused.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5637364312086212402" /></a>Unknownnoreply@blogger.com4tag:blogger.com,1999:blog-3811573850891467526.post-2663741167958791592011-06-01T22:45:00.001-07:002017-03-27T12:38:29.397-07:00Decoding MPEG-like bitstreams<p>While developing jPSXdec for the last 4 years, I've run across three different methods of decoding bitstreams. <!-- Of course, in the honored tradition of multimedia hacking, none of these approaches are documented anywhere. So I thought I'd break that unwritten rule and actually write about them.--></p><p><em>If you'd like to learn more about what part this plays in MPEG and PlayStation .STR decoding, check out my thorough document on the subject: <a href="https://github.com/m35/jpsxdec">PlayStation_STR_format.txt</a></em> </p><h4>Approach 1: Brute force</h4><p>This is the most obvious approach. For each code, peek the next n-bits until the bits match something.</p><div class="codehilite" style="background: #181818; border: 1px solid silver; background: #141414; padding-left: 0.5em; word-wrap: normal; overflow-x: auto; overflow-y: hidden" markdown="1"><pre><code>Next17Bits = Peek17Bits()<br />For Each Possible Code<br /> If Next17Bits starts with code bits<br /> Skip bit code length<br /> If END_OF_BLOCK code<br /> return END_OF_BLOCK<br /> Else If ESCAPE_CODE<br /> ParseEscapeCode()<br /> Else<br /> return matching code<br /> End If<br /> End if<br />Next<br /></code></pre></div><p>In the worst case, this approach requires 111 conditional checks to identify a bit code. To be honest, I've never actually seen this implemented anywhere besides by me years ago when first learning about bitstream parsing.</p><h4>Approach 2: Binary tree</h4><p>I actually ran across this approach implemented in the Serial Experiments Lain PlayStation game. You have a tree of conditionals testing the value of each bit until a match is found. </p><div class="codehilite" style="background: #181818; border: 1px solid silver; background: #141414; padding-left: 0.5em; word-wrap: normal; overflow-x: auto; overflow-y: hidden" markdown="1"><pre><code>If ReadNextBit() == '1'<br /> If ReadNextBit() == '0'<br /> return END_OF_BLOCK<br /> Else<br /> If ReadNextBit() == '0'<br /> return ('11+0'.ZeroRun, '11+0'.AC)<br /> Else<br /> return ('11+1'.ZeroRun, '11+1'.AC)<br /> End If<br /> End If<br />Else<br /> If ReadNextBit() == '1'<br /> If ReadNextBit() == '1'<br /> // '011s'<br /> ...<br /> Else<br /> // '010... and so on<br /> End If<br /> Else<br /> // '00... and so on<br /> End If<br />End If<br /></code></pre></div><p>The branching can be optimized a bit for most leaves: once the length of the bit code is clear, the remaining bits can be used as the index in several small lookup tables. The jPSXdec implementation only requires (in the worst case) 12 branches to determine the longest bit codes.</p><h4>Approach 3: Array lookup</h4><p>I believe this type of approach is used in ffmpeg and the Q-gears decoder. Thanks to the unspoken tradition of never documenting anything, I was unable to understand what it was doing. It wasn't until I reverse-engineered the .iki bitstream parsing that I finally saw how this approach works.</p><p>At least for MPEG-1 (and PSX STR), you can take advantage of its particular set of variable length bit codes. Only the first code ('<code>11s</code>') and the end-of-block code ('<code>10</code>') need special parsing. The rest of the codes fall under one of three groups. The group a code belongs to can be determined by looking at how many initial zeros it has. </p><ul><li>Group one starts with between 1 and 4 zeros (this also includes the escape code <code>000001</code>). </li><li>Group two starts with between 6 and 8 zeros. </li><li>Group three starts with between 9 and 11 zeros. </li></ul><p>All codes in their groups:</p><pre style="font-size: 80%"> [Special handling]<br /> 01 // end-of-block<br /> 11s<br /> ---- [Group 1] ----<br /> 0 11s<br /> 0 100s<br /> 0 101s<br /> 0 0101s<br /> 0 0110s<br /> 0 0111s<br /> 0 00100s<br /> 0 00101s<br /> 0 00110s<br /> 0 00111s<br /> 0 000100s<br /> 0 000101s<br /> 0 000110s<br /> 0 000111s<br /> 0 00001 // escape code<br /> 0 0100000s<br /> 0 0100001s<br /> 0 0100010s<br /> 0 0100011s<br /> 0 0100100s<br /> 0 0100101s<br /> 0 0100110s<br /> 0 0100111s<br /> ---- [Group 2] ----<br /> 000000 1000s<br /> 000000 1001s<br /> 000000 1010s<br /> 000000 1011s<br /> 000000 1100s<br /> 000000 1101s<br /> 000000 1110s<br /> 000000 1111s<br /> 000000 010000s<br /> 000000 010001s<br /> 000000 010010s<br /> 000000 010011s<br /> 000000 010100s<br /> 000000 010101s<br /> 000000 010110s<br /> 000000 010111s<br /> 000000 011000s<br /> 000000 011001s<br /> 000000 011010s<br /> 000000 011011s<br /> 000000 011100s<br /> 000000 011101s<br /> 000000 011110s<br /> 000000 011111s<br /> 000000 0010000s<br /> 000000 0010001s<br /> 000000 0010010s<br /> 000000 0010011s<br /> 000000 0010100s<br /> 000000 0010101s<br /> 000000 0010110s<br /> 000000 0010111s<br /> 000000 0011000s<br /> 000000 0011001s<br /> 000000 0011010s<br /> 000000 0011011s<br /> 000000 0011100s<br /> 000000 0011101s<br /> 000000 0011110s<br /> 000000 0011111s<br /> ---- [Group 3] ----<br /> 000000000 10000s<br /> 000000000 10001s<br /> 000000000 10010s<br /> 000000000 10011s<br /> 000000000 10100s<br /> 000000000 10101s<br /> 000000000 10110s<br /> 000000000 10111s<br /> 000000000 11000s<br /> 000000000 11001s<br /> 000000000 11010s<br /> 000000000 11011s<br /> 000000000 11100s<br /> 000000000 11101s<br /> 000000000 11110s<br /> 000000000 11111s<br /> 000000000 010000s<br /> 000000000 010001s<br /> 000000000 010010s<br /> 000000000 010011s<br /> 000000000 010100s<br /> 000000000 010101s<br /> 000000000 010110s<br /> 000000000 010111s<br /> 000000000 011000s<br /> 000000000 011001s<br /> 000000000 011010s<br /> 000000000 011011s<br /> 000000000 011100s<br /> 000000000 011101s<br /> 000000000 011110s<br /> 000000000 011111s<br /> 000000000 0010000s<br /> 000000000 0010001s<br /> 000000000 0010010s<br /> 000000000 0010011s<br /> 000000000 0010100s<br /> 000000000 0010101s<br /> 000000000 0010110s<br /> 000000000 0010111s<br /> 000000000 0011000s<br /> 000000000 0011001s<br /> 000000000 0011010s<br /> 000000000 0011011s<br /> 000000000 0011100s<br /> 000000000 0011101s<br /> 000000000 0011110s<br /> 000000000 0011111s<br /></pre><p>Each group has its own lookup table of 256 entries, and each code will be associated with one or more entries in the lookup table. After stripping off the minimum number of zeros in the group, no entry in the group will have more than 8 bits remaining in the bit code. For codes that have 8 bits remaining, its value identifies the associated table index. For the bit codes that have fewer than 8 bits remaining, you have to walk through every combination of the remaining bits to find all associated indexes.</p><p>Example:<div markdown="1" style="margin-left: 3em">Group 1 code: 00110s<br />Use 0 for sign bit for now: 001100<br />Strip off first leading 0: 01100<br />Find all combinations of remaining bits:</p><pre><code> 01100+000 = 96 (table index)<br /> 01100+001 = 97<br /> 01100+010 = 98<br /> 01100+011 = 99<br /> 01100+100 = 100<br /> 01100+101 = 101<br /> 01100+110 = 102<br /> 01100+111 = 103<br /></code></pre><p>Thus bit code 00110s will be associated with table indexes 96-103.</div></p><p>Now each table entry needs three values: the inverse discreet cosine transform (IDCT) run of zero-value alternating current (AC) coefficients, the non-zero AC coefficient value, and the length of the bitstream bits that should be skipped.</p><p>Once all three tables are constructed, the following pseudo code will parse your bitstream.</p><div class="codehilite" style="background: #181818; border: 1px solid silver; background: #141414; padding-left: 0.5em; word-wrap: normal; overflow-x: auto; overflow-y: hidden" markdown="1"><pre><code>If ReadNextBit() == '1'<br /> If ReadNextBit() == '0'<br /> return END_OF_BLOCK<br /> Else<br /> If ReadNextBit() == '0'<br /> return ('11+0'.ZeroRun, '11+0'.AC)<br /> Else<br /> return ('11+1'.ZeroRun, '11+1'.AC)<br /> End If<br /> End If<br />Else<br /> Next16Bits = Peek16Bits()<br /> If NumberOfLeadingZeros(Next16Bits) <= 4<br /> Match = LookupTable1[(Next16Bits >> 8) & 0xff]<br /> Else If NumberOfLeadingZeros(Next16Bits) <= 8<br /> Match = LookupTable2[(Next16Bits >> 3) & 0xff]<br /> Else If NumberOfLeadingZeros(Next16Bits) <= 11<br /> Match = LookupTable3[Next16Bits & 0xff]<br /> Else<br /> // bitstream error<br /> End If<br /> If Match == ESCAPE_CODE<br /> SkipBits(ESCAPE_CODE.BitLength)<br /> ParseEscapeCode()<br /> Else<br /> SkipBits(Match.BitLength)<br /> return (Match.ZeroRun, Match.AC)<br /> End If<br />End If<br /></code></pre></div><p>Of course the implementation details can vary, but this gives the idea. The Approach 3 I implemented for jPSXdec requires about 8 conditionals to identify a bit code in the worst case. I've found it to be about 10%-15% faster than the Approach 2 I've been using.</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3811573850891467526.post-71517838905356651962010-09-06T14:33:00.000-07:002011-07-25T13:08:40.140-07:00PlayStation Video Decoders:The Final ShowdownUpdated from the <a href="http://jpsxdec.blogspot.com/2009/10/psx-video-converter-deathmatch.html">previous comparison</a> with the lastest versions, and three new decoders!<br /><br />Most importantly, I finally captured what it <strong>ACTUALLY</strong> looks like on PlayStation hardware (in the dead center).<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEim74AULJb-r3ffXcKH0hFRjkAwEWeIK7SOvm7YIzMfmSQfmSD_UUUbZ7slH8Ivt9NovJLJ_B0UGok9_fPtB5r6QUWIdF2DQXvaNSld3fAIwDpC0jtdfmdJdHXkPgkRDs5pLz2vHoY-CWI/s1600/G_INFO_STR-all-side-by-side.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 296px; height: 400px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEim74AULJb-r3ffXcKH0hFRjkAwEWeIK7SOvm7YIzMfmSQfmSD_UUUbZ7slH8Ivt9NovJLJ_B0UGok9_fPtB5r6QUWIdF2DQXvaNSld3fAIwDpC0jtdfmdJdHXkPgkRDs5pLz2vHoY-CWI/s400/G_INFO_STR-all-side-by-side.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5515540222178963090" /></a>Those on top get it (more) correct, those on the bottom get it (more) wrong (and ffmpeg and Q-gears are just weird).<br /><br />Naturally jPSXdec dominates in quality and accuracy. :)<br /><!-- <br />I'm particularly amused by the failure of the new reevengi decoder because its author is under the impression it is "<a href="http://z4.invisionfree.com/Resident_Evil_1_2_3/index.php?s=c8e331e217513bdad593af53215705a9&showtopic=97&view=findpost&p=2400636">more advanced</a>" than jPSXdec (due to the fact it uses OpenGL, or is written in "<a href="http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.4">C/++</a>", or something...).<br /><br />I was also kinda bummed that the MAME team didn't respond to my offer to help improve their PlayStation MDEC accuracy. Given MAME's philosophy of precise replication of actual hardware, I thought they would welcome it.<br />--><br />The lineup:<ul><li><a href="http://www.zophar.net/utilities/psxutil/psxplay.html">PSXPlay</a></li><li>a fixed version of PCSX by Gabriele Gorla</li><li><a href="http://kenai.com/projects/jpsxdec">jPSXdec</a></li><li><a href="http://mamedev.org/">MAME</a></li><li><a href="http://homepage2.nifty.com/~mkb/PsxMC/">PsxMC</a></li><li><a href="http://www.zophar.net/utilities/psxutil/psmplay.html">PSmplay</a></li><li><a href="http://come.to/psxtulz">PsxTulz</a></li><li><a href="http://pmandin.atari.org/dotclear/index.php?2008/12/28/21-en-perso-engines-reevengi">reevengi</a></li><li><a href="http://www.pcsx.net/">PCSX</a></li><li><a href="http://ffmpeg.org/">ffmeg</a></li><li><a href="http://q-gears.svn.sourceforge.net/viewvc/q-gears/branches/ogre_qgears/src/common/movie/decoders">Q-gears</a></li></ul>See the <a href="https://sites.google.com/site/lainpsxfiles/a/psx-video-deathmatch-20100906.zip">download</a> for all the jucy (and technical) details.Unknownnoreply@blogger.com10tag:blogger.com,1999:blog-3811573850891467526.post-91942231445754403752010-08-19T12:39:00.000-07:002017-03-27T12:42:28.713-07:00Immaculate DecodingJust writing a straight-forward PlayStation 1 video decoder has been a lot of work. However, for the absolute most impeccable quality, there is so much more that can be considered in the process.<br /><h4>Upsampling</h4><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5YqMjWRxasBLkUmzzpA_sHZI9XDVdI8hvp51l7apPhOofE6QZO4hiN4RTGZi4dftO3XbHuqRw7Z622F3NoDHYcRW9dPEcrrbRCC6tDZ-55-W6dIIpIAPYuYM58ekFKJUHca0796TJp2c/s1600/YCbCrBreakdown.png"><img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 200px; height: 178px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5YqMjWRxasBLkUmzzpA_sHZI9XDVdI8hvp51l7apPhOofE6QZO4hiN4RTGZi4dftO3XbHuqRw7Z622F3NoDHYcRW9dPEcrrbRCC6tDZ-55-W6dIIpIAPYuYM58ekFKJUHca0796TJp2c/s200/YCbCrBreakdown.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5507210539772705250"></a>When PlayStation videos are created, the pixels are broken up into luma (brightness) components and chroma (color) components. Like with JPEG and MPEG formats, 3/4 of the chroma information is thrown away because the human eye can't really tell (this is an example of lossy compression).<br /><br />When decoding, that lost chroma information needs to be recreated somehow to convert the pixels back into RGB. Unfortunately there is no one 'right' way to do it, because there's really no way to get that lost information back. All you can do is 'guess' by filling in the blanks based on the information around the pixels using some kind of interpolation. Some of the most well known kinds of interpolation are: nearest neighbor, bilinear, bicubic, and lanczos. I've read about more advanced chroma upsampling approaches that also take into account the luma component. This works because there is often a lot of correlation between the luma and chroma components--when the luma changes, the chroma probably will also. I'd like to try to find the best one, but I haven't had much luck on finding many good resources about them all.<br /><br />Now, because this is essentially just scaling of a 2D image, I've been worried about <a href="http://www.ericbrasseur.org/gamma.html?i=1">this article</a> that points out a nasty little gremlin called gamma correction. It seems nearly everyone has been doing image scaling wrong since the popularization of the sRGB gamma corrected color space. I'm assuming video isn't immune to the same problem, yet I've never seen anyone mention it.<br /><h4>Deblocking</h4><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://en.wikipedia.org/wiki/Compression_artifact"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 150px; height: 180px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAh6HKk_eMSN9ovs2Q4GuBsrsa_o2n7N_flrMn0vSZxtXfe3-YGz1N11YNaS3vc6LRAs4GbZZCN8TlSfU4vTm7JUxIsz_XTS8D-206e19DR_7COxA3tpWEP-mD9KvVQnI5-uUeNE3bLsM/s200/Sego_lily_cm-150.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5507212052889050002"></a>Assuming we find the upsampling method of choice, there are still ways the image can be improved. Most video codecs break the frames down into 'blocks', then encode each block separately--again losing information along the way. When everything is reconstructed, that lost information can often be seen as <a href="http://en.wikipedia.org/wiki/Compression_artifact">visible distortions between blocks</a>. This problem has been addressed in more recent video codecs such as h.264, but is still a problem with the older MPEG2. I believe nearly all DVD players do some deblocking before showing the final frame.<br /><br />Even though MPEG2 has been around a long time and deblocking is so common, I've had the darndest time trying to find much mention of what deblocking algorithms are in use today. <a href="http://www.assassinationscience.com/johncostella/unblock/">UnBlock</a>, and this page on <a href="http://www.utdallas.edu/~aria/mcl/post/">JPEG Post-Processing</a> are the best I've come by. I think I've read somewhere that some advanced deblockers can even make use of the original MPEG2 data to improve the deblocking.<br /><br />I still consider myself a multimedia novice, so there are probably more post-processing methods that would really make the output shine. A big bummer among all research in that area is that if you can think it, you can pretty much count on it been patented.<br /><br /><br />Given how difficult all this stuff is, I really <em>really</em> wish I could just pass that problem off to the big players in the field, such as ffmpeg (i.e. libavcodec). I've even considered writing a PSX video to MPEG2 video translator so the MPEG2 video can be fed into ffmpeg. Unfortunately there are some big reasons why doing this still makes me uneasy.<br /><h4>IDCT</h4>The PlayStation uses its own particular IDCT approach that I've never seen anywhere else. Given how important it is that the <a href="http://guru.multimedia.cx/the-mpeg124-and-h26123-idct/">DCT used to encode the video matches the IDCT used to decode</a>, there are no existing decoders that can do it (except jPSXdec of course). <br /><h4>Differences in YCbCr</h4><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOl0CoSP4DIgRembxSXQao_4KPI3d5UQnFhrsC2RuiM60E-5aNDkpodZxm0g89SI1PUgNUEbe6XgOO1cIFDVPIW7EGzb1R-8Sm6iCiRjE8MtaP9J2J0blhD_Z4P786XumP9CwlLJJpBI0/s1600/ChromaPlacement.png"><img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 200px; height: 116px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOl0CoSP4DIgRembxSXQao_4KPI3d5UQnFhrsC2RuiM60E-5aNDkpodZxm0g89SI1PUgNUEbe6XgOO1cIFDVPIW7EGzb1R-8Sm6iCiRjE8MtaP9J2J0blhD_Z4P786XumP9CwlLJJpBI0/s200/ChromaPlacement.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5507211138310959282"></a>Another worry is that a <strong>real</strong> good quality MPEG2 decoder will spatially position the chroma components in the proper location (vertically aligned with every other luma component) as opposed to how I believe PSX does it (the MPEG1 way: in-between luma components).<br /><br />To make things a bit more complicated, MPEG2 uses the proper Rec.601 Y'CbCr color space with [16-235] luma, and [16-240] chroma range. PSX on the other hand, uses the full [0-255] range for color information. Many video converters don't handle that discrepancy very well. Related to that, pretty much all converters store the data as integers, so any fractional information is lost after every conversion. In contrast, jPSXdec maintains all that fractional information until the very end.<br /><br />In general though, I have <a href="http://jpsxdec.blogspot.com/2010/03/ycbcr-rgb-showdown.html">not been impressed with ffmpeg's quality</a>, so I can't suggest people use it when looking for good quality.<br /><br /><br />One advantage that comes when incorporating all these enhancements in jPSXdec is it provides a much nicer user experience. No need to be hopping between multiple tools to get the best results. <br /><br />So if I were to actually implement all these features, where would I get the information I lack? Perhaps the <a href="http://www.doom9.org/">doom9.org forums</a> could help. If any multimedia gurus happen to pass by this post, please, if you could, toss some wisdom my way.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3811573850891467526.post-27502223337331424652010-03-26T19:34:00.001-07:002012-03-26T23:05:16.566-07:00YCbCr to RGB Conversion ShowdownIn trying to ensure pixel perfect accuracy in my color conversions, I wanted to compare how two popular video converters handle YCbCr to RGB conversion: <a href="http://ffmpeg.org/">ffmpeg</a>* and <a href="http://www.virtualdub.org/">VirtualDub</a> v1.9.8.<br /><br />The Rec.601 YCbCr to RGB equation is defined as such:<blockquote>Given Y color range of [16, 235] and Cb,Cr color range of [16, 240].<br /><br /><pre>[ 1.164 0 1.59 ] [ Y - 16 ] [ r ]<br />[ 1.164 -0.391 -0.813 ] * [ Cb - 128 ] = [ g ]<br />[ 1.164 2.018 0 ] [ Cr - 128 ] [ b ]</pre></blockquote><br />You can generate a table of the YCbCr to RGB conversion using this bit of code. Values outside valid YCbCr ranges are simply mapped to white.<br /><pre style="font-size:80%"><br />public class YCbCrAndRgb {<br /> public static void main(String[] args) {<br /> for (int y = 0; y < 256; y++) {<br /> for (int cb = 0; cb < 256; cb++) {<br /> for (int cr = 0; cr < 256; cr++) {<br /> if (y >= 16 && cb >= 16 && cr >= 16 &&<br /> y <= 235 && cb <= 240 && cr <= 240) <br /> {<br /> int r = (int)Math.round( (y - 16) * 1.164 + (cr - 128) * 1.596 );<br /> int g = (int)Math.round( (y - 16) * 1.164 + (cb - 128) * -0.391 + (cr - 128) * -0.813 );<br /> int b = (int)Math.round( (y - 16) * 1.164 + (cb - 128) * 2.018 );<br /> <br /> if (r < 0) r = 0; else if (r > 255) r = 255;<br /> if (g < 0) g = 0; else if (g > 255) g = 255;<br /> if (b < 0) b = 0; else if (b > 255) b = 255;<br /> <br /> System.out.format("%02x%02x%02x\t%02x%02x%02x", y, cb, cr, r, g, b);<br /> System.out.println();<br /> } else {<br /> System.out.format("%02x%02x%02x\tffffff", y, cb, cr);<br /> System.out.println();<br /> }<br /> }<br /> }<br /> }<br /> }<br />}</pre><br />Using a pixel format without subsampling should let me convert pixels without blending interfering, however ffmpeg still adds blending even to 4:4:4, which would distort the results. So instead I generated several AVIs with small dimensions (8x8) with <a href="http://www.fourcc.org/yuv.php#YV12">fourcc YV12</a> pixel format (4:2:0), each frame containing one solid color. That came out to 256 AVI files, each with 256*256 frames. <br /><br />Those AVIs were fed through ffmpeg and VirtualDub and converted to uncompressed RGB AVIs. This ffmepg command converts YCbCr to RGB AVI.<pre style="font-size:80%">ffmpeg -i inYCbCr.avi -vcodec rawvideo -pix_fmt bgr24 outRgb.avi</pre>Under VirtualDub's Video->Color Depth menu you can set the output pixel format.<br /><br />A little script walked through every AVI and pulled out the first RGB pixel of each frame and associated it with the original YCbCr color.<br /><br />At that point I had a table with 256^3 rows and 4 columns:<br /><ol><li>Original YCbCr color</li><li>RGB generated with the standard equation and floating-point math</li><li>RGB generated with VirtualDub</li><li>RGB generated with ffmpeg</li></ol>Here you can download 4096x4096 images of the resulting RGB values using the three conversion methods.<br /><br /><table style="text-align: center"><tr><td colspan="2">Floating-point<br /><a href="http://sites.google.com/site/lainpsxfiles/a/ycbcr2rgb-myfloat.png?attredirects=0"><img style="cursor:pointer; cursor:hand;width: 200px; height: 200px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4LHNSn3Or31rxWdJf92SCNCjq_z8fE1Ke1UZcLVdWOUIYik-8GUeRa_g13remhp4pECd-Wx8walX_KssP2RaPcN8djC7hhzcXYepbH4x9KzzPRirTD1XpqYYnDSJ1nJOanqt7FBdwleQ/s200/ycbcr2rgb-myfloat.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5453137926293921330" /></a></td></tr><tr><td>VirtualDub<br /><a href="http://sites.google.com/site/lainpsxfiles/a/ycbcr2rgb-virtualdub.png?attredirects=0"><img style="cursor:pointer; cursor:hand;width: 200px; height: 200px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9zC6niFzzcbFa6uQdKockJNe7-nZy_aKlLOcZIQXswvRQdhKJWRHpxwpc1J5kzO3qep0gDDDVEcBVLvzkz5FqHWgNvr5hUhW62tsT_hhRHiYz6C4xVDV1qjzL8nExagfn1r1RC_tH0qU/s200/ycbcr2rgb-virtualdub.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5453138258841018386" /></a></td><td>ffmpeg<br /><a href="http://sites.google.com/site/lainpsxfiles/a/ycbcr2rgb-ffmpeg.png?attredirects=0"><img style="cursor:pointer; cursor:hand;width: 200px; height: 200px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjWkjY8SUDsr7i8FjzOY_mK5VR6XE7G3ccrP6MuL4La9xdr9Bouy_eqm0pTFsXDqYFeIEuFvwnA8_nuMpPvF2j_6sFbVKpmKHHnMo_uB2GTPj-_5eUvHtXPC5OuCkqrVKTGt7yd47v-Zw/s200/ycbcr2rgb-ffmpeg.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5453139457247203058" /></a></td></tr></table>Now to analyze, starting with some visual comparisons. Diffing and autoleveling (normalizing) exposes what pixels are different.<br /><br /><table style="text-align: center"><tr><td>Floating-point vs. VirtualDub<br /><a href="http://sites.google.com/site/lainpsxfiles/a/myfloat-vs-virtualdub.png?attredirects=0"><img style="cursor:pointer; cursor:hand;width: 200px; height: 200px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmibHqV0-EJ_W4YV3r4GisE9ly4oVeABoj0wbWYU1T-1gNtge8odF6yBYAJyrDmXw600SmXn876yrR3n7Oq4zLj3Tr2roIocK6tytQqE_sMj5-1U4g0poX5rMGYKs8KuqSnNHyBynqopI/s200/myfloat-vs-virtualdub.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5453150385174583634" /></a></td><td>Floating-point vs. ffmpeg<br /><a href="http://sites.google.com/site/lainpsxfiles/a/myfloat-vs-ffmpeg.png?attredirects=0"><img style="cursor:pointer; cursor:hand;width: 200px; height: 200px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEircO3iQy_tRcnjklieGUS4E-l1a1a_LsTn-eBxSHbfInP9xkyfk3FzWafgnOToQlGGzma8kk0HXLppaK0ixeqNHCNmZ7qEkaEdifIabvkGibWx3fTxvRNdKr_ZwCtj1qA5azcvyN1ijQk/s200/myfloat-vs-ffmpeg.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5453150652740615794" /></a></td></tr></table>Seems VirtualDub is far more accurate than ffmepg, but still doesn't match the floating-point version perfectly.<br /><br />Now some numbers.<ul><li>VirtualDub has 1795792 pixels (11%) different from the floating-point conversion.</li><li>ffmpeg has 10827725 pixels (65%) different from the floating-point conversion.</li></ul>Differences broken down by color channel.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfYsek2IXh536-b2yMnbs0_6sUhbVZAatR2gs9t34oLFXdIx6aVql2OKeNiIpK7ZybjuvAb1gtkivI7rcgkRoXHN069ZY56vstIdHBGIQqMKHRbJspJzsfruIu61bE3B2wpjNnaPyphqA/s1600/ycbcr-stats.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 200px; height: 136px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfYsek2IXh536-b2yMnbs0_6sUhbVZAatR2gs9t34oLFXdIx6aVql2OKeNiIpK7ZybjuvAb1gtkivI7rcgkRoXHN069ZY56vstIdHBGIQqMKHRbJspJzsfruIu61bE3B2wpjNnaPyphqA/s200/ycbcr-stats.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5453154730621116130" /></a>I'm disappointed but not surprised that there are so many 1-off values in general. But ffmpeg's variance is as much as -3?? Wow, I hope I'm doing something wrong because that's pretty bad.<br /><br />In the rare case someone has over an hour and 10GB to spare, along with various strange prerequisites, you can <a href="http://sites.google.com/site/lainpsxfiles/a/YCbCr-compare.zip?attredirects=0&d=1">download the scripts</a> used to generate these details.<br /><br /><div style="float:left">*</div><pre style="font-size:60%">FFmpeg version SVN-r22107, Copyright (c) 2000-2010 the FFmpeg developers<br /> built on Feb 28 2010 06:11:15 with gcc 4.4.2<br /> configuration: --enable-memalign-hack --cross-prefix=i686-mingw32- --cc=ccache-i686-mingw32-gcc --<br />arch=i686 --target-os=mingw32 --enable-runtime-cpudetect --enable-avisynth --enable-gpl --enable-ver<br />sion3 --enable-bzlib --enable-libgsm --enable-libfaad --enable-pthreads --enable-libvorbis --enable-<br />libtheora --enable-libspeex --enable-libmp3lame --enable-libopenjpeg --enable-libxvid --enable-libsc<br />hroedinger --enable-libx264 --enable-libopencore_amrwb --enable-libopencore_amrnb<br /> libavutil 50. 9. 0 / 50. 9. 0<br /> libavcodec 52.55. 0 / 52.55. 0<br /> libavformat 52.54. 0 / 52.54. 0<br /> libavdevice 52. 2. 0 / 52. 2. 0<br /> libswscale 0.10. 0 / 0.10. 0</pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3811573850891467526.post-32109576968541578802010-03-13T00:00:00.000-08:002010-04-18T13:01:07.982-07:00IDCT Demystified (a little)The inverse discrete cosine transform is a very mysterious and intimidating equation. <br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisPRotJ8ihTIfQ42Zb1sd0loaNiGnT5jbx1X9EqfJqJ5NcmF7rEjklZjwfOyeKykz_CfvfvMJjHkQiO2-iKCmd21M4qFhr-OY7YBpuFhSb6a_e1D8S41MY-tb2lo-x8qKonSO0ar19jF4/s1600-h/idctequation.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 262px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisPRotJ8ihTIfQ42Zb1sd0loaNiGnT5jbx1X9EqfJqJ5NcmF7rEjklZjwfOyeKykz_CfvfvMJjHkQiO2-iKCmd21M4qFhr-OY7YBpuFhSb6a_e1D8S41MY-tb2lo-x8qKonSO0ar19jF4/s400/idctequation.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5448025776156929042" /></a>(apologies if I messed up the notation)<br /><br />For the longest time I let the IDCT remain a black box. I found a handful of Java IDCT implementations, plugged them in, and cross my fingers.<br /><br />I know what the 2D DCT does: it pushes all the image data to the top left corner of the block, while the IDCT undoes that magic. I'm not sure <i>how</i> it does this, but just knowing <i>what</i> it does is enough for me.<br /><br />But recently I finally discovered that the IDCT is simply a couple of matrix multiplications. <br /><br /><i>idct_matrix<sup>T</sup> . coefficients . idct_matrix</i><br /><br />The IDCT equation doesn't really suggest that to the casual mathematician. Of course if you take a class or pay for a book on the subject, maybe this is old news to you.<br /><br />For those uninformed like me, let's take a closer look at this IDCT matrix.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilOGE9_B1XW3pyznpqH7NS1oTJSNdECmKEH6K9m6NWsExja3knYuNw_vOSGPFxMMlPxq19ZwY4Du7DJINFkmk10QOkA9c270ZE73Q-BAc6r5OLvkJ7KtWlTxzeQhLkOVXaYEWAq-9XXBE/s1600-h/idctplain.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 347px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilOGE9_B1XW3pyznpqH7NS1oTJSNdECmKEH6K9m6NWsExja3knYuNw_vOSGPFxMMlPxq19ZwY4Du7DJINFkmk10QOkA9c270ZE73Q-BAc6r5OLvkJ7KtWlTxzeQhLkOVXaYEWAq-9XXBE/s400/idctplain.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5448025644081423186" /></a><br />Theoretically we could throw a bunch of trigonometry identities at this matrix to simplify it, but it turns out to be so much easier to just calculate it and see which decimal values are the same. In the end, there turns out to only be 7 unique values (listed here in varying forms).<br /><br /><pre>1/sqrt(8) = cos( PI/ 4)/2<br />cos(1*PI/16)/2 = cos( PI/16)/2 = sqrt(2+sqrt(2+sqrt(2)))/4<br />cos(2*PI/16)/2 = cos( PI/ 8)/2 = sqrt(2+sqrt(2))/4<br />cos(3*PI/16)/2 = cos(3*PI/16)/2 = sqrt(2+sqrt(2-sqrt(2)))/4<br />cos(5*PI/16)/2 = cos(5*PI/16)/2 = sqrt(2-sqrt(2-sqrt(2)))/4<br />cos(6*PI/16)/2 = cos(3*PI/ 8)/2 = sqrt(2-sqrt(2))/4<br />cos(7*PI/16)/2 = cos(7*PI/16)/2 = sqrt(2-sqrt(2+sqrt(2)))/4</pre>Now the IDCT matrix can be simplified to this:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdH1y_1PBb4yTmhJRAaDSCqBC0qQMrl2AAX2UHQm9dgFGhAcXev5AHzlvQESKXmklBTDwmJRn6eIu5SSYPD_uhO_RGsx-XqTLgUGYYGDfugM8r1rx2WhdiZM7E7_DBEseaQvLf1LEhpKw/s1600-h/idctmatrix.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 346px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdH1y_1PBb4yTmhJRAaDSCqBC0qQMrl2AAX2UHQm9dgFGhAcXev5AHzlvQESKXmklBTDwmJRn6eIu5SSYPD_uhO_RGsx-XqTLgUGYYGDfugM8r1rx2WhdiZM7E7_DBEseaQvLf1LEhpKw/s400/idctmatrix.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5448025966067540306" /></a>Taking things a step further, let's multiply the two IDCT matrix multiplications out (<a href="http://maxima.sourceforge.net/">Maxima</a> is awesome). After a lot of trigonometric simplification, it turns into a massive matrix. This tiny portion below resembles what the entire matrix looks like.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQSAVHUZfTYUqKskJU5GJ2gTk0Mwz6WctmNF7mCFg9Xr9hxWHumipW6841CfV2TQARacnBi9JVqLN5MSFBKLAjttmTqb77FHbZOamAhy7bSu0CydZ7wOfGCZgp6SWSKrovU0Ga1qOsRfs/s1600-h/idctmultiplied-summary.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 108px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQSAVHUZfTYUqKskJU5GJ2gTk0Mwz6WctmNF7mCFg9Xr9hxWHumipW6841CfV2TQARacnBi9JVqLN5MSFBKLAjttmTqb77FHbZOamAhy7bSu0CydZ7wOfGCZgp6SWSKrovU0Ga1qOsRfs/s400/idctmultiplied-summary.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5448034062246630498" /></a><br />You can <a href="http://sites.google.com/site/lainpsxfiles/a/idctmultiplied.png?attredirects=0">download</a> the full 30,000 pixel wide image if you dare.<br /><br />All those additions/subtractions help to explain why <a href="http://svn.softwarepublico.gov.br/trac/cacic/browser/cacic/trunk/agente-windows/srcacic/LibJPEG/jidctflt.c?rev=918">fast IDCT implementations</a> consist of so many sums and only occasional multiplications.<br /><br />The bare math still makes it difficult to identify patterns, so I took things to the extreme and <a href="http://sites.google.com/site/lainpsxfiles/a/idct_visualized.html?attredirects=0&d=1">visualized it</a> a bit.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3811573850891467526.post-3109873656326182292010-02-07T21:52:00.000-08:002010-04-18T13:01:42.508-07:00Writing a Java-only Video PlayerFinally designed and put together a <a href="http://kenai.com/projects/jpsxdec/sources/svn/show/trunk/src/jpsxdec/player?rev=35">fully working implementation</a>, involving a custom blocking queue and 6 threads. I’ve tested it on Windows XP, OS X, and old Kubuntu Hardy. Windows and Mac both look amazing and run perfectly smooth. Unfortunately on Linux the video playback stutters a lot. At first I thought it was due to the GC. After integrating an impressive object pool design, the cause actually turned out to be the Java audio api.<br /><br />I use the <a href="http://java.sun.com/javase/6/docs/api/javax/sound/sampled/DataLine.html#getLongFramePosition()">audio playback position</a> to determine when a frame should be displayed. Running a little test exposes how reliable this timer is.<br /><div style="color: #0000aa"><br /><div class="content" style="border: 1px solid silver; background: #f4f4f4; padding-left: 0.5em; word-wrap: normal; overflow-x: auto; overflow-y: hidden;"><!-- Generator: GNU source-highlight 2.11.1<br />by Lorenzo Bettini<br />http://www.lorenzobettini.it<br />http://www.gnu.org/software/src-highlite --><br /><pre><tt><span style="font-weight: bold"><span style="color: #000080">import</span></span> javax<span style="color: #990000">.</span>sound<span style="color: #990000">.</span>sampled<span style="color: #990000">.*;</span><br /><br /><span style="font-weight: bold"><span style="color: #0000FF">public</span></span> <span style="font-weight: bold"><span style="color: #0000FF">class</span></span> <span style="color: #008080">AudioPositionTest</span> <span style="color: #FF0000">{</span><br /> <span style="font-weight: bold"><span style="color: #0000FF">public</span></span> <span style="font-weight: bold"><span style="color: #0000FF">static</span></span> <span style="color: #009900">void</span> <span style="font-weight: bold"><span style="color: #000000">main</span></span><span style="color: #990000">(</span>String<span style="color: #990000">[]</span> args<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">throws</span></span> LineUnavailableException <span style="color: #FF0000">{</span><br /> <span style="color: #008080">AudioFormat</span> audFmt <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #0000FF">new</span></span> <span style="font-weight: bold"><span style="color: #000000">AudioFormat</span></span><span style="color: #990000">(</span><span style="color: #993399">18900</span><span style="color: #990000">,</span> <span style="color: #993399">16</span><span style="color: #990000">,</span> <span style="color: #993399">2</span><span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">true</span></span><span style="color: #990000">,</span> <span style="font-weight: bold"><span style="color: #0000FF">true</span></span><span style="color: #990000">);</span><br /> DataLine<span style="color: #990000">.</span><span style="color: #008080">Info</span> info <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #0000FF">new</span></span> DataLine<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">Info</span></span><span style="color: #990000">(</span>SourceDataLine<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #0000FF">class</span></span><span style="color: #990000">,</span> audFmt<span style="color: #990000">);</span><br /> <span style="color: #008080">SourceDataLine</span> player <span style="color: #990000">=</span> <span style="color: #990000">(</span>SourceDataLine<span style="color: #990000">)</span> AudioSystem<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">getLine</span></span><span style="color: #990000">(</span>info<span style="color: #990000">);</span><br /> player<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">open</span></span><span style="color: #990000">(</span>audFmt<span style="color: #990000">);</span><br /> player<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">start</span></span><span style="color: #990000">();</span><br /><br /> <span style="color: #009900">byte</span><span style="color: #990000">[]</span> abBuf <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #0000FF">new</span></span> <span style="color: #009900">byte</span><span style="color: #990000">[</span><span style="color: #993399">2</span> <span style="color: #990000">*</span> <span style="color: #993399">400</span><span style="color: #990000">];</span><br /><br /> <span style="color: #009900">long</span> lngTestLength <span style="color: #990000">=</span> <span style="color: #993399">20</span> <span style="color: #990000">*</span> <span style="color: #993399">1000</span><span style="color: #990000">;</span> <span style="font-style: italic"><span style="color: #9A1900">// 20 seconds</span></span><br /> <span style="color: #009900">long</span> lngTestStart <span style="color: #990000">=</span> System<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">currentTimeMillis</span></span><span style="color: #990000">();</span><br /> <span style="color: #009900">long</span> lngTestEnd <span style="color: #990000">=</span> lngTestStart <span style="color: #990000">+</span> lngTestLength<span style="color: #990000">;</span><br /><br /> System<span style="color: #990000">.</span>out<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">println</span></span><span style="color: #990000">(</span>System<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">getProperty</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"os.name"</span><span style="color: #990000">)</span> <span style="color: #990000">+</span> <span style="color: #FF0000">"</span><span style="color: #CC33CC">\t</span><span style="color: #FF0000">Java "</span> <span style="color: #990000">+</span><br /> System<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">getProperty</span></span><span style="color: #990000">(</span><span style="color: #FF0000">"java.version"</span><span style="color: #990000">));</span><br /> <span style="color: #008080">StringBuilder</span> sb <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #0000FF">new</span></span> <span style="font-weight: bold"><span style="color: #000000">StringBuilder</span></span><span style="color: #990000">(</span><span style="color: #993399">400</span><span style="color: #990000">);</span><br /> <span style="font-weight: bold"><span style="color: #0000FF">while</span></span> <span style="color: #990000">(</span>System<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">currentTimeMillis</span></span><span style="color: #990000">()</span> <span style="color: #990000"><</span> lngTestEnd<span style="color: #990000">)</span> <span style="color: #FF0000">{</span><br /> player<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">write</span></span><span style="color: #990000">(</span>abBuf<span style="color: #990000">,</span> <span style="color: #993399">0</span><span style="color: #990000">,</span> abBuf<span style="color: #990000">.</span>length<span style="color: #990000">);</span><br /> <span style="color: #009900">long</span> lngTime <span style="color: #990000">=</span> System<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">currentTimeMillis</span></span><span style="color: #990000">();</span><br /> <span style="color: #009900">long</span> lngPos <span style="color: #990000">=</span> player<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">getLongFramePosition</span></span><span style="color: #990000">();</span><br /> sb<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">append</span></span><span style="color: #990000">(</span>lngTime <span style="color: #990000">-</span> lngTestStart<span style="color: #990000">);</span><br /> sb<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">append</span></span><span style="color: #990000">(</span><span style="color: #FF0000">'</span><span style="color: #CC33CC">\t</span><span style="color: #FF0000">'</span><span style="color: #990000">);</span><br /> sb<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">append</span></span><span style="color: #990000">(</span>lngPos<span style="color: #990000">);</span><br /> System<span style="color: #990000">.</span>out<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">println</span></span><span style="color: #990000">(</span>sb<span style="color: #990000">);</span><br /> sb<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">setLength</span></span><span style="color: #990000">(</span><span style="color: #993399">0</span><span style="color: #990000">);</span><br /> Thread<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">yield</span></span><span style="color: #990000">();</span><br /> <span style="color: #FF0000">}</span><br /><br /> player<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">stop</span></span><span style="color: #990000">();</span><br /> player<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">close</span></span><span style="color: #990000">();</span><br /> <span style="color: #FF0000">}</span><br /><span style="color: #FF0000">}</span></tt></pre></div></div><br />Graphing some of the output makes it pretty clear why Linux playback is choppy.<div style="text-align: center"><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrvw146rJyCh06WSziEV8Nj_eVFQERkKr3ZVoRRZ1Y9Swk3CP28zC2mUXAKzqoJLNh1P6EmsGmTl1AwzGd7Y87-a5zf1gxux1QlW25I_SZNeTSqsNgq0e6QAHPs2xZ4ekbiLyXMY5FVys/s1600-h/20100207-Windows-Playback.gif"><img style="margin:0 10px 10px 10px;cursor:pointer; cursor:hand;width: 200px; height: 136px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrvw146rJyCh06WSziEV8Nj_eVFQERkKr3ZVoRRZ1Y9Swk3CP28zC2mUXAKzqoJLNh1P6EmsGmTl1AwzGd7Y87-a5zf1gxux1QlW25I_SZNeTSqsNgq0e6QAHPs2xZ4ekbiLyXMY5FVys/s200/20100207-Windows-Playback.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5435746643044447570" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-uKlgPccD8CxrPjHqFpLFB9Ebrb7aGBrRSDESFRqybqT7qEQNEJXmzv1hVKaeDIgjsOlO-1GU3bB1bWFBotkmUw0JX2In6vshDfjJN6eCaISTVJPuUbZ3iLvzjSL-VeeW7S_NZn7ZArQ/s1600-h/20100207-Kubuntu-Playback.gif"><img style="margin:0 10px 10px 10px;cursor:pointer; cursor:hand;width: 200px; height: 136px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-uKlgPccD8CxrPjHqFpLFB9Ebrb7aGBrRSDESFRqybqT7qEQNEJXmzv1hVKaeDIgjsOlO-1GU3bB1bWFBotkmUw0JX2In6vshDfjJN6eCaISTVJPuUbZ3iLvzjSL-VeeW7S_NZn7ZArQ/s200/20100207-Kubuntu-Playback.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5435746825129726050" /></a></div><br />Since that isn’t going to work, my next test will involve registering a <a href="http://java.sun.com/javase/6/docs/api/javax/sound/sampled/Line.html#addLineListener%28javax.sound.sampled.LineListener%29">listener</a> for <a href="http://java.sun.com/javase/6/docs/api/javax/sound/sampled/LineEvent.Type.html">start and stop events</a>, and track playback time manually. Though I’m worried my time and the playback time are going to get out of sync.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3811573850891467526.post-74500287575124207952009-10-24T09:50:00.001-07:002012-10-10T16:13:41.055-07:00PSX Video Converter Deathmatch<hr><em><strong>UPDATE:</strong> This comparison has been superseded by a <a href="http://jpsxdec.blogspot.com/2010/09/psx-video-decoders-final-showdown.html">newer one</a></em><hr><br />I took 8 different video converters and lined them up for the showdown of the decade!<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVsp-nZM0kW6CvbhHcUrE_jwBD2Jh3P3CoNiGAV4pcz4UaX4G5PLi-X-8NXUFqW1ltaWCVAzPlIFBWAmAFIEvETqjEl8P0dnQT66GVBUUHPq1IPoFZaviwBUjw83ikoI8II0k2OlZ2DwI/s1600/G_INFO_STR-all-8-side-by-side.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 356px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVsp-nZM0kW6CvbhHcUrE_jwBD2Jh3P3CoNiGAV4pcz4UaX4G5PLi-X-8NXUFqW1ltaWCVAzPlIFBWAmAFIEvETqjEl8P0dnQT66GVBUUHPq1IPoFZaviwBUjw83ikoI8II0k2OlZ2DwI/s400/G_INFO_STR-all-8-side-by-side.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5407324193513896002" /></a>Ok, so it's not really that dramatic. Some points of interest:<br /><ul><li>PCSX shows the most amount of blocky artifacts, which is understandable because its converter was designed for speed over quality.</li><li>PsxMC, PSmplay, PsxTulz, and PCSX all show very similar coloring. PsxMC and PSmplay are especially similar; however, they are not pixel exact matches.</li><li>Q-gears seems to have the darkest and warmest colors of them all, while ffmpeg is the brightest.</li><li>jPSXdec seems to produce softer images than the others, and its colors are quite similar to PSXPlay.</li></ul>The differences may not seem very apparent side-by-side, but if you align the images on top of each other (like layers) then toggle the top image's visibility, the differences really stand out.<br /><br />Now which is the most accurate? That depends on your definition of accurate.<br /><ol><li>Do you want the exact values the PlayStation 1 hardware produces?</li><li>Do you want it to match how you see it on the television?</li><li>Do you want it to more closely resemble what the original designer created?</li><li>Do you want a more mathematically precise conversion?</li></ol>I don't have modded PlayStation hardware, and I don't have any way to very accurately capture composite video output, so I can't investigate #1 or #2. <br /><br />You need to have the official Sony PlayStation 1 movie converter tool to investigate #3. If some shifty soul wanted to convert <a href="http://erictheturtlefiles.googlepages.com/ColorBars320x240.avi">this video</a> to STR and send it to me, I could investigate further. ;)<br /><br />I made my best effort to ensure jPSXdec is very mathematically accurate, so I can at least recommend jPSXdec if you want #4.<br /><br /><a href="http://erictheturtlefiles.googlepages.com/psx-video-deathmatch-20091123.zip">Download all the converted images, along with more details (including some source code)</a> on how I did all the conversions.<br /><br /><i><b>25Oct2009:</b> updated download with corrections and included convertible test STR.</i><br /><br /><i><b>23Nov2009:</b> updated download with better PsxTulz screenshot (thanks T_chan!).</i>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3811573850891467526.post-69746650452169662232009-08-15T04:08:00.001-07:002009-11-23T23:25:45.113-08:00jPSXdec forever<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbK-jzXvR3CBPanwynLMZDe9B6teNDRQzYejc8ZySiRYVes4LqtmmBex9aHAyom3FQvNQyZ92OJx1Qqy-aGCsq5eQxcTwfQsnVyNhLNjTho3egsBTz4VJZBVwuXU3S7J1TC_ll06_vzFw/s1600-h/locandchurn.png"><img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 200px; height: 125px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbK-jzXvR3CBPanwynLMZDe9B6teNDRQzYejc8ZySiRYVes4LqtmmBex9aHAyom3FQvNQyZ92OJx1Qqy-aGCsq5eQxcTwfQsnVyNhLNjTho3egsBTz4VJZBVwuXU3S7J1TC_ll06_vzFw/s200/locandchurn.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5370146073439043186" /></a><br />According to Ohloh, jPSXdec is worth at least $150,000, but that is for code from a year ago. It now has now swelled to over 28,000 lines of code in over 170 files, and will probably be past 30k LOC by next version's release.<br /><br />I really wish I could work on jPSXdec non-stop until it's ready for prime time again. School, work, the economy, a seriously expensive family emergency, and some critical life changes have all conspired to make that impossible. In fact, I don't have much hope in seeing the next release available anytime this year.<br /><br />Things completed so far:<br />* The complicated part of media playback (managing 6 simultaneous threads isn't easy)<br />* Much needed cleanup of the Tim decoder, XA ADPCM decoder, and serialization code<br />* Reorganized the arrangement of media streams verses more static types of media<br />* Fixed both bugs on the issue list. <br />* Fixed the Tim false-positive matching that happens fairly often<br />* Fixed FF7 frame-rate miscalculation<br />* Break things up by game (i.e. setup plugin system)<br />* ISO9660 file detection<br />* Improved detection of audio (including CD-i) and video media items<br />* More robust disc image detection<br /><br />Still to do:<br />* Re-implement the saving process for the various media types<br />* Redo frame rate detection<br /><br />Beyond the next release:<br />* Automatic error reporting<br />* Redo the GUI<br />* Append AVI writer to make it stricter so it can produce cleaner AVI files<br />* AVI PNG codec<br />* Yuv4mpeg2 writing and/or AVI YUV codec<br />* Real-time media playback/preview<br />* Searching for static demux and MDEC data<br />* Finding and uncompressing lhz data, often used in PSX games<br />* Raw direct CD reading from the disc drive (based on <a href="http://java-avm.sourceforge.net/">java-avm</a>)<br />* CD-i video formats<br />* More game handling<br />* STR and XA re-encoders<br />* CD track audio handling<br /><br />When hell freezes over:<br />A custom hex browser for jPSXdec. Other free and/or open source hex browsers are generally decent, but none do everything I really need. Some desired features:<br />* Viewing of very large files without loading the whole thing into memory (hundreds of MB) <br />* Quick viewing and editing values as big/little endian of varying bit sizes/signs/types<br />More specifically for PSX hacking<br />* Identifying and browsing by sector (much like CDmage and IsoBuster do)<br />* Highlighting of the sector headers and footers<br />* Viewing of continuous demuxed sector payloads<br />* Identification of known sector types, and the various fields in each<br />* An overview map of the entire CD, with quick identifying symbols/colors for every sector and its type<br />The closest thing I've seen to this is VirtualDub's hex viewer. <br /><br />And the ultimate pièce de résistance:<br />* Real-time processing of the data as you mouse-over it, and showing how it results in the final output<br />* Allows you to take each bit of data in the disc and follow it through the entire decoding process, each step of the way<br />* Allow you to change anything in real-time, and see how it would turn out<br />I've repeatedly imagined a program like this for even just mpeg1 or 2 streams. Those streams are really complicated, and you never get to see the direct connection between the data and the output. It would be so neat to hover over a block or a macro block and be able to see exactly where it was going to end up on screen, how it will look, and everything around it. The whole motion detection as well. It would be an incredible tool to teach people how those streams work. In the almost impossible case you've seen the official Bluetooth development tools, that's exactly what I had in mind.<br /><br />All these neat ideas could eventually turn jPSXdec into the ultimate PSX hacking utility.<br /><br />The time frame for everything? A long...long time. Years probably. Which really makes me wonder: what will become of this project in, say, another decade? Should I start soliciting help?<br /><br />In the next to impossible case someone would like to join in developing jPSXdec, his skills might hopefully include:<br />* Very usable knowledge of Java (no need for an expert because I don't think I am)<br />* Love and value for clear and well documented source code<br />* Some experience with reverse-engineering just about anything (media formats preferred)<br />Added bonus:<br />* General understanding of mpeg/jpeg-type image formats<br />* Awareness of cross-platform development issues, and/or experience with developing simple programs for multiple platforms (i.e. Windows, Linux, Mac)Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-3811573850891467526.post-40188200263869118362009-05-08T05:23:00.000-07:002018-05-26T17:01:58.731-07:00Comparing Media Quality of Playstation 1 gamesI suppose <i>very</i> few people have ever looked as closely at Playstation 1 media as I have. Of those that have, I assume most worked for Sony, or developed games using the official SDK. Of the few that never got that approved proprietary insight, almost all are Japanese. Finally, of those even fewer remaining whose primary language is English, almost none care anymore at this late date. So I thought I'd take a moment and share some of what I've observed.<br /><br />To my knowledge, only one game has actually used custom variable-length (i.e. huffman) codes in its video streams: Serial Experiments Lain. The infamous <a href="https://samples.mplayerhq.hu/game-formats/psx-str/">logo.iki</a> sample may also use custom huffman codes (it sure doesn't use the standard ones), but until I find what game it's from I can't know for sure.<br /><br />Now I assume S.E. Lain's use of custom variable-length codes means its video quality is higher than if the standard set was used, else why would they use it? Its custom decoding software also took full advantage of every last bit of space available to each frame. I've never seen games using the standard SDK decoder that pushed their buffer to the limit. And if that wasn't enough, it sacrificed as much audio quality as it could to increase space for video bandwidth. <br /><br />I find this all terribly ironic because the quality of the game's artwork is downright awful. <br /><br /><div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmEOv3Nfi_enTJovKjXf4kc9wgKNIPENzsce90wGOJbp94-pe-L-10G2LVcG3YLzMZLFVVSh9Kh4PZ4j5X5NLF27c8Oyfwq8sFQXw0fJriFQrfakWJlIBgn1hT-wVpOxWlq84C8TUM_Eo/s1600/20090508-BadLainAnimation-PC.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="200" data-original-width="692" height="92" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmEOv3Nfi_enTJovKjXf4kc9wgKNIPENzsce90wGOJbp94-pe-L-10G2LVcG3YLzMZLFVVSh9Kh4PZ4j5X5NLF27c8Oyfwq8sFQXw0fJriFQrfakWJlIBgn1hT-wVpOxWlq84C8TUM_Eo/s320/20090508-BadLainAnimation-PC.png" width="320" /></a></div>
So while S.E. Lain's video quality is pointlessly top-notch, its sound quality is not only bad, it is probably one of the worst. The audio was encoded very poorly, with many of the loud moments pointlessly sawed to half the dynamic range, creating excruciating distortions.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRAAj8UJgO9tD59ZNXHRqKehmB6ZC1R1g8Cw4ZglR-ZvsX_DP29XoC340sYd6Yh4E-oK7YTHAwLFghd7PgmReJsxQhsbtIcXtOresW9giaWk2WHK7pxQFfDmAg-8T3OatTecwDiBAjFqE/s1600-h/20090412-LainSawWave.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 98px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRAAj8UJgO9tD59ZNXHRqKehmB6ZC1R1g8Cw4ZglR-ZvsX_DP29XoC340sYd6Yh4E-oK7YTHAwLFghd7PgmReJsxQhsbtIcXtOresW9giaWk2WHK7pxQFfDmAg-8T3OatTecwDiBAjFqE/s320/20090412-LainSawWave.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5333428376874248498" /></a>It's a crying shame, because even though everything about the game was different from the anime series, at least the audio contained more work by the original Lain voice actress, Kaori Shimizu. <br /><br />Lain's video decoder also took a small speed hit because the data is stored as big-endian. This means that the little-endian Playstation platform has to take a moment to reverse every 32bit value read from memory. Who knows, maybe reversing it would have sped up the animation of Lain while drudgingly browsing all those media items.<br /><br />The game that I've seen with the next best video quality trick is Alice In Cyber Land. It may be the only game that uses variable frame rates. During times with less video action, the frame rate could be dropped, giving the images more bandwidth for detail. When the action picked up again, the frame rate and quality could return to normal so the more rapid frame changes could be shown. I suspect any game's video could be modified to use this feature. In fact, it's really too bad that the official Sony SDK encoder didn't use this trick. So many game videos might have looked even nicer.<br /><br />Meanwhile, on the good end of the audio quality spectrum, Square's (now SquareEnix) custom audio format provided the best audio experience of any games I've seen. Its unique format, used in several of their RPGs, produced almost twice the quality of the best standard SDK audio format. An entire sector was devoted to each left/right audio channel, and at intervals that resulted in nearly CD quality output.Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-3811573850891467526.post-35247001194025691882009-04-11T04:33:00.000-07:002010-03-12T20:59:36.856-08:00Through the Digital Looking Glass<img style="float:right; margin:0 0 10px 10px;width: 160px; height: 102px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaZPjrH9KkA_eVvmDkXgHnGPOpgssMHTOgRSUnchu3Ym6zLydmSFW9kTV_i6QLTtmqAhaQ_p8ScBf-iPr4fnn-4voRNBNUHzGMumCvkqgEHUt2tt8N6jultvligzCE2UaqoRn2NXqQedg/s400/lainlogo.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5447978343062249714" />While exhaustively reverse-engineering the Serial Experiments Lain game, always in the back of my mind was an article I read years ago. It describes some curious connections between Lain, and another game called Alice In Cyber Land.<br /><a href="http://www.cjas.org/~leng/alice.htm">http://www.cjas.org/~leng/alice.htm</a><br /><br />So naturally, once the Lain game hacking was thoroughly complete, my attention quickly turned to finding the secrets Alice held. <br /><br />The work to discover the unique ways the game stored its videos really paid off. The Alice videos were all well animated, and suggested a game that could be a lot of fun. But for now I must be content with its raw Japanese clips, all of which can now be viewed <a href="http://www.youtube.com/view_play_list?p=AAD2DB9480641831">on Youtube</a>.<br /><br />The Alice In Cyber Land franchise didn't stop with the game. It also included a soundtrack, and <a href="http://www.bcdb.com/cartoon/62318-Alice_In_Cyberland_(Series).html">short OVA</a>. It seems at least episode 1 was <a href="http://www.llamas.net/~asudem/fsd/l1_2.html">fansubbed</a> by a group called "Boot To Da Head" back in 1997. The first episode is <a href="http://www.youtube.com/view_play_list?p=1C3B6E959F340219">now watchable</a> in very low quality, raw Japanese.<br /><br />While the connections between Lain and Alice are intriguing, you might be interested to know that they don't end there. Tucked away in a corner of the internet is a little account by one of the game's creators that extends the connections to one more series: Digimon Tamers.<br /><a href="http://www.konaka.com/alice6/tamers/characters/juri-e.html">http://www.konaka.com/alice6/tamers/characters/juri-e.html</a>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-3811573850891467526.post-86094220322486990312009-04-06T21:42:00.000-07:002010-03-12T21:00:09.625-08:00CD-i<img style="float:right; margin:0 0 10px 10px;width: 120px; height: 89px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCK6IPHAC29g17AsbGI26KglPEC8Icl_krqUZWK7bhtV00S42bNaOdicfggknBGwgOL05JQAuVK_Qxs3O9ZG37cU48-E3853gQWCkoESjV53TEnDI1WYB5rEauPRBeJt8VNCCeALdbUfo/s400/CDIlogo.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5447768481574810322" />I was pleasantly surprised when I found someone concocted a clever way of using jPSXdec to <a href="http://cdii.blogspot.com/2009/03/how-to-convert-music-of-cd-i-games-to.html">decode CD-i audio</a>.<br /><br />As explained in <a href="http://jcatki.no-ip.org:8080/cdxa/">Jonathan Atkins's CDXA documentation</a>, the Sony Playstation 1 and the Phillips CD-i both used the same audio format on their CDs. It never occurred to me that the CD-i likely has a retro community still following it, much like the Playstation 1 does.<br /><br /><a href="http://www.youtube.com/watch?v=AxdELuxh4f0">This video</a> describes a working solution to extracting CD-i audio with jPSXdec that will work with any game. However, after the extraction, you have to manually break up the audio clips and possibly adjust the speed of some.<br /><br />Alternatively, you could do the job that jPSXdec can't yet do so the extracted audio clips don't need any extra editing.<br /><br />If you let jPSXdec do its best to index the CD (or raw music file), it will find all the audio sectors, but fails to concatenate most of the contiguous streams. You're left with several thousand audio clips with a duration of 1 sector. It wouldn't be too difficult to write a script that checks the audio properties (channel, frequency, etc) and finds what sectors should be combined into a single audio clip. It even sounds like <a href="http://jpsxdec.blogspot.com/2007/11/games-tested.html#c2676625570579519582">someone has already managed to make some headway with this</a>.<br /><br />Adding better CD-i audio handling to jPSXdec is quite easy, and will be included in the next release (whenever I can get this redesign finished). As for CD-i video, I can't say I have much motivation (or time) to figure it out. But if anyone wants to get their hands dirty and write some decoding code of their own, I'd be happy to support them however I can.Unknownnoreply@blogger.com4tag:blogger.com,1999:blog-3811573850891467526.post-68707717395908703552009-01-27T06:01:00.000-08:002009-10-08T10:53:47.454-07:00Java real-time video playbackMuch of the easy changes have already been made to jPSXdec. The biggest and hardest change left is implementing real-time playback. To do this in pure Java is tricky. I've spent a month looking at every kind of Java video player out there.<br /><br />I want to keep jPSXdec as cross-platform and simple-to-use as possible (Just Work™). So while the <a href="http://java.sun.com/javase/technologies/desktop/media/jmf/">JMF</a> has Java-only implementations for playback, it needs a separate installation, has far more functionality that I need, and being closed source doesn't help. It's curious that even though the JMF has plenty of documented bugs, and hasn't been updated in years, it's still the de facto Java media standard. Meanwhile, the <a href="http://fmj-sf.net/">FMJ</a> library is open source, but it's even bigger than JMF, and uses JNI to wield each platform's native playing capabilities. I've examined various other small libraries, but nothing met my needs: a simple synchronized audio and video player. So I'm stuck trying to figure out how to do it myself. <br /><br />Initially I thought to duplicate the general design of JMF/FMJ since it seems to work for them. It would also help someone with greater familiarity with those libs to take the next step and properly integrate PSX decoding into them. However, after several days of tearing apart those massive libraries, and seeing I'd only scratched the surface, I dropped that idea. <br /><br />Finally went back and took a closer look at <a href="http://sureplayer.sourceforge.net/">SurePlayer</a>. It plays mpeg1 movies great with very little processor use. It's fully cross-platform, and is a much more digestible library, so I'll be using that as a guide for implementation. With this clear direction, I can push forward with more jPSXdec development. Maybe in several years when Java 7 is ubiquitous, jPSXdec can be changed to utilize the new <a href="http://weblogs.java.net/blog/chet/archive/2007/05/media_frenzy.html">JMC</a>.<br /><br />Also during my searchings I serendipitously ran across a <a href="http://java-avm.sourceforge.net/">Java library to handle cross-platform raw CD reading</a>! It's not quite as clean as I would like, but it's a pretty good foundation to build upon.<br /><br />In other news, we've had a couple translators pop out of the woodwork recently. Will they be the salvation this project so desperately needs? <br /><br />A man can dream.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3811573850891467526.post-54946907787121797402008-09-24T11:31:00.000-07:002018-02-26T17:38:43.796-08:00How to encode quality PlayStation 1 video<p>Recently I've run across a couple of groups trying to replace the video of a Playstation 1 game. As we have to do the same thing with S.E. Lain, I thought I would share some insight as to how it might be done with the highest quality output.</p><p>Since there are many things that go into encoding mpeg video, that step is best left to programs that know how to juggle those options, such as ffmpeg. It also allows you to tweak those options, and use its advanced features to get the best results.</p><p>So here is how you do it, broken down into 6 ridiculously complicated steps.</p><ol type="1" compact><li>Convert your video into 4:2:0 yuv4mpeg2, but using the PSX specific rgb->yuv conversion.</li><li>Feed the yuv4mpeg2 video into ffmpeg at an allowed fps and create a mpeg1 movie with only I-frames (-intra). This should be done at a variety of different quality levels (-qscale from 1 to n).</li><li>Parse the I-frames out of the movie and parse their macro-blocks</li><li>Convert the mpeg1 VLCs to PSX VLCs</li><li>Do this for every mpeg1 quality and pick the one that fits best within the amount of space available to the frame</li><li>Multiplex the frames and construct all the sectors</li></ol><p>If the new video is mostly just the old video with some changes (e.g. subtitles) then quality can improved tremendously with this variation.</p><ol type="1" start="5" compact><li>Use some method to determine which macro blocks to replace (manually picking them, or performing a diff on lossless video data, or a fuzzy diff on lossy video data)</li><li>Only replace those macro blocks with new ones of the same qscale</li><li>If the replaced data makes the frame too big, then either replace the entire frame with an ffmpeg created frame that will fit (qscale will probably be bigger), or remove some quality in the frame to make it smaller</li><li>Multiplex the frames and construct all the sectors</li></ol><p>Alternatively have ffmpeg write an AVI using MJPG codec and parse the JPEG frames and convert the JPEG VLCs to PSX VLCs (I'm not sure how to get ffmpeg to produce quality variations with the MJPG codec).</p>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-3811573850891467526.post-67017606001308973972008-07-14T20:18:00.000-07:002009-04-11T08:39:16.430-07:00zOMG psx.lain.pl is down!And it has been for quite awhile. I thought it was just temporary, but finally learned yesterday that the good fellow that was nice enough to host the page has chosen to close the account. We are grateful for the time we could use the server. <br /><br />Don't worry, we still have all data and work done so far. Unfortunately we're currently without a host, and the project is still stuck at around 14% completion.<br /><br />I personally would like to thank everyone that has contributed thus far...<br /><br /><span style="font-weight:bold;">Hikari</span> - Translated dialogs from video sequences to Polish.<br /><span style="font-weight:bold;">phm</span> - Extracted the media with jpsxdec and setup the wiki. Retranslated video sequences dialogs from Polish to English. Advertised for translators, and coordinated with their changes.<br /><span style="font-weight:bold;">MercuryTW</span> - Provided some translations from a translator of his own (Keigo). Edited/corrected translated files.<br /><span style="font-weight:bold;">stalker-kun</span> - Provided hosting for the wiki.<br /><span style="font-weight:bold;">otakufish</span> - Provided some translations.<br /><span style="font-weight:bold;">toruvinn</span> - Provided nice domain.<br /><span style="font-weight:bold;">farhan</span> - Ruthlessly proofread random translations, utilising his qualifications in the field of Applied Pedantry with Grammar Nazism.<br /><span style="font-weight:bold;">fishy</span> - Proofread translations, created the public project page.<br /><span style="font-weight:bold;">arc</span> - Provided some translations.<br /><span style="font-weight:bold;">Jossos</span> - Provided some translations.<br /><span style="font-weight:bold;">utakata</span> - corrected a Japanese transcription.<br /><span style="font-weight:bold;">Najica</span> - Provided some translations.<br /><span style="font-weight:bold;">Quibbage</span> - Created subtitle files for videos.<br /><br />...and everyone else (sorry if I've missed your name here)--thank you all very much.<br /><br />jPSXdec development has been pretty quiet as well. I should submit the bug that fails to decode some of the Lain videos, or just commit the fix. The next things to do with jPSXdec require some major changes, and things have been busy (my toon won't hit level 60 by itself ;). I'm still here and interested in the project and related topics. I don't plan on that changing anytime soon.Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-3811573850891467526.post-47415506671838430952008-05-04T17:12:00.000-07:002009-04-11T08:39:28.240-07:00Sonic<span style="font-weight:bold;">AVI</span><br />Fixed the obvious problems with AVI writing, but still problems persist.<br />* My Windows Quicktime install must be bad because it crashes from like everything (but Mac Quicktime plays fine)<br />* My Linux mplayer must be bad because it plays all movies stretched, one way or another<br />* All programs on my lappy crash from my movies except Windows Media Player<br />* My Linux Totem still plays it with green garbage<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvwUIr_U3NSKKd80kSnV0UXxwukklPdHXb-rIq9gPX_e_PckvmoVLIbJ3hBawPAtG_fJB-JT78DQSLHc8nIEzxexVpK8GSWd4ACPUQR2xJv33XkI9OsDMBvIC6AvNj753JMAs29noeyZs/s1600-h/TotemGreen.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvwUIr_U3NSKKd80kSnV0UXxwukklPdHXb-rIq9gPX_e_PckvmoVLIbJ3hBawPAtG_fJB-JT78DQSLHc8nIEzxexVpK8GSWd4ACPUQR2xJv33XkI9OsDMBvIC6AvNj753JMAs29noeyZs/s320/TotemGreen.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5196680552166098258" /></a>So I think I may be doing MJPG slightly wrong, but I'm not sure what. Plus I finally figured out why I could never find any documentation on the MJPG codec: "there is no document that defines a single exact format that is universally recognized as a complete specification of “Motion JPEG” for use in all contexts" <a href="http://en.wikipedia.org/wiki/MJPEG">Wikipedia</a> <br /><br /><span style="font-weight:bold;">Native decoder</span><br />Got the native decoder working great on Windows, Linux and Mac. CMake has made cross-platform building a breeze :D It's really exciting to see the decoding plow through dozens of frames per second.<br /><br />Indeed, native decoding is fast...<br /><br /><span style="font-weight:bold;">Java is faster</span><br />The heck?? Contrary to what I thought I saw in my initial tests, my swift Java decoding module is <i>significantly</i> faster than using the native decoder. How? Not sure, but I suspect it's due to all the overhead needed when calling a JNI function (such as changing big-endian to little-endian). It already melts through 150 sectors/second like a hot knife through butter--but since it spends half its time with garbage collection, could it be faster with some object pooling?Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-3811573850891467526.post-63082365400908578682008-04-22T22:12:00.000-07:002009-04-11T08:39:57.195-07:00v0.34I just needed to get something for a public release. It was the re-implementation of the command-line that kept hanging me up (it was boring and I wanted to work on other things ;). I admit in my rush to just get something released, I sorta skimped on the code commenting. :P<br /><h4>Testing</h4>Before releasing, I randomly tested jpsxdec on the dozen or so games that my friends let me borrow. As a result I threw in some last-minute changes to handle a couple new movie types. 'Last minute' means these may not even work right (I look forward to finding a way to save variable frame rate movies ^^).<br /><br />I ran some quick tests on my Linux Mint machine. Compiz was often rendering the progress window without controls, so there was no way to close the program! And there's an annoying JFileChooser 'All Files' filter bug... :P (just wrote a work-around a moment ago).<br /><br />My tests on a Mac were a little more promising. Rendering was slick--even <a href="http://jpsxdec.googlecode.com/svn/trunk/web/macgui.png">looked better</a> than Windows rendering.<br /><br />After seeing how jpsxdec worked on Linux, I was worried about the quality of jpsxdec--then I saw iTunes for Windows and was feeling pretty good again.<br /><h4>AVI writing is faulty</h4>Seems my AVI writer is getting something wrong because it is crashing or otherwise playing poorly on Linux by VLC ('this avi is broken'), mplayer (plays upside-down, stretched, or just crashes), Totem player (green gunk on the screen). On Windows and Mac, Quicktime is having problems (plays video too slowly or crashes). Real Player also crashes the good crash.<br /><h4>Speed</h4>Since much of the core decoding work for jpsxdec is finished, I started looking for something a little more exciting to work on. So, following MrVacBob's suggestion, I began writing a crazy fast Java decoder. After doing everything I could think of, and examining the work of <a href="http://peace.snu.ac.kr/dhkim/java/MPEG/">previous</a> <a href="http://vsr.informatik.tu-chemnitz.de/~jan/MPEG/MPEG_Play.html">coders</a>, I came to the conclusion that a real-time PSX Java decoder may be possible, but the resulting code would be so ugly, long, and annoying, it just isn't worth it. I hope to complete a faster Java decoder that'll cut the decoding time by maybe half, but also make a small, cross-platform native library will be fast enough for real-time playback.<br /><br />My friends keep dropping games on me--more than I can keep up with. It takes so long to rip games that I went ahead and threw together raw cd reading on Windows. It's pretty buggy, and I'm sure I'm doing something wrong, but it mostly worked. If ever I can get it more stable, I'll include it. For my Linux coding friends, the JNI Java class is in the source if you feel like writing a Linux version of the lib :)<br /><h4>Licenses</h4>The LGPL of the Swing libraries included with jpsxdec don't require that I distribute the source code of the libraries (I haven't changed them, and I am linking them separately). But since jpsxdec is GPL, does that require me to include the LGPL sources with the distribution? I really didn't want the hassle of it, but just to be safe I included the source with the pre-combiled binaries together in the zip files.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3811573850891467526.post-86208501107309489802008-03-13T19:49:00.000-07:002009-04-11T08:40:06.147-07:00IncomingBeen wanting to get some stats on jpsxdec code for a long time (Google code doesn't have such features), finally ran across <a href="http://www.statsvn.org/">StatSVN</a> and took a quick look at the results.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUnyTFPAJ5lc3v7TElds40JXbjn5r9OFId0wZbcMUE0Z6YfxJsEW0j7fhmm6GPlH2KXjVHQSvrn8-bsbK1NIcxkTClFtWQrBvG59ZCk3cNbxvV6eVMgcB0TN4LQ1yA0S7945kYhaetShQ/s1600-h/locandchurn.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUnyTFPAJ5lc3v7TElds40JXbjn5r9OFId0wZbcMUE0Z6YfxJsEW0j7fhmm6GPlH2KXjVHQSvrn8-bsbK1NIcxkTClFtWQrBvG59ZCk3cNbxvV6eVMgcB0TN4LQ1yA0S7945kYhaetShQ/s400/locandchurn.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5177430003931071010" /></a><br />Now running over 20,000 lines of code, and almost 100 files. Compared to <a href="http://jpsxdec.blogspot.com/2007/10/open-sauce.html">Oct 21, 2007</a>'s 7,000 lines, that's 13,000 LOC over 144 days, for a measly 90 lines per day.<br /><br />Anyway, I'm guesstimating next week will be the next jpsxdec release. It will have some exciting features:<br /><ul><li><strike>Saving to AVI, both uncompressed and MJPG compressed</strike> your mileage may vary</li><li><strike>A very nice dialog box providing the many decoding options available</strike> it's arrite</li><li><strike>Final Fantasy 9 finally working properly</strike> done!</li><li><strike>Chrono Cross is also working!</strike> mostly done!</li><li><strike>Cleaned up command-line</strike> done!</li><li>and lots of delicious code documentation :)</li></ul>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3811573850891467526.post-35230883411743574342008-02-25T13:59:00.000-08:002009-04-11T08:40:19.167-07:00lain? lain!The <span style="font-weight:bold;"><a href="http://psx.lain.pl/">Serial Experiments Lain PSX Game Translation Project</a></span> is really coming along. A few more wonderful translators have generously offered some help. We have roughly 7% of the game translated already.<br /><br />Here are some exciting fruits of everyone's efforts so far (actual screenshots).<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://lainpsxfiles.googlepages.com/SLPS_016.04_25022008_134827_0103.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px;" src="http://lainpsxfiles.googlepages.com/SLPS_016.04_25022008_134827_0103.png" border="0" alt="" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://lainpsxfiles.googlepages.com/SLPS_016.04_25022008_134832_0196.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px;" src="http://lainpsxfiles.googlepages.com/SLPS_016.04_25022008_134832_0196.png" border="0" alt="" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://lainpsxfiles.googlepages.com/serialtranslationlain.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px;" src="http://lainpsxfiles.googlepages.com/serialtranslationlain.png" border="0" alt="" /></a>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-3811573850891467526.post-78325161765031246642008-02-17T22:08:00.001-08:002018-02-26T17:46:02.226-08:00nihongo nibanMuch awesomeness has transpired recently. But first, the dull ramblings of jpsxdec status.<br /><br />Looked up how to encode uncompressed (RGB) AVI files. It's not too complicated--Microsoft and other sites have usable documentation. Even found a <a href="http://rsb.info.nih.gov/ij/docs/source/ij/plugin/filter/AVI_Writer.java.html">Java class</a> to get me started. <!-- But I got really excited when the hidden art of MJPG encoding was uncovered. It is so ridiculously easy, I can understand why no one ever describes how to do it.* --> Of course if we're gonna write AVI files, we need to know the frame-rate. Just a simple 400 lines of code is all that took. Needed to also change the overall code design to a 'push' architecture with listeners. This had the additional bonus of pulling the actual file writing to the top-level interface--right where it belongs.<br /><br />Overall things are looking pretty good. For the next release I want to add a new popup window showing the many decoding options. <br /><br />Also in the future I want to allow for piping out uncompressed AVI to a program like ffmpeg or mencoder. For Windows I'll also include the infamous Video for Windows. Still need to add raw cd reading. <br /><br />But while merrily carrying on with all this, out of nowhere came a fishy fellow with the powers of language transformation! He generously offered to spend some time with the S.E. Lain game. Sooo... efforts on jpsxdec are delayed as the <span style="font-weight:bold;">Serial Experiments Lain PSX Game Translation Project</span> commences (SELPGTP?).<br /><br />But with 5.5 hours of audio, he has his work cut out for him. Do you share the powers of language transformation? We could really use your help.<br /><br />On the technical side, we are working on adding the eventual translation into the game. And I present to you an actual screen shot based on an <a href="http://jpsxdec.blogspot.com/2007/11/nihongo.html">earlier idea</a>.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglqYpCgnttGUambWoTmc9EaC2bpGhfSQ9KrAVHyEXg5gQwi11aY4VJbIe_sBpmSY0cVI7vyHQbL9nHCDubhVEGisJTSjvJrqZxoo1OBmyebwb6d7s2392BNE3k9HfVNtMZHTu_Bi9mnHM/s1600-h/LainModScreenshot200802.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglqYpCgnttGUambWoTmc9EaC2bpGhfSQ9KrAVHyEXg5gQwi11aY4VJbIe_sBpmSY0cVI7vyHQbL9nHCDubhVEGisJTSjvJrqZxoo1OBmyebwb6d7s2392BNE3k9HfVNtMZHTu_Bi9mnHM/s320/LainModScreenshot200802.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5169184896145522354" /></a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3811573850891467526.post-86541650650691435712008-02-02T10:28:00.000-08:002009-04-11T08:41:43.249-07:00AmalgamationBeen busy with a bunch of different aspects of jpsxdec. Only the GUI and Code Design will be in the next release (v0.31 today!). The rest will show up in releases after that.<br /><br /><span style="font-weight:bold;">GUI</span><br />Even though it's a pretty lame GUI now, I hope it will drop the bar of entry a little. <br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuCySl0GWrfuFlp4NnPBK496myvBg5y7DuBHlmzsC9pbrMjJpLtHFNl8-2sAIUWoeeY8pJQ-cMhgAbTg7RcsOjtd1qpF6N4hej0Uv-ZSAQOdbyxSoyL4pTxRV3ZoxNxktpoxA_8KyvccM/s1600-h/gui.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuCySl0GWrfuFlp4NnPBK496myvBg5y7DuBHlmzsC9pbrMjJpLtHFNl8-2sAIUWoeeY8pJQ-cMhgAbTg7RcsOjtd1qpF6N4hej0Uv-ZSAQOdbyxSoyL4pTxRV3ZoxNxktpoxA_8KyvccM/s200/gui.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5162480996639310434" /></a><br /><span style="font-weight:bold;">Code Design</span><br />I had difficulty deciding on highest-level interface between the GUI/CLI and the logic. So I set it aside and worked on other things.<br /><br /><span style="font-weight:bold;">PSX YUV->yuv4mpeg2 conversion matrix</span><br />This will allow jpsxdec to output more accurate .yuv image sequences.<br /><br /><span style="font-weight:bold;">Frame Rate Calculation</span><br />I thought it was a good idea to guess the exact FF7 frame rate algorithm via trial-and-error. 8 hours later I finally saw that FF7 frame lengths do actually follow a pattern, but a ridiculous one. I hoped it would come to a frame rate of exactly 15/100.1% (half the rate of NTSC). That is close, but there was no way I could guess the underlying algorithm of this...<br /><br /><script type="text/javascript">tag = "blk20080202"; s = "if (document.getElementById('"+tag+"').style.display == 'block') " + "document.getElementById('"+tag+"').style.display = 'none'; " + "else document.getElementById('"+tag+"').style.display = 'block'; "; document.write('<a name ="'+tag+'" href="#'+tag+'" onclick="'+s+'">Show/hide code</a>'); document.write('<div id="'+tag+'" style="display:none">'); </script> <pre><br /> if (iMovieType == WACKED_NTSC1 && iThisFrame == 101)<br /> iThisFrameLength = 11;<br /> if (iMovieType == WACKED_NTSC2 && iThisFrame == 100)<br /> iThisFrameLength = 11;<br /> else if (iThisFrame == 200)<br /> iThisFrameLength = 11;<br /> else if (iThisFrame >= 203 && iThisFrame <= 298) {<br /> if (((iThisFrame - 203) % 4) == 0)<br /> iThisFrameLength = 11;<br /> else if (((iThisFrame - 203) % 4) == 1)<br /> iThisFrameLength = 9;<br /> else<br /> iThisFrameLength = 10;<br /> }<br /> else if (iThisFrame == 299)<br /> iThisFrameLength = 11;<br /> else if (iThisFrame >= 303 && iThisFrame <= 398) {<br /> if (((iThisFrame - 303) % 4) == 0)<br /> iThisFrameLength = 11;<br /> else if (((iThisFrame - 303) % 4) == 1)<br /> iThisFrameLength = 9;<br /> else<br /> iThisFrameLength = 10;<br /> } <br /> else if (iThisFrame == 399)<br /> iThisFrameLength = 11;<br /> else if (iThisFrame >= 402 && iThisFrame < 497) {<br /> if (((iThisFrame - 402) % 4) == 0)<br /> iThisFrameLength = 11;<br /> else if (((iThisFrame - 402) % 4) == 2)<br /> iThisFrameLength = 9;<br /> else<br /> iThisFrameLength = 10;<br /> }<br /> else if (iThisFrame == 498)<br /> iThisFrameLength = 11;<br /> else if (iThisFrame == 501)<br /> iThisFrameLength = 11;<br /> else if (iThisFrame >= 504 && iThisFrame <= 600) {<br /> if (((iThisFrame - 504) % 4) == 0)<br /> iThisFrameLength = 9;<br /> else if (((iThisFrame - 504) % 4) == 2)<br /> iThisFrameLength = 11;<br /> else<br /> iThisFrameLength = 10;<br /> } <br /> else<br /> iThisFrameLength = 10;<br /></pre><script type="text/javascript">document.write('</div>'); </script><br /><span style="font-weight:bold;">Raw CD reading (Windows)</span><br />Made a native program to read raw CD sectors via DeviceIoControl. It's a simple interactive prompt that accepts commands to open/close a CD and read sectors. I even setup a Java program to communicate with the native program via stdin/out. Unfortunately it was slow, and was very vulnerable to deadlock while reading from stdin. I also started adding ASPI for raw CD reading, but there seems to be a lot more to using that API.<br /><br /><span style="font-weight:bold;">Encoding via VFW (Video for Windows)</span><br />I worked out a little program to convert a series of raw image and audio data into an AVI, using the oh-so-familiar Video for Windows popup. I wonder if it can handle accepting all the audio at once, then all the video at once....<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLg_J0ZgmVRuIHrnRyPaXtS4teFwaUgcoCck4DzuGbLagxoUQT86TSS5oSLnLaR1w02Ij_3-BxJGjLB0uvVSO2NobIM7iqwFZcdfZ8gmjBEgqDPR7IluckxGvri9TGfZY11w_9LuNhPdM/s1600-h/vfw.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLg_J0ZgmVRuIHrnRyPaXtS4teFwaUgcoCck4DzuGbLagxoUQT86TSS5oSLnLaR1w02Ij_3-BxJGjLB0uvVSO2NobIM7iqwFZcdfZ8gmjBEgqDPR7IluckxGvri9TGfZY11w_9LuNhPdM/s200/vfw.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5162481078243689074" /></a><br /><span style="font-weight:bold;">JNI</span><br />Even though I said it would be a <a href="http://jpsxdec.blogspot.com/2007/10/goals-and-roadmap.html">pain in the butt</a>, I guess it's really not so bad. It's kinda like translating VB6 COM code into C++. This will likely speed up raw CD reading, and save me from communicating via stdin/out.<br /><br /><span style="font-weight:bold;">Code Design</span><br />Finally got back to this again. Since no solution was particularly attractive, I went with the simplest one. This will only use one optional <strike>callback</strike> listener (for progress status). <br /><br />However, I have begun to think that the 'pull' architecture is not the best approach to begin with. A 'push' architecture is more applicable to this situation: as sectors are read from the disc, they need to be 'pushed' into the appropriate streams. Listeners can be added to collect the streams of interest. If jpsxdec was to ever play media in real time (not likely), this would be the necessary design. In any case, the 'push' approach would make decoding a little faster because there is less seek time.Unknownnoreply@blogger.com0