[Vorbis] any help with pyogg and pyvorbis?

matthias felsche matthiasfelsche at web.de
Tue Feb 24 01:53:46 PST 2009


Dear List,
I'm just creating a little application for my openmoko freerunner, 
unfortunately in python, so that I have to use pyogg and 
pyvorbis(http://ekyo.nerim.net/software/pyogg/index.html) as wrappers 
around the C-functions and objects.
I've got it all installed, after applying some patches and trying to run 
an example of encoding a wave-file I just get an empty ogg-file, the 
right header and so on, but no data has been written.
The python-example is the following:

_____________________________
#!/usr/bin/env python
'''An example of encoding using the Python wave module'''
import ogg.vorbis, wave

fout = open('out.ogg', 'wb')
inwav = wave.open('in.wav','rb')
channels = inwav.getnchannels()
vd = ogg.vorbis.VorbisInfo(channels = channels,
                           rate = inwav.getframerate(),
                           quality = 0.2).analysis_init()
os = ogg.OggStreamState(5)
map(os.packetin, vd.headerout())
og = os.flush()
while og:
    og.writeout(fout)
    og = os.flush()
nsamples = 1024

eos = 0
total = 0
while not eos:
    data = inwav.readframes(nsamples)
    total = total + nsamples
    if not data:
        vd.write(None)
        break
    vd.write_wav(data)
    #print 100.0 * total / inwav.getnframes()
    vb = vd.blockout()
    while vb:
        vb.analysis()
        vb.addblock()

        op = vd.bitrate_flushpacket()
        while op:
            os.packetin(op)
            while not eos:
                og = os.pageout()
                if not og: break
                og.writeout(fout)
                eos = og.eos()
            op = vd.bitrate_flushpacket()
        vb = vd.blockout()


_________________________


Only knowing very few about C and just something about the vorbis-codec, 
I found that the problem occurs here:

og = os.pageout()
if not og: break

no page is actually written, it returns None. And consequently it breaks.

The wrapper-source says this:


/* TODO: You can't keep a page between calls to flush or pageout!! */

static PyObject *
py_ogg_stream_pageout(PyObject *self, PyObject *args)
{
  ogg_page op;
  int res;
 
  if (!PyArg_ParseTuple(args, ""))
    return NULL;
  res = ogg_stream_pageout(PY_OGG_STREAM(self), &op);
  if (res == 0) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  return py_ogg_page_from_page(&op);
}

And ogg_stream_pageout always returns 0, so, insufficent data has been 
accumulated to write a page.
Can anyone help me and guess, where the fault may be. After all I've 
read this seems to be the right encoding procedure. So is it the 
python-wrapper? Is it the data I've been using (16Bit-Little Endian, 
16000Hz, Mono wav-file) wrong?

Thank you very much!
Matthias



More information about the Vorbis mailing list