Manage OGG Streams with OGMtools

Author Note: This was originally posted on in 2008. I am replicating it here for posterity.

When I make videos I usually find myself in a position where I need to add narration and/or background music. Whatever the case, I almost always use ogg to encode the audio. Storing the audio in ogg saves space on my machine without sacrificing quality. However, I invariably need to loop, concatenate, or change the audio in some way, which can be difficult. For many of these tasks I turn to the OGMtools suite to make the process easier.

The OGMtools suite contains several different utilities to manage ogg files. The tools were designed to use along with video ripping software to encode DVD movies, but they can be used for much more.

Obtain ogg Stream Information with ogminfo

ogminfo is useful for obtaining information about a particular ogg file.

ogminfo -s audio.ogg

This command will print a complete summary of the audio file including file size, bitrate, number of packets, and the play length. The length is the most important attribute to me; it instantly tells me how much video I need to cut to make the audio match the video clip I am working on.

The tool will also provide more information about a particular file by setting the verbosity level using the -v option.

Concatenating ogg Audio Files with ogmcat

Of all the OGMtools I use ogmcat the most. It is useful for taking short snippets of narration audio and combining them into longer streams. It is also useful for looping background audio.

ogmcat -o audio.ogg track1.ogg track2.ogg track3.ogg

This command will combine track1, track2, and track3 end to end and write the resulting stream to audio.ogg. Please note that ogmcat uses a strict matching algorithm to merge audio files. The matching ensures that all of the audio will sound correctly when merged. If all of the files were created the same way using the same software there should not be an issue.

Like I said before, I also use ogmcat to loop audio files. This works the same way the previous example did with one exception — instead of providing multiple input files I use the same one multiple times.

ogmcat -o audio.ogg track.ogg track.ogg track.ogg

Merge ogg Audio Tracks with ogmmerge

When I do screencasts I typically use recordmydesktop. An issue that I always run into is getting the audio to visually sync with the video. To resolve the issue I record the screen capture first then narrate the actions using Audacity. The result is an ogg theora video file from recordmydesktop and an ogg vorbis audio file from audacity. To put the two together I convert the theora video to xvid then use ogmmerge to put them together. For whatever strange reason OGMtools does not support ogg theora.

ogmmerge -o final.ogm -A video.avi audio.ogg

This command combines the audio and video streams into an ogg file named final.ogm. The -A option is important, it tells ogmmerge to not include any audio from the video file. By default recordmydesktop captures audio when it runs. The -A options keeps the unwanted audio out of the final product.

After creating the merged file I typically use ffmpeg to convert the file to DV Digital Video so that I can use it with Kino. However, if the project I am working on is all screen captures and does not need further editing, I just use ogmcat to pull all of the segments together.

This may seem like a lot of work but it really isn’t. I have shell scripts that automate the process. They make doing all of the conversions trivial.

Split OGM files with ogmsplit

ogmsplit is another tool in the suite that can be used to divide an OGM (Ogg Media Stream) into smaller chunks. It will divide files based on time or file size.

ogmspit -t 300 -o split.ogg video.ogg

This command will divide video.ogg into separate files, once for every 300 seconds of content. The output files will be named split-XXXXX.ogg, where XXXXX is a zero padded sequential number starting at 1.

Similarly, the following command will split video.ogg once for every 50 megabytes.

ogmspit -s 50MiB -o split.ogg video.ogg

Separating Streams with ogmdemux

Another tool is ogmdemux; this tool has the capacity to extract streams in an ogm file. This is handy for separating audio and video streams into separate files.

ogmdemux -o video -na video.ogm

This command extracts the video stream from video.ogm and writes it to a file named video-v1.avi; the -na (no audio) option is what tells ogmdemux to only extract the video. The file name is determined by what options are used; specifying the -o option just gives the output file a base name

Similarly, the following command extracts only the audio from the full video and writes it to a file called audio-v1.ogg.

ogmdemux -o audio -nv video.ogm

It is also possible to define the exact audio, video, or text stream to extract. The default is always the first one. For more information on this tool visit it’s man page.

As you can see, even though the OGMtools were designed to be used in a video ripping and encoding stack they have many more uses.