manash
manash

Reputation: 7106

Storing multiple channels with different encoding/sampling in a single WAV file

I have two RTP streams (one for each call direction) that I want to mix in a single WAV file.

The problem is that the two streams may use different codecs (and therefore different sampling frequency, encoding, etc).

Is it possible to store the two RTP streams in a WAV file using two channels (i.e. stereo)? Asked differently, is there a way to store multiple channels with different encoding, sampling frequency, etc?

Upvotes: 0

Views: 472

Answers (2)

Arnaud Leyder
Arnaud Leyder

Reputation: 7002

As Roman R. mentioned it is not immediate. You will need to take an extra step in between to convert whatever you have on your RTP stream into a proper WAV file. The idea is to use a software like ffmpeg to do so:

2 × mono → stereo: ffmpeg -i left.mp3 -i right.mp3 -ac 2 output.wav

After that you could try something of the flavor (untested):

ffmpeg -i rtp://leftrtp -i rtp://rightrtp -ac 2 output.wav

Most likely you will need to tune the codec settings to make it work as you want. You can Google around and find some infos on the subject or read the ffmpeg doc.

Upvotes: 1

Roman Ryltsov
Roman Ryltsov

Reputation: 69662

Structure of the WAV file assumes that sampling rate and channel bitness is the same for all channels of the feed. Encoding applies the entire feed (with many encodings/formats/codecs you cannot separate a channel without decoding the feed).

You will need to store feeds in separate files, or you need a file format which supports multiple audio tracks (MP4, MKV for example) though they all have their own restrictions.

Upvotes: 1

Related Questions