[theora] Add an intro to a theora file without re-encoding?

Lino Mastrodomenico l.mastrodomenico at gmail.com
Tue Jul 21 03:01:30 PDT 2009


2009/7/21 Michael Opdenacker <michael at free-electrons.com>:
> I still have a problem with oggSilence... When I ask for a 6s duration,

While you wait for a proper solution with oggSilence, you may want to
try this small Python program:

---< cut here >---
# usage: silence.py frequency_in_Hz duration_in_seconds output.wav

import struct, sys

freq = int(sys.argv[1])
size = int(round(float(sys.argv[2]) * freq)) * 4
f = open(sys.argv[3], 'wb')
header = ('RIFF', size + 36, 'WAVEfmt \x10\0\0\0\1\0\2\0',
          freq, freq * 4, '\4\0\x10\0data', size)
f.write(struct.pack('< 4s I 16s 2I 8s I', *header))
f.write(struct.pack('B', 0) * size)
f.close()
---< cut here >---

Use e.g. with:
    silence.py 44100 3.51 silence.wav

to create 3.51 seconds of silence at 44100 Hz with filename "silence.wav".

It always creates stereo 16-bit-per-sample files. Works with any Python version.
It keeps the whole file in memory, so if you need hours of silence...

-- 
Lino Mastrodomenico


More information about the theora mailing list