Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to move the Vorbis stream into an ogg container but ffmpeg does not seem to recognize the stream.

Even though MPlayer gives this output upon playback:

Opening audio decoder: [acm] Win32/ACM decoders
Loading codec DLL: 'vorbis.acm'
Loaded DLL driver vorbis.acm at 10000000
Warning! ACM codec reports srcsize=0
AUDIO: 44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000->176400)
Selected audio codec: [vorbisacm] afm: acm (OggVorbis ACM)


ffmpeg -i Source.wav -acodec copy Target.ogg
Input #0, wav, from 'Source.wav':
  Duration: 00:02:15.17, bitrate: 128 kb/s
    Stream #0.0: Audio: qg[0][0] / 0x6771, 44100 Hz, 2 channels, 128 kb/s
[ogg @ 00000000003096C0] Unsupported codec id in stream 0
Output #0, ogg, to 'Target.ogg':
    encoder         : Lavf53.6.0
    Stream #0.0: Audio: qg[0][0] / 0x6771, 44100 Hz, 2 channels, 128 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
Could not write header for output file #0 (incorrect codec parameters ?)

Of course this does not necessarily need to be done via ffmpeg, any method that is workable would be fine...

I have cut down one of the files to 512KB: sample.wav
(Changed two chunk size fields in the wave header to account for this, the embedded stream is cut "without notice")

share|improve this question
Does it actually play back correctly in MPlayer? I don't think *.wav files support vorbis streams - they should just be raw PCM data. – Darth Android Aug 24 '12 at 22:16
@DarthAndroid: They do support raw data and encoding, see Wikipedia. – H.B. Aug 24 '12 at 22:27
@H.B. Can you provide a sample file of the input? – LordNeckbeard Aug 26 '12 at 20:24
@LordNeckbeard: I made a shorter sample from one of the files if you are still interested... – H.B. Aug 27 '12 at 21:13
up vote 3 down vote accepted

The WAV container is basically just a file header. It does not support variable length frames, required by Vorbis. "OggVorbis ACM" is actually Vorbis within an Ogg container (to provide the framing) so that it can be used in the legacy Windows ACM audio framework, which does not support the required framing. This also allows it to be used in WAV files, although that doesn't make as much sense since you could just save a .ogg file instead.

ffmpeg does not implement or recognize this non-standard "OggVorbis ACM" WAV codec. You can use a program that recognizes this, such as Audacity, or you could try just stripping off the WAV header to extract the Ogg Vorbis that is inside.

Valid Ogg streams start with OggS, which marks the beginning of every Ogg Page in the file. In the file you provided there are 66 bytes before the first OggS. At least on Mac/Linux/Unix you can strip off the first 66 bytes with the command:

tail -c +67 sample.wav > sample.ogg

In your file, the embedded Ogg actually contains two streams, in what seems to be an attempt to pad it to a fixed bit rate. The second stream has an unknown codec and seems to confuse some players. For example, Firefox plays the first stream (ignoring the second) but Chrome stops when it encounters the second stream. It also has other spec violations, including no eos (end-of-stream) (perhaps because you did not post the complete file).

If you extract out the first bitstream (the vorbis one) it seems to play correctly. Here are some tools that should be able to extract the first bitstream:

  • oggsplit (works on either the wav or ogg files)
  • oggSplit from Ogg Video Tools (works on the ogg file)
  • oggz-rip (however this program does not like your file, probably due to the other spec violations)

It might be better to just read the WAV file with a program like Audacity and re-encode it to ensure that it doesn't contain any other weirdness.

share|improve this answer
I tried stripping the wave header before, however MPlayer will no longer play it then, and other players have trouble as well. Also for some reason the OggS can also be found in other places within the stream, see for example offset 2f196 of the sample, though i do not know much about the ogg vorbis specification... – H.B. Aug 28 '12 at 1:47
OggS should be at the beginning of each Ogg Page. I've expanded on my answer to address the issue you are seeing. – mark4o Aug 28 '12 at 7:07
The reencoding is exactly what i try to avoid here to not loose any more quality. Thanks for your time, i'll have a look at that approach... – H.B. Aug 28 '12 at 11:09
@H.B. mark4o's solution does not re-encode, IIRC, and at least allows ffmpeg to properly decode the sample. – LordNeckbeard Aug 28 '12 at 18:04
@LordNeckbeard: I know, i was just referring to the last paragraph: "It might be better to just read the WAV file with a program like Audacity and re-encode it" – H.B. Aug 28 '12 at 18:09

I have encountered the same problem, with only difference that I needed to process large number of Ogg Vorbis WAV files. Audacity could not open many of them (currently Audacity lacks support for Ogg Vorbis WAV files with codec ID 6771), not to mention it cannot batch process files recursively (its Apply Chain feature limited to files in single directory).

I ended up writing ogg_wav script to convert Ogg Vorbis WAV to more usable format. The script have many options and error handling. It can convert Ogg Vorbis WAV to uncompressed WAV (-c option), or extract primary OGG stream (-e option, the default if no options provided), among other things. It skips files without Ogg streams. With -d option it will delete original .wav file.

This is how it works in simplest case: it checks if file have Ogg stream with ogginfo, checks if we have necessary write permissions, then looks for first "OggS" mark and uses moggsplit to try to extract Ogg stream(s), and if there is more than one, it assumes that the largest playable Ogg stream is the one we want. The script can handle some more complicated cases too and has many options, run ogg_wav -h to see them all.

Here are some examples how to use it. First, it is necessary to install the script: download ogg_wav (it requieres Bash shell and I tested it only in Linux), make it executable (with chmod +x) and put it to /usr/local/bin/.

To convert Ogg Vorbis WAV to OGG (it is possible to specify more than 1 file or use shell globbing like *.wav):

ogg_wav ogg-vorbis.wav

The command above will create ogg-vorbis.ogg by extracting largest playable OGG stream from the WAV file.

For large number of files it is better to use GNU parallel. This is the command to convert Ogg Vorbis WAV to uncomressed WAV recursively (remove -d option if you would like to keep backup of original WAV files by changing .wav extension to .bak):

find DIRECTORY -type f -iname '*.wav' | parallel ogg_wav -cd '{}'

The script will skip WAV files with no Ogg stream inside so it can be used even you have uncompressed WAV and Ogg Vorbis WAV in the same folder.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .