[gst-devel] Write an audio data stream to file with GStreamer

Vladimir Eremeev wl2776 at gmail.com
Thu Dec 17 16:05:20 CET 2009



Markus Luttenberger wrote:
> 
> Markus Luttenberger schrieb:
>> I read through the GStreamer manual and searched in the internet but I 
>> don't really find a way to write an audio stream (bytes of audio data) 
>                                        ^^^^^^^^^^^^
>> to a file, preferably a wav file.
> 
> Data from memory, to be more specific...
> 

If your task as simple as just to encode audio samples from memory and write
them to a file in any suitable format (WAV, ASF, MP3, something else), I'd
recommend using FFmpeg and its API (libavformat, libavcodec, etc).

You just do the following:

//init.
av_register_all();
AVCodecContext *codec_ctx = avcodec_alloc_context();
AVCodec  *m_codec = avcodec_find_decoder(CODEC_ID_MJPEG);
avcodec_open(codec_ctx, codec);
uint8_t *buf;
short *samples;
int buf_size;
int bytes_used;

// allocate buf
// assign samples to point to your data

//encode
avcodec_encode_audio(codec_cts,buf,buf_size,samples);

//write buf to a disk


//cleanup
avcodec_close(codec_ctx);
av_free(codec_ctx);

Details are here: 
http://cekirdek.pardus.org.tr/~ismail/ffmpeg-docs/avcodec_8h.html#c41ab8ea9bc0fd3bcf8dc9d3b446f5d3

Even simpler, you can exec ffmpeg and feed it with data via a pipe.
-- 
View this message in context: http://old.nabble.com/Write-an-audio-data-stream-to-file-with-GStreamer-tp26828466p26829360.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.





More information about the gstreamer-devel mailing list