decoding .raw voip data to opus - voip

I have got this capture file (pcap) with RTP packets seems to be encoded by opus. In wireshark, analyzed the stream and saved as raw file.
Now I have got the .raw file of the audio. Using the opus tool from http://www.opus-codec.org/downloads/
I cannot decode it direct to wav because the file is raw,not .opus. I cannot encode it to .opus because this raw data is the extract of already encoded stream.
I just need to play this voice back. Any suggestions Please

As far as I know you won't be able to decode Opus stream extracted that way - framing information is lost. You need either write Wireshark module that would be able to decode opus or write another tool to extract stream from RTP into another container (typically OGG is used).
http://xiph.org/~giles/2012/rtpopus.c seems to be tool that you need.

Old question, but if anyone needs to decode Opus RTP packets, here is the solution:
PJSIP comes with a tool (pjsip-apps/src/samples/pcaputil.c) that does just that. It gets compiled by default, just make sure you have libopus-dev installed before you build PJSIP. Simply feed a pcap file with RTP packets to pcaputil and specify the codec on the command line (e.g. "opus/48000"). You will get the decoded audio as a PCM WAV file.
pcaputil can also decrypt SRTP packets (if given the key), however I could not get that to work and instead used srtp-decrypt to decrypt the packets, followed by Wireshark to convert the .txt output back to .pcap for feeding to PJSIP's pcaputil (see also https://www.acritelli.com/hacking-voip-decrypting-sdes-protected-srtp-phone-calls/).

Related

How to collect EVS codec from pcap file

I have several pcap files which captured by wireshark.
I collected that data from pcap file, payload data.
and saved it as file.
I tried to convert it to pcm data with this link
https://github.com/ToughmanL/EVS_CODEC
but it seems the data I collected is not EVS format.
please let me know how to get EVS codec from pcap file.
My understanding is that Stack Overflow is for programming questions, so here is an answer based on existing / example source code. First, in your screen cap Wireshark has found a commonly used form of EVS; the 61 byte packet payload length matches the EVS spec for 24400 bps primary mode, using compact format, which means (i) no ToC header byte in the payload, and (ii) only the payload size determines the bitrate. Second, to feed that to the 3GPP decoder you have to create a file with a MIME header and format, which is needed by the 3GPP reference program.
x86_mediatest.cpp (under the mediaTest folder in the Docker containers here) does this - it reads a pcap record-by-record, pulls out RTP payloads and writes them to a .cod file (coded format), including the MIME header. Running the 3GPP program on that file, with appropriate command line options then gives a PCM raw audio file you can convert to wav using sox, Audacity, Hypersignal, etc.
In x86_mediaTest.cpp, look for "if (pcap_extract) {". Also note the comment "If pcap RTP payloads are in CH (Compact Header) format, they are converted to FH (Header-Full) format by adding a ToC payload header byte". Which may explain why in your case, if you directly copied the compact header format payloads and fed them to the 3GPP decoder, it didn't work.
There is also a mediaMin program that will take the pcap on the command line and do the whole thing, generating a .wav file. You can use that for comparison and audio quality testing vs your code.
Disclaimer: I work for the company that created the mediaTest and mediaMin tools

Converting from .opus to .wav

Hello I am supposed to write a utility that will extract an opus encoded audio payload from RTP packets which I will read from a pcap dumpfile. The utility should also have the functionality that can be used to decode the payload that I am extracting from the rtp packets and convert it to a .wav file.
Currently I have written a code that extracts the payload from the rtp packets and dumps it into a file "log.opus". However I am stuck at this point. How should I proceed with writing the decoder logic?
I am working on Windows platform and am using winpcap library and libopus.
I suggest you have a look at this trivial example I created to show how to use Opus:
http://git.xiph.org/?p=opus.git;a=blob;f=doc/trivial_example.c
You'll want to keep just the decoder part. There's also the API documentation for more details:
http://www.opus-codec.org/docs/html_api-1.1.0/index.html

Convert a RTP sequence payload (coded with GSM\ opus\speex ) in a .wav file

I have a text file contaning payload of RTP packets (in hex,coded with GSM\ opus\speex ) belong to a VoIP conversation, does anyone know how to convert this file into a .wav audio file?
I'm using windows.
Thanks
.wav is just an file container which you can have an any codec format and makes the player to recognize the codec inside. Refer Wiki: WAV and for more technical details refer WaveFormat. And It just wrappers the raw codec content. If you have experience in C program, there are open source available to convert one codec to PCM. Since PCM is the raw audio data in 16 bit format.
But I suggest an solution but don't know it will met your requirement.
install latest wireshark
using wireshark capture the RTP packets.
Select UDP packet and Right click and choose Decode As option
Select Transport tab and choose RTP protocol
Now you can see RTP packet with right codec
Go to Telephony -> RTP -> Stream analysis -> Save the RTP Payload as .raw
At this stage the codec data is available in .raw file format.
There are open software are available are available such as SoX, ffmpeg etc...
From there are you can covert .raw to .wav format.
After that you can play in VLC (PCM, GSM, ADPM, Alaw , uLaw) or any other supported player (Amr)
You won't find Speex, g729 since these are paid

How to determine the codec of an audio file on Windows?

I need to find the codec of an audio file. How can I do this?
Do I need to write code to do this or is there a simpler way?
Please help me. If possible share helpful links.
The good old file utility will reveal lots of information about audio files, sometimes including the codec:
$ file X.wav
X.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 16000 Hz
#bhebsquines
"It is important to distinguish between a file format and an audio codec. A codec performs the encoding and decoding of the raw audio data while the data itself is stored in a file with a specific audio file format. Although most audio file formats support only one type of audio data (created with an audio coder), a multimedia container format (as Matroska or AVI) may support multiple types of audio and video data." - http://en.wikipedia.org/wiki/Audio_file_format
The application gspot does a good job of pulling codecs from audio and video files.
http://www.headbands.com/gspot/
run it and drag a file into the window. It will pull all of the data from there. Note that some audio files will not display a codec as they are made from "Raw" audio.
You can identify your codec by extenion name itself example file1audio.mp3 or fileaudio.avi, .mp3, .avi will be your file type or codec, you can use k-lite codec pack for your different type audio format. use this link http://www.free-codecs.com/download/k_lite_codec_pack.htm

How to retrieve H263/H264 data from a pcap file.

I have tried tools like videosnarf that takes a pcap file as input and creates a raw .h264 file , which could be later encoded with ffmpeg , and finally can be played with vlc player. But videosnarf can only handle h264 data.
I'm not able to find a similar tool that can dump h263 data from a pcap file. I tried to decode h263 stream from wireshark but I have had no luck so far.
I can program in perl/python but I don't know what exact steps to follow to retrieve h263 raw data from a pcap file as I haven't played with pcap capture files before.
sjd,
You can try setting up a sniffer using Twisted Python library (Twisted) this would allow you to capture the raw data coming in over your network as long as you can tell Twisted what port to listen to (or listen all), and where to dump the file to, etc and then do something with that new file (like send it into ffmpeg to test saving to .mov).
You would have to generate the .sdp file for ffmpeg, so unless you automate that step of the process, it is really annoying. I am currently working on the automation portion but am struggling just as much.
I'm using EventMachine for Ruby with FFMPEG, and .sdp from SIP.
Hope this helps a little.

Resources