OGMMERGE(1)

NAME
ogmmerge - Merge multimedia streams into an OGG/OGM file

SYNOPSIS
ogmmerge [global options] -o out [options] <file1> [[options] <file2> ...]

DESCRIPTION

This program takes the input from several media files and joins their streams (all of them or just a selection) into an OGM. It was formerly known as 'oggmerge' and is based on the 'oggmerge' CVS module from Xiph's repository (<http://www.xiph.org/>). (http://www.xiph.org/)

Global options:

-v, --verbose
    Increase verbosity.

-q, --quiet
    Suppress status output.

-o, --output out
    Write to the file 'out'.

Options that can be used for each input file:

-a, --astreams <n,m,...>
    Copy the n'th audio stream, NOT the stream with the serial no. n. Default: copy all audio streams.

-d, --vstreams <n,m,...>
    Copy the n'th video stream, NOT the stream with the serial no. n. Default: copy all video streams.

-t, --tstreams <n,m,...>
    Copy the n'th text stream, NOT the stream with the serial no. n. Default: copy all text streams.

-A, --noaudio
    Don't copy any audio stream from this file.

-D, --novideo
    Don't copy any video stream from this file.

-T, --notext
    Don't copy any text stream from this file.

-s, --sync <d[,o[/p]]>
    Synchronize manually, delay the audio stream by d ms.
    d > 0: Pad with silent samples.
    d < 0: Remove samples from the beginning.
    o/p: adjust the timestamps by o/p to fix linear drifts. p defaults to 1000 if omitted. Both o and p can be floating point numbers.
    Defaults: no manual synch correction (which is the same as d = 0 and o/p = 1.0).

-r, --range <start-end>
    Only process from start to end. Both values take the form 'HH:MM:SS.mmm' or 'SS.mmm', e.g. '00:01:00.500' or '60.500'. If one of start or end is omitted then it defaults to 0 or to end of the file respectively.
    If you want to split a file into smaller ones I strongly suggest you use ogmsplit(1) as it can do a much better job than using the -r option.

-c, --comment 'A=B#C=D' or '@filename'
    Set additional comment fields for the streams. Sensitive values would be 'LANGUAGE=English' or 'TITLE=Ally McBeal'. If the parameter starts with '@' then the comments will be read from a file with the same name without the leading '@'. -c can be specified multiple times per file. The comments will all be concatenated.

-f, --fourcc <FourCC>
    Forces the FourCC to the specified value. Works only for video streams. Note that you cannot simply use a hex editor and change the FourCC by hand as the OGG file format uses checksums which would be wrong after such a change.

--omit-empty-packets
    Normally, when a subtitle entry should be removed, an empty packet is created and inserted with the appropriate timestamp. With this option these empty packets are omitted completely.

--old-headers
    Assume that the input file has been created with an older version of ogmmerge ( < 1.1). This may be needed if ogmmerge cannot read such a file correctly.

--nav-seek <filename>
    Use an external AVI index file as generated by aviindex from the transcode package. Can be used if an AVI file has a broken index.

Other options:

-l, --list-types
    List supported input file types.

-h, --help
    Show usage information.

-V, --version
    Show version information.

USAGE

For each file the user can select which tracks ogmmerge should take. They are all put into the file specified with '-o'. A list of known (and supported) source formats can be obtained with the '-l' option.

EXAMPLES

Let's assume you have a file called MyMovie.avi and the audio track in a separate file, e.g. MyMovie.wav. First you want to encode the audio to OGG:

$ oggenc -q4 -oMyMovie.ogg MyMovie.wav

After a couple of minutes you can join video and audio:

$ ogmmerge -o MyMovie-with-sound.ogm MyMovie.avi MyMovie.ogg

If your AVI already contains an audio track then it will be copied aswell (if ogmmerge supports the audio format). To avoid that simply do

$ ogmmerge -o MyMovie-with-sound.ogm -A MyMovie.avi MyMovie.ogg

After some minutes of consideration you rip another audio track, e.g. the director's comments or another language to MyMovie-add-audio.wav. Encode it again and join it up with the other file:

$ oggenc -q4 -oMyMovie-add-audio.ogg MyMovie-add-audio.wav
$ ogmmerge -o MM-complete.ogm MyMovie-with-sound.ogm MyMovie-add-audio.ogg

The same result can be achieved with

$ ogmmerge -o MM-complete.ogm -A MyMovie.avi MyMovie.ogg \
  MyMovie-add-audio.ogg

Now fire up mplayer and enjoy. If you have multiple audio tracks (or even video tracks) then you can tell mplayer which track to play with the '-vid' and '-aid' parameters. These are 0-based and do not distinguish between video and audio.

If you need an audio track synchronized you can do that easily with

$ ogmmerge -o goodsync.ogm -A source.avi -s 200 outofsync.ogg

This would add 200ms of silence at the beginning of the audio tracks taken from outofsync.ogg. And -s always applies to all audio tracks in a source file. If you want to apply -s only to a specific track then take the same source file more than once and add -a and -s accordingly.

Some movies start synced correctly but slowly drift out of sync. For these kind of movies you can specify a delay factor that is applied to all timestamps - no data is added or removed. So if you make that factor too big or too small you'll get bad results. An example is that an episode I transcoded was 0.2 seconds out of sync at the end of the movie which was 77340 frames long. At 29.97fps 0.2 seconds correspond to approx. 6 frames. So I did

