Libreplay - a lib to save realplay output

Motivation

When you use realplay, sometimes you would like to save the sound that you hear, to be able to listen to it later in time. But realplay doesn't have a save or export button, so how to do it?

It seems hard, if not impossible.

So I decided to kick some code for a very tiny utility that would do this kind of things.

libreplay will save the output of realplay in a raw format, so you can do what you want with this uncompressed data later in time.

Download

June 1 2006: libreplay-0.5.1.tar.gz (very small file)
Fixing minor stuff (turning stuff into static, removing the including of bfd.h).

May 29 2006: libreplay-0.5.tar.gz (very small file)
David Decotigny (david decotigny free fr, with dots betweens these words, except the second hole which gets an at-sign) added an emulation mode. The lib won't be aggressive while downloading the stream but won't output any sound (in 0.3 we output to the sound card to slow down the download). He also provided the possibility to write audio in other directories than /tmp.

Feb 26 2003: libreplay-0.3.tar.gz (very small file)
Peter Gober (peter gober fokus fraunhofer de, with dots between all those strings, except the second hole, which receives an at-sign) (if your addresses' seeker gets this one, it is surely not a computer :-)) had troubles with a live stream, and added support for it. After some hacks, here is the release. It was not very tested, if you have troubles, tell me.

Dec 19 2002: libreplay-0.2.tar.gz (very small file)

Nov 29 2002: libreplay-0.1.tar.gz (very small file)

libreplay is in the public domain.

Installation

Just do a make in the directory, should be alright. There will be the file libreplay.so which contains everything usefull.

Configuration

This works on linux with oss. It may work somewhere else, but it was not tested. If you can't use it, try to contact me.

Usage

This documentation is only valid for version 0.5 of libreplay. Avoid using 0.1, it crashes too much realplay. (Version 0.2 does not have LIBREPLAY_AUDIO support.) (Version 0.3 does not have LIBREPLAY_EMULATE nor LIBREPLAY_DIRPATH support.)

You must set the variable LIBC_PATH to the place where your libc is (something like /lib/libc.so.6). If you are under bash, just do
export LIBC_PATH=/lib/libc.so.6
(replace /lib/libc.so.6 by your libc of course).

Do
LD_PRELOAD=./libreplay.so realplay
in the directory where libreplay is.

realplay will create realplayer_stream_XX_speed_YY_channels_ZZ_format_AA.raw for each stream you play. It will create these files in the /tmp directory by default (can be changed by setting the LIBREPLAY_DIRPATH environment variable).

XX will be replaced by the stream number (from 0 to whatever the number of streams you download).

YY will be the speed of the stream (44100 if the stream is at 44100Hz, for instance).

ZZ will be the number of channels of the stream (1 for mono, 2 for stereo).

AA will be the size of each sample of the stream (I only saw 16 for it, meaning: 16 bits, signed, little endian).

Some streams may be empty, because realplay sometimes opens and closes the soundcard whitout outputting any sound.

The output is a raw file, use sox or you favorite conversion program to transform it into a format you like more.

For instance, using sox, you would do

sox -t raw -s -w -c 2 -r 44100 realplayer_stream_6_speed_44100_channels_1_format_16.raw out.wav copy

-t raw for saying it's a raw file,
-s -w for saying it's 16b signed,
-c 2 for saying there are 2 channels,
-r 44100 for saying it's a 44100Hz stream.

It has been tested against realplayer 8.

By setting the environment variable LIBREPLAY_AUDIO, you can save live streams. Some streams create problems when they are saved faster than they are played; the server will send again some audio data, and the result is bad. With this option, the stream is played and saved at the same time. If you have problems with your saved streams, try this option.

There is also the environment variable LIBREPLAY_EMULATE which also adds some delay in the downloading, but does not output audio to the sound card (the sound card might be in use, rendering the use of LIBREPLAY_AUDIO impossible). You set it to 1 for an almost exact emulation of delay. You may set it to higher values to speed up a bit the download. Default value is 4 which means the download has 1/4 of realtime delay (the stream is downloaded at speed x4).

You also may set LIBREPLAY_DIRPATH and the files will be saved in the indicated directory. The default directory is /tmp.

You may use the scripts realplay.dump and realplay.dump_live, which include all the necessary to let realplay be used with libreplay.
realplay.dump will only save the stream.
realplay.dump_live will save it and play it.
There is also realplay.dump_emulate_live that uses the LIBREPLAY_EMULATE environment variable.
You may need to edit these scripts, to adapt the paths, for them to fit your system. These scripts are only here to help you; if they don't work, you still will need to read the documentation (this file) and understand it.
You may also need to modify the value of LIBREPLAY_EMULATE in realplay.dump_emulate_live if it is too high or too low, depending on the stream (setting it to 1 should be safe for all streams).

Gregory did a little perl utility to, maybe, facilitate the usage of this little tool. realexport.tar.gz realexport.sh something.rm is the way to use it, according to Gregory. (It may work, it may fail, not tested.) You will need sox and lame available on your system. Note that realexport.sh was developed with the 0.3 version of libreplay. It may not work with the 0.5 version (LIBREPLAY_EMULATE is not supported I guess).

Take also a look at realdump.sh by David Decotigny. He does the sox conversion and ogg encoding on the fly. (Maybe I should include it − after cleaning − in the main release...)

Problems?

Contact me so I can help you.

If you crash realplay, please include the url of the stream you tried to save, so I can try to reproduce the problem here.

It should be very easy to read the code and know what's going on.

To be quick, we use the preload facility to catch open, close and ioctl to let realplay think it is talking to /dev/dsp where in fact it outputs sound into a regular file. (With the 0.3 version and above, we catch write too, since we may really open the audio device and when realplay does 1 write, we do 2 writes.)

With ptrace

(This was added March, 21st, 2005.)

realplay could be a static program, this would make things a little harder, and render libreplay unusable. But we simply could patch the linux kernel to let it save every output to /dev/dsp into a regular file. Or, without entering kernel world, we could use ptrace too.

Dario thought this idea was nice. He made some shell scripts, using the wonderful strace. Here they are.

These scripts do more or less the same job as libreplay. You don't get the type of audio (44100Hz, 16b, etc.) but we could get this information from strace. Well, just a demonstration of the easiness of the job... You may need some hacks to let them work. Thanks Dario!

Final word

Could it be easy for realplay to know it is not talking to /dev/dsp? Well, I don't know... and I don't care. I want to control what happens inside my computer.

To protect from libreplay or the ptrace stuff, we could create a "trust" computer, that would not run with such hacks. Some are thinking about this solution. We'll see if we can defeat them or not if such a computer is released one day and adopted by users. I bet we can, but it's just a bet.

If we can't, well, simply play the sound and record it from the speaker with old-fashioned hardware.

Forbid people to record and share is impossible. Humans are hardwired to communicate with each others. The world of Money is trying to put its own rules in the process, and it will lose. (If it could destroy itself in the meantime, this would not be bad, but we are entering the world of off-topicness here.) That's only a bet, though...

Copyrights are definitly a bad thing.

Links

I just saw (November, 14th, 2003) that there existed vsound, which exists for several years, as it seems. You think you make something original, and you get doomed... (You may need to search the web for vsound, since the original website of it is this one, done by an Australian, but because of legal matters, he took it away from the Internet, so maybe the link I give does not exist anymore at the time you click it; I love the world I live in, really.)


Contact: sed@free.fr

Creation time: Fri, 29 Nov 2002 22:08:22 +0100
Last update: Mon, 14 Apr 2008 13:20:31 +0200

Powered by a human brain, best viewed with your eyes (or your fingers if you are blind).