Convert an audio file into a pcap with codec G722 - voip

I need to convert an audio file (any common format) into a rtp stream saved in a .pcap file with G.722 Codec.
The generated .pcap file will be sent with SIPp using:
<exec play_pcap_audio="g722.pcap"/>
I know it is possible to send also .wav file with the following command, if the .wav is correctly encoded:
<exec rtp_stream="g711.wav"/>
But seems that is not possible to encode a .wav with G722.
There are multiple solutions on the web and SO on how to convert a .pcap into an audio file, but I'm actually looking for the opposite.

Steps to convert wav audio to .pcap file:
Split audio to 20 ms chunks
Encode each chunk with G.722 encoder
Create RTP header for each encoded chunk
Save RTP stream to .pcap
I've never used SIPp, but if it can process encoded G.722 stream, then use ffmpeg for encoding:
ffmpeg -i sample.wav -ar 16000 -acodec g722 sample.g722

Get softphone supporting wav files as source and G.722 codec, make call with only G.722 enabled, capture RTP stream to pcap.

Related

ffmpeg audio encoding based on codec and not on stream identifier

I have an RTSP Stream with one video stream and three audio streams as the source. Two of the audio streams are encoded with .mp2 and one is encoded with .ac-3. I want to convert the .mp2 streams to AAC. This would be easy if the .mp2streams would have the same stream identifier every time I start ffmpeg, but unfortunately the stream identifiers change. This means sometimes the two .mp2 streams are 0:a:0 and 0:a:1 and the next time they are 0:a:1 and 0:a:2.
Is there an option to re-encode only the .mp2 streams and keep the .ac-3 stream untouched?
I should probably also mention that this encoding is used for live TV so it is not an option to produce intermediate files or have several ffmpeg commands.
Try
ffprobe -show_entries stream_tags -select_streams a INPUT_URL
and see if there are any stream tags (metadata) that distinguishes mp2 streams. Then you can use the metadata stream specifier to selectively set re-encoding:
ffmpeg ... -c copy -c:a:m:{name}:{value} ac3 ...
where {name} and {value} are the name and value of the tag, respectively.
Reference on stream specifier: https://ffmpeg.org/ffmpeg.html#Stream-specifiers-1
If there isn't any usable tag, your only solution likely is to run ffprobe first to identify the stream # before running ffmpeg.

How to add a 5.1 .flac audio track to a .ts file with already 3 audio tracks?

I want to add a 5.1 .flac audio track to a .ts file that already has three audio tracks. I tried with tsMuxer and ffmpeg with unsuccessful results. In tsMuxeR the .flac track is not recognized and in ffmpeg everything seems to work fine until the very last moment when I check the file and the .flac audio track is not included in the "output.ts". The .flac track is about 3GB and its lenght is around two and a half hours.
Thank you so much.
I don't think you'll find any existing software that maps FLAC into a MPEG-2 Transport Stream.
This gives you an idea what sort of issues you run into: https://xiph.org/flac/ogg_mapping.html
Let's say you came up with a reasonable way of mapping FLAC into a MPEG-2 Transport Stream - there won't be anything reading it.
Unless there is a specified way of mapping FLAC into a MPEG-2 Tranport Stream - you are on your own.
But PCM is supported in a MPEG-2 Transport Stream (for example Blu-Ray).
I'd use ffmpeg to transcode your audio from FLAC to PCM and then mux it into your transport stream.
Your audio transcode (FLAC to PCM) is lossless.

decoding .raw voip data to opus

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/).

Convert audio to 8-bit signed PCM

I have a .mp4 audio file that I want to convert to a 8-bit unsigned PCM format for an Arduino Uno using the TMRpcm library.
It also could be a .wav file. Anyways, I have tried many things to no avail. The closest I got was with Audacity using the NIST Sphere codec. I tried to do this with FFmpeg, but it only supports demuxing NIST Sphere files. How do I convert audio to this format on Mac OS X (10.10.2)?
avconv is a fork from ffmpeg ... so use ffmpeg if you wish
avconv -i input.mp4 -ar 8000 -acodec pcm_u8 -ac 1 output.wav
WAV is the container format for the PCM codec so if you MUST have PCM then get into a binary file editor (wxHexEditor is a nice one) and delete the first 44 bytes (its header) of that WAV file
So above gives you 8000 samples per second and a bit depth of 8 bits, and mono.
verify this using
avprobe some_video_audio_file.wav
see bit depth listing available using avconv here
I realized that I was trying to convert a corrupt audio file. Audacity converted a valid file correctly.

What is the difference between M4A and AAC Audio Files?

Is there any difference between M4A audio files and AAC audio files or are they exactly
the same thing but with a different file extension?
.M4A files typically contain audio only and are formatted as MPEG-4 Part 14 files (.MP4 container).
.AAC is not a container format and instead it is a raw MPEG-4 Part 3 bitstream with audio stream encoded.
Note that M4A does not have to contain exactly AAC audio, there are other valid options as well.
There are raw video and audio streams, this streams cannot be played directly on most video/audio player, they need to be "encapsulated" on a transport, a raw H.264 video stream and a raw AAC audio stream need to be inside a MP4 encapsulator, it can be also inside an AVI or MOV encapsulator.
A MP4 file can contain a H.264 video stream and/or an AAC audio stream, but for some reason someone decided that a MP4 file that contains video and audio use the file extension M4V (v for video) and if it is an MP4 file that only contains audio to use the M4A extension, that is a common practice in other encapsulators like Windows Media which use WMV and WMA, or OGG which use OGV and OGA, silly as it seems.
So a file that has a M4A file extension is an MP4 file that can contain a AAC audio track but it is not always the case, that's why programs like mediainfo become handy to know what is inside a file.
They are not the same thing.
An .m4a file is basically the same thing as an mp4; it is only a container format. codec != container It does not imply a codec, and therefore it can only contain mp3, ac3 or any other audio codec.
An .aac file contains concatenated AAC frames pre-pended with ADTS headers (and optionally an ID3 tag).

Resources