jPSXdec is a cross-platform PlayStation 1 media decoder/converter.
Get the latest version here.

Wednesday, September 24, 2008

How to encode quality PlayStation 1 video

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.

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.

So here is how you do it, broken down into 6 ridiculously complicated steps.

  1. Convert your video into 4:2:0 yuv4mpeg2, but using the PSX specific rgb->yuv conversion.
  2. 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).
  3. Parse the I-frames out of the movie and parse their macro-blocks
  4. Convert the mpeg1 VLCs to PSX VLCs
  5. Do this for every mpeg1 quality and pick the one that fits best within the amount of space available to the frame
  6. Multiplex the frames and construct all the sectors

If the new video is mostly just the old video with some changes (e.g. subtitles) then quality can improved tremendously with this variation.

  1. 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)
  2. Only replace those macro blocks with new ones of the same qscale
  3. 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
  4. Multiplex the frames and construct all the sectors

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).