$ ogmmerge -o goodsync.ogm -s 0,77346/77340 outofsync.ogm

The result was fine.

The sync options can also be used for subtitles in the same manner.

For text subtitles you can either use some Windows software (like SubRipper) or the subrip package found in transcode(1)'s sources (in contrib/subrip). The general process is:

1.  extract a raw subtitle stream from the source:
    $ tccat -i /path/to/copied/dvd/ -T 1 -L | \
        tcextract -x ps1 -t vob -a 0x20 | \
        subtitle2pgm -o mymovie

2.  convert the resulting PGM images to text with gocr:
    $ pgm2txt mymovie

3.  spell-check the resulting text files:
    $ ispell -d american *txt

4.  convert the text files to a SRT file:
    $ srttool -s -w -i mymovie.srtx -o mymovie.srt

The resulting file can be used as another input file for ogmmerge:

$ ogmmerge -o mymovie.ogm -c 'TITLE=My Movie' mymovie.avi \
    -c LANGUAGE=English mymovie.ogg -c LANGUAGE=English mymovie.srt

FILE SIZE

Using OGG as the container format introduces overhead - each OGG packet has a header, and each OGG packet can span one or more OGG pages, which itself again contain headers. Several tests show that the overhead is bigger than the overhead introduced by AVI (comparing video only files and files with video and MP3 audio).

The overhead is defined as file size - raw stream size. mencoder prints the raw stream size after encoding, so you'll be able to get that information rather easily.

Most of the times you want to calculate the overhead prior to encoding in order to adjust the bitrate accordingly. Unfortunately the overhead per frame is not constant - only the percentage is constant. This percentage is calculated as 100 * (OGG size - raw size) / raw size and seems to be somewhere between 1.1% and 1.2%. This depends on the number of streams and the stream types used.

The raw size itself can be approximated by
             frames * vbitrate
raw size = ( ----------------- + length * abitrate ) / 8 * 1000 * 1024
              frames per sec
assuming that vbitrate and abitrate are given in kbit/s = 1000 bit/s, and length is given in seconds.

NOTES

What works:

*   AVI as the video and audio source (currently only raw PCM, MP3 and AC3 audio tracks)

*   OGG as the source for video, audio (Vorbis, raw PCM, MP3 and AC3 audio) and text streams (subtitles).

*   WAV as the audio source

*   MP3 audio files

*   AC3 audio files

*   Track selection

*   Manual audio synchronization by adding silence/removing packets for Vorbis audio and for text streams by adjusting the starting point and duration.

*   Manual audio synchronization for AC3 and MP3 audio by duplicating/removing packets at the beginning.

*   Adding user comments to the mandatory comment headers (only the headers are mandatory. Comments themselves are not mandatory.)

*   Text subtitles can be read from SRT (SubRipper / subrip) and MicroDVD files or taken from other OGM files.

*   PCM, AC3 and MP3 audio work well under Windows and with MPlayer now.

*   Chapter information as generated by dvdxchap are supported.

What not works:

*   Manual audio synchronization for PCM sound (who needs it anyway?)

Planned functionality:

*   support for other subtitle formats

CHAPTERS
ogmmerge supports chapter information as generated by dvdxchap(1). The format is very simple:

CHAPTER01=HH:MM:SS.sss
CHAPTER01NAME=the first chapter
CHAPTER02=HH:MM:SS.sss
CHAPTER02NAME=another chapter

with HH = hour, MM = minute, SS = seconds, sss = milliseconds.

The chapter information is stored in the video stream's comments. Therefore you could also specify the chapters with -c CHAPTER01=... Using a chapter file has an advantage: If the video stream's comments already contain chapter information and the command line contains a chapter information file then the existing chapter information will be completely replaced.

TECHNICAL ASPECTS

This section is not needed by the average user.

ogmmerge consists of three parts:

*   Demultiplexers (called readers) open and read input files specified on the command line and extract specific tracks.

*   Packetizers (or output modules) take data from a demultiplexer and encapsulate them into OGG pages. These are stored in queues.

*   The main program requests from every known demultiplexer that it should read some data. It then gets the OGG page with the smallest timestamp from all the packetizer queues. This page is written to the output file.

The general class definitions for the readers and the packetizers can be found in ogmmerge.h.

The main loop expects that the queues managed by the demuxer's packetizers are filled with at least one page after a call to the demuxer's read() function. The demuxer must make sure that enough data is passed to each of its associated packetizers. Have a look at r_ogm.cpp.

A possible setup might look like this:

                        +-> p_video
           +-> r_avi -+
           | +-> p_pcm
           |
ogmmerge -+-> r_ogm ---> p_vorbis
           |
           | +-> p_video
           | |
           +-> r_ogm -+-> p_vorbis
                        |
                        +-> p_vorbis

One AVI source with a video and an audio track, one OGG/OGM source with only one Vorbis track, another OGG/OGM source with a video and two Vorbis tracks.

AUTHOR
ogmmerge was written by Moritz Bunkus <moritz@bunkus.org>.

SEE ALSO
ogmdemux(1), ogmsplit(1), ogminfo(1), ogmcat(1), dvdxchap(1)

WWW
The newest version can always be found at <http://www.bunkus.org/videotools/ogmtools/> (http://www.bunkus.org/videotools/ogmtools/)