Ogg Theora Cook Book

Ogg File Concatenation

To concatenate two or more Ogg files with audio and video streams into a single video file without reencoding is easy, but can lead to the same synchronization problems as using oggCut.

The command line tool oggCat creates a new Ogg file from a number of other Ogg files.

Synopsis: oggCat outputFile.ogv inputfile1.ogv inputfile2.ogv [ inputfile3.ogv [ .. ] ]

To create an Ogg file, the parameters for all streams must match. If one or more parameters in an input file do not match, that file will be ignored, but the process of creating the output file will continue. The output file is a valid ogg file. It is just not the ogg file desired.

The Process

oggCat reads in the first file mostly as it is. However, it does not handle any unkown streams and does not integrate them into the output file.

To find a corresponding stream within the succeeding Ogg files, oggCat creates a parameter table with all necessary information about the streams of the first file (inputfile1.ogv), so that the first file serves as a "reference".

The streams in the following files (inputfile2.ogv inputfile3.ogv ...) are tested against the parameters of the reference table, so they do not have to be in the same order as the reference file.

Example:

The first Ogg file consists of one theora and one vorbis stream. The theora stream video has a frame size of 320x240 pixel and the vorbis audio stream has a sample rate of 32 kHz.

The next file consists of three streams: two theora streams and one vorbis stream. oggCat can handle the concatenation as long as there is at least one theora stream available with matching parameters (320x240 pixel framesize) and the audio stream parameter matches, too. The second theora stream can have whatever parameters.

If there are no matching parameters in any of the streams, oggCat prints a line suggesting how the file might be reencoded:

vorbis parameter compare: data rate not matching 32000 != 64000
You may try to reencode with the datarate of the other file

Please try to resample with the following command
oggResize -D 32000 <file see below>

Using cat

Another way to concatenate two videos is by adding one file after another with the command line tool cat. This method triggers the player to setup a new decoding session for the next stream.

The Ogg Standard allows opening a stream after another stream has ended, but most players do not implement this method of re-opening a decoder session. Therefore this method should always be tested with the players that should be used after this session.

oggCat and oggz-chop

When a file has been created with oggz-chop, concatenation is not possible because of the way oggCat works.

The reason is that files with a skeleton and different time offsets defined in this skeleton for every stream (as is the case for most files created with oggz-chop) can not be concatenated to one continuous stream. This behavior is caused by the fact that two ogg streams would overlap. The presented frames would overlap the ones that are not presented, as they are only needed for the decoding of the first video frame. This is not possibile in one Ogg stream.

Syncronizing issues with oggCat

Different streams in one Ogg file may not have the (exact) same length. During the concatenation process the streams of the next Ogg file in the concatenation list are placed directly after the corresponding streams of the starting file without any time gaps. Therefore synchronization of the second file will suffer from an inaccurate stream ending of the first file.