Java – Stream raw sounds using FFMPEG

Stream raw sounds using FFMPEG… here is a solution to the problem.

Stream raw sounds using FFMPEG

I’m using the ffmpeg library to decode/encode audio in JAVA using Process objets. THE PURPOSE IS TO GET THE RAW DATA DECODED BY FFMPEG IN MY JAVA CODE AND SEND THEM BACK TO FFMPEG TO GENERATE A STREAM OR CREATE A FILE.

SINCE JAVA SOUNDS ONLY ALLOW WAV AUDIO DATA, I MADE MY FIRST ATTEMPT WITH THIS COMMAND LINE :

ffmpeg -i http://199.180.75.118:80 -acodec pcm_s16le -ar 44100 -ac 2 "/home/dr_click/montest.wav"

It works. However, my goal is to get frames dynamically instead of files. I considered using pipes, but it seems to only work for Linux and not Windows (no MacOS known)
So, I prefer to transfer a wav file locally and capture it in JAVA into an AudioInputStream.

I wrote this command :

ffmpeg -re -i http://199.180.75.118:80 -acodec pcm_s16le -ar 44100 -ac 2 -f rtp rtp://127.0.0.1:1234

Seems to work on the server side. However, when I enter the following command line on the server side:

ffplay rtp://127.0.0.1:1234

It doesn’t work at all. I got this error :

  • [rtp @ 0x7f29c8000b80] could not receive RTP load type 97 without SDP file description

If I try this couple:

ffmpeg -i http://199.180.75.118:80 -acodec pcm_s16le -ar 44100 -ac 2 -f rtp -sdp_file /home/dr_click/audio.sdp rtp://127.0.1.1:1234

and

ffplay /home/dr_click/audio.sdp

I get the following error:

  • [rtp @ 0x7f7d00008040] protocol ‘rtp’ is not on the whitelist ‘file,crypto’! If

If I finally try :

fmpeg -protocol_whitelist file,http,rtp,tcp -i http://199.180.75.118:80 -acodec pcm_s16le -ar 44100 -ac 2 -f rtp -sdp_file /home/dr_click/audio.sdp rtp://127.0.1.1:1234

I’m still getting the same error.

What

did I miss when streaming some raw data locally and capturing it back to AudioInputStream?

Thank you for all your responses.

Solution

I finally found an explanation. An RTP stream with a load of 10 or 11 is the big endian. Therefore, it is not possible to stream using a little-endian codec.
The correct way to stream is to change the codec and the command line becomes:

ffmpeg -re -i /home/dr_click/live.wav -acodec pcm_s16be -ar 44100 -ac 2 -payload_type 10 -f rtp rtp://127.0.0.1:1234

Thanks to the people who read my question.

Related Problems and Solutions