Difference between revisions of "Video"

From Archivematica
Jump to navigation Jump to search
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Main Page]] > [[Documentation]] > [[Media type preservation plans]] > Video
+
[[Main Page]] > [[Documentation]] > [[Format policies]] > Video
  
  
==[[Significant properties of video files]]==
+
==[[Significant characteristics of video files]]==
  
 
==Preservation Format==
 
==Preservation Format==
MPEG-2
+
*FFV1/PCM in Matroska wrapper (MKV) (Archivematica 0.7.1 and later)
 +
*MPEG-2/PCM in Material eXchange Format wrapper (MXF) (Archivematica 0.7 and earlier)
  
 
==Access Format==
 
==Access Format==
OGG
+
MPEG-1/MP2
  
 
==Normalization tool==
 
==Normalization tool==
Line 14: Line 15:
  
 
==Comments==
 
==Comments==
*Video stream will be converted to MPEG-2 with Intra-coded (I) frames; audio stream will be converted to LPCM with a bit depth of 16 bits and a sampling frequency of 48000 HZ; wrapper format is MXF (Material Exchange Format).
+
 
 +
===FFV1/MKV===
 +
*FFv1 is a completely lossless video codec. For a comparison of lossless codecs, see [http://compression.ru/video/codec_comparison/lossless_codecs_2007_en.html|Lossless Video Codecs Comparison ‘2007].
 +
*Matroska (pronounced maTROSHka) is an open standard free video container format which can hold a large number of video and audio codecs. See http://www.matroska.org/.
 +
 
 +
===Other containers and codecs===
 
*According to Library of Congress, "For file-based compressed video, conform to or approximate MPEG-2_422 (4:2:2 Profile) at Main Level (aka MPEG-2 422@ML) or MPEG-2_MP (Main Profile) at Main Level (aka MPEG-2 MP@ML). Uncompressed or losslessly compressed copies are preferred to compressed (for future development)." [http://www.digitalpreservation.gov/formats/fdd/fdd000028.shtml Library of Congress Sustainability of Digital Formats: MPEG-2 Video Encoding (H.262)]
 
*According to Library of Congress, "For file-based compressed video, conform to or approximate MPEG-2_422 (4:2:2 Profile) at Main Level (aka MPEG-2 422@ML) or MPEG-2_MP (Main Profile) at Main Level (aka MPEG-2 MP@ML). Uncompressed or losslessly compressed copies are preferred to compressed (for future development)." [http://www.digitalpreservation.gov/formats/fdd/fdd000028.shtml Library of Congress Sustainability of Digital Formats: MPEG-2 Video Encoding (H.262)]
*Video stream preservation issues:
+
*For preservation of audio streams, WAV PCM or WAV BWF are preferred formats and AIFF is acceptable. See [http://www.carli.illinois.edu/mem-prod/contentdm/guidelines_for_audio.pdf Guidelines for the Creation of Digital Collections: Digitization Best Practices for Audio, Consortium of Academic and Research Libraries in Illinois, 2009], p. 2.
**From [http://www.media-matters.net/docs/WhitePapers/WPMJ2k.pdf Lossless Video Compression for Archives: Motion JPEG2k and Other Options,             Ian Gilmour, National Film and Sound Archive, Australia, R. Justin Dávila, System Architect and Technology Consultant, Media Matters LLC, date unknown]: "Archivists have a short list from which to select a digital archival file format for a modern, 21st Century migration project. Such an archival file should have the requirement of being both lossless to preserve content and also compressed to conserve storage capacity. The leading candidate for such a file format is Motion JPEG 2000. Two complementary image compression schemes are in widespread use: JPEG and MPEG, along with some other, less standardized options. The original JPEG has been used for many years in compressing full color images. JPEG-2000 uses wavelet compression as adopted for the Digital Cinema Initiative (DCI), and enables true lossless compression. MPEG-4 is being adopted rapidly for transmission of audio, video and other data at lower bit-rates for similar quality compared to previous MPEG standards. MPEG-4 part 10 Advanced Video Coding, also known as ITU H.264 typically achieves file sizes and data rates half the rates used in MPEG-2. For MPEG-4, in two very specific instances, known as PCM-I, and Transform bypass, the MPEG-4 toolset allows for lossless encoding of finite picture regions or macroblocks. However, when taken as a whole, the MPEG-4 tool set is not designed to support lossless encoding of entire picture sequences, with any significant degree of data reduction. JPEG-2000 is a technically better solution for this requirement." (p.1)
+
*More information
**[http://www.danceheritage.org/preservation/DigitalVideoPreservation1.pdf Digital Video Preservation Reformatting Project,Prepared by Media Matters, LLC for the Dance Heritage Coalition, Presented to The Andrew W. Mellon Foundation, June 2004] recommends JPEG 2000 encoding in an MXF container for long-term preservation of video files. (p.99)
+
**More information on the Material Exchange Format (MXF) is available at [http://www.digitalpreservation.gov/formats/fdd/fdd000013.shtml Library of Congress Sustainability of Digital Formats: MXF]
*Audio stream preservation issues:
+
**[http://www.danceheritage.org/preservation/DigitalVideoPreservation1.pdf Digital Video Preservation Reformatting Project,Prepared by Media Matters, LLC for the Dance Heritage Coalition, Presented to The Andrew W. Mellon Foundation, June 2004]
**For preservation of audio streams, WAV PCM or WAV BWF are preferred formats and AIFF is acceptable. See [http://www.carli.illinois.edu/mem-prod/contentdm/guidelines_for_audio.pdf Guidelines for the Creation of Digital Collections: Digitization Best Practices for Audio, Consortium of Academic and Research Libraries in Illinois, 2009], p. 2.
+
**[http://www.ahds.ac.uk/preservation/video-preservation-handbook.pdf Arts and Humanities Data Service Preservation Handbook: Moving Image, Gareth Night, 2005]
 +
**[http://www.prestoprime.org/docs/training/P1-Wright-Vienna2009-10.pdf WP2 - Preservation Strategies, Richard Wright, PrestoPRIME WP2 BBC Research & Development, UK, 2009]
 +
**[http://www.avpreserve.com/wp-content/uploads/2010/04/AVPS_Codec_Primer.pdf A Primer on Codecs for Moving Image and Sound Archives: 10 Recommendations for Codec Selection and Management. Chris Lacinak, AudioVisual Preservation Solutions. 2010]
 +
 
 +
===Motion JPEG 2000===
 +
*Motion JPEG 2000 (MJPEG2K) is emerging as a preferred format for video files. See for example:
 +
**[http://standards-catalogue.ukoln.ac.uk/index/MJ2 UKOLN Multimedia standards: MJ2]
 +
**[http://www.media-matters.net/docs/WhitePapers/WPMJ2k.pdf Lossless Video Compression for Archives: Motion JPEG2k and Other Options, Ian Gilmour, National Film and Sound Archive, Australia, R. Justin Dávila, System Architect and Technology Consultant, Media Matters LLC, date unknown]
 +
 
 +
 
 +
==Encoding JPEG2000-MXF video (Added by Misty de Meo) ==
 +
 
 +
===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 [http://www.cinecert.com/asdcplib/ AS-DCP library] and the [http://sourceforge.net/projects/mxflib/ 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.
 +
 
 +
<code>ffmpeg -i invideo -vcodec tiff f%10d.tif</code>
 +
 
 +
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
 +
 
 +
<code>ffmpeg -i invideo outfile.wav</code>
 +
 
 +
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.
 +
 
 +
<code>image_to_j2k -ImgDir directory -OutFor j2c</code>
 +
 
 +
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
 +
 
 +
<code>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</code>
 +
 
 +
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:
 +
 
 +
<code>gst-launch-0.10 filesrc location=video.mov ! qtdemux ! pngdec !
 +
ffmpegcolorspace ! videoscale ! jp2kenc ! mxfmux ! filesink
 +
location=video.mxf</code>
 +
 
 +
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:
 +
 
 +
<code>gst-launch-0.10 filesrc location=video.mxf ! mxfdemux name=d d. !
 +
jp2kdec ! ffmpegcolorspace ! videoscale ! ffenc_mpeg4 ! filesink
 +
location=video.mp4</code>
 +
 
 +
===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:
 +
 
 +
<code>image_to_j2k -ImgDir directory -OutFor j2k</code>
 +
 
 +
You should then wrap them into an MJ2 video using the following command:
 +
 
 +
<code>wrap_j2k_in_mj2 directory video.mj2</code>
 +
 
 +
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:
 +
 
 +
<code>gst-launch-0.10 filesrc location=video.mj2 ! mj2demux ! mxfmux ! filesink
 +
location=video.mxf</code>
 +
 
 +
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?
  
  
 
__NOTOC__
 
__NOTOC__

Latest revision as of 15:17, 13 February 2013

Main Page > Documentation > Format policies > Video


Significant characteristics of video files[edit]

Preservation Format[edit]

  • FFV1/PCM in Matroska wrapper (MKV) (Archivematica 0.7.1 and later)
  • MPEG-2/PCM in Material eXchange Format wrapper (MXF) (Archivematica 0.7 and earlier)

Access Format[edit]

MPEG-1/MP2

Normalization tool[edit]

FFmpeg

Comments[edit]

FFV1/MKV[edit]

  • FFv1 is a completely lossless video codec. For a comparison of lossless codecs, see Video Codecs Comparison ‘2007.
  • Matroska (pronounced maTROSHka) is an open standard free video container format which can hold a large number of video and audio codecs. See http://www.matroska.org/.

Other containers and codecs[edit]

Motion JPEG 2000[edit]


Encoding JPEG2000-MXF video (Added by Misty de Meo)[edit]

Method one: OpenDCP[edit]

  • 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[edit]

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 ([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 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[edit]

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!

Areas for future work[edit]

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