Monday, March 7, 2011

lossless video codec playback in Java

I need to encode a sequence of frames with a lossless video codec and play them in a Java app. I don't care about the file size. The output frames should match the input frames exactly. Lossy codecs don't do this even at high bit rates.

None of these well-known lossless video codecs appear to be supported in JMF or FMJ:

  • HuffYUV
  • CorePNG
  • Lagarith
  • FFV1
  • ...

Do you know of any lossless video codec that is supported in Java?

Other options I've considered:

  • animated GIF: is the playback guaranteed to have a constant frame rate like real video codecs?
  • load and display the separate frames: how difficult will it be to do this at a constant frame rate and without dropping too many frames?
  • Proce55ing: the video playback library requires Quicktime, which isn't available on my platform.

EDIT: I finally decided to settle for JMF's (non-standard) MotionJPEG at highest quality. It's not strictly lossless, but still much better quality than MPEG4.

From stackoverflow
  • Well, since you say file-size is not an issue, gzip/bzip2 can be a quick and painless option. It won't give maximum compression, but it can be the last recourse if you fail to find a better answer.

    Gzipped files can be transparently opened using java.util.zip.GZIPInputStream, and similar interfaces are available for Bzip2.

    palm3D : That's basically a variation of the "load and display the separate frames" option. I'm worried it won't be fast enough even without the compression.
    ePharaoh : Why would that option be slower? I can only think of i/o becoming a bottleneck, depending on specifics like resolution of the video. CPU won't be a bottleneck because you are reducing its work by giving it ready to use data. PS. I have implemented a video decoder (MPEG4 FGS) once.
    palm3D : I tried something similar: I can read uncompressed BMP files at a decent rate, but not PNG files because they need some decoding. So the bottleneck seems to be decoding/decompression, not I/O.
  • FMJ does support an experimental method of storing/playing a series of PNG images much the way MJPEG is a series of JPEG images. One is an experimental XML file format which uuencodes the PNGs (fairly bloated), and the other is the x-multipart-mixed-replace HTTP format, which FMJ supports in a file format ending with the extension .mmr

    palm3D : The README says movie playback is not yet implemented on Linux. :-(
    • Animated GIFs: yes, you can define the framerate of animated GIFs (actually you can set a delay for each single frame)

    • displaying frames manually: depends on the hardware, frame rate and size of the images. An HD resolution at 30fps will be difficult without hardware support, thumbnail size shouldn't be a problem on any platform.

    • Another alternative: depending on what you want to do, you could consider to 'remote-control' another player or framework, possibly with some native code. For example, embed an mplayer on *nix/X11, or use COM to control WMP or DirectShow on Windows.

0 comments:

Post a Comment