Difference between revisions of "JPEG2000"

From Archivematica
Jump to navigation Jump to search
(JP2-MXF video)
(Reparent "more information")
Line 185: Line 185:
GStreamer seems ripe for someone to develop a custom, archives-oriented video conversion program. Any volunteers?
GStreamer seems ripe for someone to develop a custom, archives-oriented video conversion program. Any volunteers?
===More information===
==More information==
[http://www.digitalpreservation.gov/formats/fdd/fdd000143.shtml Library of Congress Sustainability of Digital Formats: JPEG 2000 Part 1 (Core) jp2 File Format]
[http://www.digitalpreservation.gov/formats/fdd/fdd000143.shtml Library of Congress Sustainability of Digital Formats: JPEG 2000 Part 1 (Core) jp2 File Format]

Revision as of 13:01, 23 March 2011

Main Page > Documentation > Media type preservation plans > JPEG2000

File extension(s)


Format registry information

None. Closest is PRONOM (JPX - JPEG 2000 Extended)

Significant characteristics

See Significant characteristics of raster images

Preservation action plan

See Raster images

Preservation issues

  • JPEG2000 image compression ranges from completely lossless to very lossy.
  • Florida digital Archive has "high confidence level" in ability to preserve losslessly compressed JP2 files: FDA Recommended Data File Formats.

Encoding JPEG2000-MXF video

Method one: OpenDCP

  • FFmpeg
  • OpenJPEG 1.4 ([1])
  • OpenDCP ([2])

This workflow is designed around digital cinema package (DCP) production. Most of the open-source tools are based around DCP since they're being designed by indie filmmakers.

OpenDCP is a utility for creating DCPs. The AS-DCP library and the mxflib library it's based on are possibilities for someone with more programming skills than me to build an archives-targeted tool.

The disadvantage to this route is that DCPs use separate files for audio and video, accompanied by an XML file describing the pair, which might make playback less convenient than a single AV MXF. The available tools are also targeted more to film framerates, and I'm not sure if it's possible to obtain a video FPS like 29.97 using unmodified tools.

Step 1: Decoding source video

The source video should be decoded into a series of single frames before being encoded into JPEG2000. This can be done using Ffmpeg.

ffmpeg -i invideo -vcodec tiff f%10d.tif

This will produce one file for every frame in the video. Why do we do this? Well, the various Motion JPEG2000 formats are essentially a series of single JPEG2000 files; each frame will be encoded to JPEG2000 before multiplexing into a video.

The audio should be decoded to uncompressed WAV. This is a simple process so I won't go into much detail here. The command should be a variant of

ffmpeg -i invideo outfile.wav

Step 2: Create JP2 frames

Next, these frames should be compressed into JPEG2000. Note that this will not be done using OpenJPEG's support for Motion JPEG2000! Motion JPEG2000 is a specific container for single JPEG2000 frames, while MXF wraps its frames in a different way. Technically, JPEG2000/MXF is considered a separate format.

image_to_j2k -ImgDir directory -OutFor j2c

This will create JP2 frames using the default lossless compression frames, but you may wish to customize this. Frames will be saved as .j2c files in the same directory as the TIFF frames.

Step 3: Create MXF file

opendcp_mxf -i image_directory -r framerate -o video.mxf

opendcp_mxf -i audio.wav -o audio.mxf

opendcp_xml --reel video.mxf audio.mxf

This will produce two MXFs, one containing video and one containing audio. The third command creates an accompanying XML file, mainly targeted at digital projectors.

Method two: GStreamer

GStreamer can encode to and from JPEG2000 MXF. By default it uses JasPer as the JP2 encoder, which has some limitations. I believe there may be a project underway to replace JasPer with OpenJPEG. GStreamer's commandline utility also has very inconvenient syntax; it's designed primarily to be used as a library to be called by custom programs. The gst-launch utility is mainly meant for debug purposes. For production would be best to write a custom archives-oriented converter based on Gstream rather than use the gst-launch utility.

The advantage to GStreamer is that it provides all of the required functionality, and can go straight from a source video to producing an output.

On the other hand, GStreamer currently uses JasPer for JP2 encoding. It may be better to use it in conjunction with an external JP2 encoder.


GStreamer ([3]) gst-plugins-bad

The GStreamer debug utility is based around a chain of smaller tools chained together. Here's a sample command which takes a video-only file, in QuickTime format with PNG video, and turns it into a JPEG2000 MXF:

gst-launch-0.10 filesrc location=video.mov ! qtdemux ! pngdec ! ffmpegcolorspace ! videoscale ! jp2kenc ! mxfmux ! filesink location=video.mxf

This goes through a series of steps to get from your source video to the encoded video. This example does:

  • filesrc location=video.mov : Tells gst-launch where to find the source


  • qtdemux : Demultiplexes the video. This means that it "opens" the

container and extracts the tracks inside it, making them available to the other GStreamer tools

  • pngdec : Decodes PNG compressed video into uncompressed video
  • ffmpegcolorspace : Interprets the colour space in the video. Necessary to

be able to pass it to other tools

  • videoscale : Negotiates the size of the video. When used with no

arguments, it just ensures the next tool knows what the size is

  • jp2kenc : Encodes the video stream to JPEG 2000. You can specify the

settings here if you want

  • mxfmux : Combines (multiplexes) the streams being processed into an MXF


  • filesink location=video.mxf : Saves the video to a "filesink", e.g. a

location on the hard drive

The exact commands will depend on the source video. You can also do a combined audio/video file, but the commands for that are kind of complex and, to be honest, I haven't quite gotten my head around it yet.

You can also decode and convert videos using GStreamer. Here's a sample command to convert the previous video to MPEG-4 with default settings:

gst-launch-0.10 filesrc location=video.mxf ! mxfdemux name=d d. ! jp2kdec ! ffmpegcolorspace ! videoscale ! ffenc_mpeg4 ! filesink location=video.mp4

Method three: GStreamer + OpenJPEG


GStreamer gstreamer-plugins-bad FFmpeg OpenJPEG

As I mentioned before, GStreamer's JP2 encoder isn't ideal right now. However, you can easily encode a video with another tool and wrap it into MXF using GStreamer.

First, extract your video to frames with ffmpeg as described above, then compress them to JP2 frames using the following command:

image_to_j2k -ImgDir directory -OutFor j2k

You should then wrap them into an MJ2 video using the following command:

wrap_j2k_in_mj2 directory video.mj2

This will produce a single MJ2 file using the frames you extracted. By default the framerate will be 25fps, which is probably wrong - consult the OpenJPEG documentation to find out how to set the framerate.

You can then open this video file using GStreamer and rewrap the frames into an MXF using a command like the following:

gst-launch-0.10 filesrc location=video.mj2 ! mj2demux ! mxfmux ! filesink location=video.mxf

This will produce an MXF with the contents as your video - no recompression or loss of quality. Hooray!

Areas for future work

GStreamer seems ripe for someone to develop a custom, archives-oriented video conversion program. Any volunteers?

More information

Library of Congress Sustainability of Digital Formats: JPEG 2000 Part 1 (Core) jp2 File Format