June 3, 2008

Manage Ogg audio streams with OGMtools

Author: Chad Files

When I make videos, 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 utilities to manage Ogg Media Stream (OGM) files. The tools were designed to be used along with video ripping software to encode DVD movies, but they can be used for much more.

ogminfo lets you obtain information about a particular Ogg file. A command like ogminfo -s audio.ogg prints a complete summary of an audio file, including file size, bitrate, number of packets, and the play length, which instantly tells me how much video I need to cut to make the audio match the video clip I am working on. The tool can also provide more information about a particular file if you set the verbosity level using the -v option.

ogmcat is useful for taking short snippets of narration audio and combining them into longer streams, and for looping background audio. For example, the command ogmcat -o audio.ogg track1.ogg track2.ogg track3.ogg combines track1, track2, and track3 end-to-end and writes the resulting stream to audio.ogg.

ogmcat uses a strict matching algorithm to merge audio files to ensure that all of the audio sounds correct when merged. For a full list of what ogmcat checks, refer to the limitations section of the man page. If all of the files were created the same way using the same software there should not be an issue. If there is an issue, ogmcat will throw an error and the merge will fail. You can override some of the lesser checks by using the -n option.

To loop audio files, use a single input file multiple times: ogmcat -o audio.ogg track.ogg track.ogg track.ogg

Merge and split Ogg audio tracks

When I do screencasts I typically use recordmydesktop to record the screen capture, then narrate the actions using Audacity. I then have to get my Ogg Vorbis audio track to visually sync with the Ogg Theora video file. To put the two together, I convert the Theora video to xvid, because OGMtools does not support Ogg Theora, then use ogmmerge to put them together, with a command like ogmmerge -o final.ogm -A video.avi audio.ogg. The -A option tells ogmmerge to not include any audio from the video file.

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. I use shell scripts that automate the process and make doing all of the conversions trivial.

The converse of ogmmerge is ogmsplit, which can be used to divide an OGM into smaller chunks based on time or file size. For example, ogmspit -t 300 -o split.ogg video.ogg will divide video.ogg into separate files, one 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 command ogmspit -s 50MiB -o split.ogg video.ogg will split video.ogg once for every 50 megabytes.

ogmdemux can extract streams in an OGM file. This is handy for separating audio and video streams into separate files. The command ogmdemux -o video -na video.ogm extracts the video stream from video.ogm and writes it to a file named video-v1.avi; the -na (no audio) option tells ogmdemux to extract only 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 command ogmdemux -o audio -nv video.ogm extracts only the audio from the full video and writes it to a file called audio-v1.ogg.

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 its man page.

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


  • Tools & Utilities
  • Graphics & Multimedia
Click Here!