Encoding JPEG2000-MXF using open-source tools

4,211 views
Skip to first unread message

Misty De Meo

unread,
Mar 22, 2011, 5:31:57 PM3/22/11
to archiv...@googlegroups.com
I've been doing some experimenting with open-source tools to create
JPEG2000-encoded MXF video files. I know this is something other people
have been having trouble with, so I thought I'd share my findings.

I've been working on Mac OS X, but the tools should also be compatible
with Linux and might work in Windows. I've found a few different paths to
doing this. There isn't necessarily an ideal start-to-finish workflow yet,
but the tools seem to be there to allow one to be scripted or programmed.


Method one: OpenDCP

- FFmpeg
- OpenJPEG 1.4 (http://www.openjpeg.org/)
- OpenDCP (http://code.google.com/p/opendcp/)


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
(http://www.cinecert.com/asdcplib/) and the mxflib library
(http://sourceforge.net/projects/mxflib/) 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, I believe 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.

Requirements:

GStreamer (http://gstreamer.freedesktop.org)
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
video
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
container
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

Requirements:

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!

---

Obviously there's a lot of room to improve on this and discuss more, but
this e-mail is long enough already so I'll leave it to be discussed in the
future. I'll be wikifying the info from here, but I'd love to see more
discussion on the mailing list. And if anyone here happens to be more of a
coder than I am - GStreamer's just begging to be built on to make a real
archives video-to-MXF/JP2 converter. Just saying!

Misty

Misty De Meo
Digital Collections Technician | Technicienne des collections numériques
Canadian Museum for Human Rights | Musée canadien des droits de la personne
E-mail / Courriel: misty....@humanrightsmuseum.ca
269 rue Main Street
Winnipeg, MB
R3C 1B3

Manojlovich, Slavko

unread,
Mar 23, 2011, 8:29:02 AM3/23/11
to archiv...@googlegroups.com
Thanks for the excellant summary of the alternatives for encoding JPEG2000-MXF. We will try out GStreamer and report back to the list.

Slavko Manojlovich
Manager, Digital Archives Initiative
Memorial University of Newfoundland

________________________________


Method one: OpenDCP

ffmpeg -i invideo outfile.wav

opendcp_xml --reel video.mxf audio.mxf

Method two: GStreamer

Requirements:

GStreamer (http://gstreamer.freedesktop.org <http://gstreamer.freedesktop.org/> )
gst-plugins-bad

Requirements:

GStreamer
gstreamer-plugins-bad
FFmpeg
OpenJPEG

wrap_j2k_in_mj2 directory video.mj2

---

Misty

--
You received this message because you are subscribed to the Google Groups "archivematica" group.
To post to this group, send email to archiv...@googlegroups.com.
To unsubscribe from this group, send email to archivematic...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/archivematica?hl=en.

winmail.dat

Evelyn McLellan

unread,
Mar 23, 2011, 2:06:46 PM3/23/11
to archivematica
Hi Misty,

Thanks for posting all this detail to the discussion list. We are very
interested in trying this, and also look forward to Slavko's test
results.

Evelyn McLellan
Systems Archivist
Artefactual Systems Inc.
> E-mail / Courriel: misty.de....@humanrightsmuseum.ca
> 269 rue Main Street
> Winnipeg, MB
> R3C 1B3
>
> --
> You received this message because you are subscribed to the Google Groups "archivematica" group.
> To post to this group, send email to archiv...@googlegroups.com.
> To unsubscribe from this group, send email to archivematic...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/archivematica?hl=en.
>
>  winmail.dat
> 12KViewDownload
Reply all
Reply to author
Forward
0 new messages