Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Streaming raw sound with FFMPEG

I'm using the ffmpeg library to decode / encode audio in JAVA, using the Process objets. The aim is to got the raw datas decoded by ffmpeg in my JAVA code and then, to send them back to ffmpeg to generate a stream or create a file.

As JAVA sounds only allow wav audio datas, I made a first try 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. But, my goal is to get the frames on the fly and not a file. I thought about using a pipe but it seems it will work only with Linux and not with Windows (and no idea for MacOS) So, I'd prefer to stream locally a wav file and to catch it with JAVA into a 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

It semms to work on the server side. But, when I enter the below 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] Unable to receive RTP payload type 97 without an SDP file describing it

If I try the 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 got the following error :

  • [rtp @ 0x7f7d00008040] Protocol 'rtp' not on whitelist 'file,crypto'! if

And 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 still get the same error.

Which point do I miss to stream locally some raw datas and catch them back in the AudioInputStream ?

Thank you for all your replies.

like image 435
Dr_Click Avatar asked Oct 30 '25 06:10

Dr_Click


1 Answers

Finally, I found the explanation. The RTP streaming with the payload 10 or 11 are big endian. So, it's impossible to stream with a little endian codec. The right way to stream is to change the codec and the command line is becoming :

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

Thank you to those who read my question.

like image 112
Dr_Click Avatar answered Nov 01 '25 19:11

Dr_Click



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!