Implementation of encapsulating extracted opus payload from RTP packet with ogg container
Asked Answered
S

2

8

We have the captured pcap file which includes RTP opus payload per rfc6716, now we can cut off the RTP header and extract the opus payload, we want to encapsulate the payload to ogg opus per spec https://datatracker.ietf.org/doc/html/draft-ietf-codec-oggopus-07 (Ogg Encapsulation for the Opus Audio Codec) and send out, so that VLC can playback the captured opus, we don't want to save to an ogg file then let VLC to playback, we will send the ogg opus out to VLC directly once one packet is encapsulated, anyone who have the referenced implementation of the encapsulation, or 3rd party library I can refer?

Spittoon answered 22/5, 2015 at 2:16 Comment(0)
C
2

The packets can be read using the libpcap library and then encapsulated in Ogg using the libogg library. There is an example program called opusrtp in the opus-tools package that can sniff for Opus RTP packets on the loopback interface using libpcap and write them to Ogg. You would want to do something similar, but change the pcap_open_live() to something like pcap_open_offline() if you want to read from a pcap save file, and write the Ogg pages from libogg to a socket instead of a file. Also define OPUS_PAYLOAD_TYPE to be the RTP payload type you want to look for.

Conventual answered 22/5, 2015 at 3:50 Comment(6)
Sorry for too late response, while I see there are some APIs in opusrtp, e.g. opus_packet_get_samples_per_frame which lies in libopus library, ogg_stream_pageout which is ogg lib, I can see the API document, but I can't find the exact implementation source code of the API, do you know where I can get it? ThanksSpittoon
@Programmer: opus_packet_get_samples_per_frame() is implemented in opus src/opus.c (docs). ogg_stream_pageout() is implemented in ogg src/framing.c (docs).Conventual
Yes, I see those API implementation, thanks. Well, if the captured pcap has 2 direction stream, one is from A to B, and the other is from B to A, we say 2 people have a phone call with each other. Each stream has its own rtp sequence, the opusrtp will check rtp out of sequence, if so, then the rtp packets is just discarded, I can modify the code to not discard, but not sure if I feed all these 2 stream rtp opus packets to opusrtp example program just as the captured sequence , opusrtp can still work well and produce a good .opus file, currently I don't have such capture, any guidance on this?Spittoon
You could write each stream as a separate opus stream or to its own .opus file.Conventual
The purpose is to reproduce/playback the real conversation scenario. Write each stream to its own .opus file, we can't playback with VLC with a dialog based voice conversation, if write each stream as a seperate opus stream, can we hear a voice conversation? If this works, do you know how to implement? From opusrtp I don't see such functionality.Spittoon
You could stream each audio stream to a separate VLC, or you could use a program like FFmpeg which can read from multiple streams and mix them together using an audio filter. If you mix them in your program you'd need to decode the audio streams, mix them together, and then re-encode the mixed audio.Conventual
S
0

I had a similar need, and following the advice from this answer I wrote an integration of opusrtp that can receive as input a pcap file and then generates the .opus from it.

The gist was in fact using pcap_open_offline() instead of pcap_open_live(), set the correct payload type, and a few other details to adapt to the input file format.

I have the modified opusrtp in a fork on github.

You can use it with something like ./opusrtp --extract PCAPFILE

It generates rtpdump.opus, which you can then transform as needed.

Schismatic answered 3/2, 2016 at 19:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.