Streaming from the input

Moderator: flatmax

EvanFooma
Posts: 2
Joined: Sat Mar 25, 2017 1:28 am
Location: Poland
Contact:

Streaming from the input

Post by EvanFooma » Wed Mar 29, 2017 6:57 pm

I am looking to stream my Internet radio station using SAM, Simplecast from two separate locations during the day. What is the most efficient way to do this?

flatmax
Posts: 609
Joined: Sat Jul 23, 2016 11:39 pm

Re: Streaming from the input

Post by flatmax » Thu Mar 30, 2017 8:52 am

Can you please give a little more information, not sure what SAM is ?
Two separate locations on the same network ?

thanks
Matt
Check out our audiophile quality crossovers : https://bit.ly/2kb1nzZ
Please review the Zero sound card on Amazon USA : https://www.amazon.com/dp/B075V1VNDD
---
Check out our new forum on github : https://github.com/Audio-Injector

W00fer
Posts: 5
Joined: Fri Mar 31, 2017 7:59 am

Re: Streaming from the input

Post by W00fer » Sun Apr 02, 2017 8:17 am

flatmax wrote:Can you please give a little more information, not sure what SAM is ?
Two separate locations on the same network ?

thanks
Matt
SAM = SAM Broadcaster
https://spacial.com/sam-broadcaster-pro/

abonam
Posts: 20
Joined: Sat May 13, 2017 7:21 am

Re: Streaming from the input

Post by abonam » Thu May 18, 2017 1:00 pm

Hello,

I am trying to do similar thing streaming audio from the input.
I am using auioinjector installed on a PI3
I followed your suggestions on setting up ffmpeg and ffserver.
I am able to see the stat.html page, the .wav file is there and I can even open it with the player, however the file is empty.

alsamixer shows both L and R channel are on CAPTURE mode for the input line I am using.
Input volumes are set to 79 for Master and 70 for capture, Output mixer HiFi is selected.
I was already able to stream music to a single client using rtp.
My next step is to setup a server, this is my first attempt of using ffserver and ffmpeg.

I started the server with the command

Code: Select all

ffserver -f /etc/my_ffserver.conf &
The conf file (without the comments) looks like this:


HTTPPort 8090
HTTPBindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 15000
CustomLog -
<Feed inputAudio.ffm>
File /tmp/inputAudio.ffm
FileMaxSize 200K
ACL allow 127.0.0.1 192.168.1.88
</Feed>
<Stream inputAudio.wav>
Feed inputAudio.ffm
Format s32le
AudioCodec pcm_s32le
AudioBitRate 3072
AudioChannels 2
AudioSampleRate 48000
NoVideo
AVOptionAudio flags +global_header
</Stream>
<Stream stat.html>
Format status
ACL allow localhost
ACL allow 192.168.0.0 192.168.255.255
</Stream>



Then, I issued the ffmpeg command with the debug on (-v 48)

Code: Select all

ffmpeg -f alsa -i plughw -acodec pcm_s32le -v 48 -f ffm http://192.168.1.88:8090/inputAudio.wav
and I got the following output (no error so far)
Reading option '-f' ... matched as option 'f' (force format) with argument 'alsa'.
Reading option '-i' ... matched as input file with argument 'plughw'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'pcm_s32le'.
Reading option '-v' ... matched as option 'v' (set logging level) with argument '48'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'ffm'.
Reading option 'http://192.168.1.88:8090/inputAudio.wav' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument 48.
Successfully parsed a group of options.
Parsing a group of options: input file plughw.
Applying option f (force format) with argument alsa.
Successfully parsed a group of options.
Opening an input file: plughw.
[alsa @ 0x103f520] All info found
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, alsa, from 'plughw':
Duration: N/A, start: 1495073088.573811, bitrate: 1536 kb/s
Stream #0:0, 1, 1/1000000: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
Successfully opened the file.
Parsing a group of options: output file http://192.168.1.88:8090/inputAudio.wav.
Applying option acodec (force audio codec ('copy' to copy stream)) with argument pcm_s32le.
Applying option f (force format) with argument ffm.
Successfully parsed a group of options.
Opening an output file: http://192.168.1.88:8090/inputAudio.wav.
[http @ 0x1049800] request: GET /inputAudio.wav HTTP/1.1
User-Agent: Lavf/56.25.101
Accept: */*




I opened the page at http://192.168.1.88:8090/stat.html
The web server is up and the messages from the ffserver terminal are here below:

Thu May 18 02:04:31 2017 FFserver started.
Thu May 18 02:05:03 2017 192.168.1.67 - - [GET] "/stat.html HTTP/1.1" 200 1631
Thu May 18 02:05:05 2017 192.168.1.67 - - [GET] "/stat.html HTTP/1.1" 200 1634
Thu May 18 02:05:07 2017 192.168.1.67 - - [GET] "/stat.html HTTP/1.1" 200 1634
Thu May 18 02:05:17 2017 192.168.1.67 - - [GET] "/inputAudio.wav HTTP/1.1" 200 79
Thu May 18 02:05:57 2017 192.168.1.67 - - [GET] "/inputAudio.wav HTTP/1.1" 200 79




The requests from different clients are accepted by the server, but the .wav file is empty.
I tried the following:
-verified the supported format and encoding with the command

Code: Select all

ffmpeg -formats
ffmpeg -codecs
- change the format/encoding to mp3, pcm_s16le, ogg, mp2
- change the input specifying -i hw:0,0 (same as -i plughw)
- trying different bitrates, consistent to the codec 16 or 32 and the number of channels (2)

For every combination, I had no error in output, the server was up and running but I was never able to get any content on the stream.

Anytime I made a syntax or parameter mistake, the server or the ffmpeg command returned errors.

Any idea how on how can I proceed to get the audio on the stream?

Thank you in advance for your help!
Attachments
ffserver.png
ffserver.png (97.39 KiB) Viewed 5249 times

flatmax
Posts: 609
Joined: Sat Jul 23, 2016 11:39 pm

Re: Streaming from the input

Post by flatmax » Thu May 18, 2017 4:30 pm

Out of interest, I would like to play with this too. How did you install ffserver ?

thanks
Matt
Check out our audiophile quality crossovers : https://bit.ly/2kb1nzZ
Please review the Zero sound card on Amazon USA : https://www.amazon.com/dp/B075V1VNDD
---
Check out our new forum on github : https://github.com/Audio-Injector

abonam
Posts: 20
Joined: Sat May 13, 2017 7:21 am

Re: Streaming from the input

Post by abonam » Thu May 18, 2017 4:53 pm

Hello,

found this post on raspberry.org (cut and paste from https://www.raspberrypi.org/forums/view ... &p=1092525)

An easier way to get ffmpeg instead of libav is to use:

https://deb-multimedia.org/

Just add:
deb http://www.deb-multimedia.org jessie main non-free
to:
/etc/apt/sources.list

Then:
sudo apt-get update
(ignore warning about missing key)
sudo apt-get install deb-multimedia-keyring
(press y when prompted about missing key)
sudo apt-get update
(to confirm missing key problem fixed)
sudo apt-get dist-upgrade
(to upgrade from libav to ffmpeg)


The above sequence does not work on pi zero, works on pi3 (tested) and should work on pi2.

Thanks,
Andrea

abonam
Posts: 20
Joined: Sat May 13, 2017 7:21 am

Re: Streaming from the input

Post by abonam » Thu May 18, 2017 5:03 pm

Hello again,


just found out the answer to my question :)

We need to use

Code: Select all

ffmpeg -f alsa -i plughw -acodec pcm_s32le -v 48 -f ffm http://192.168.1.88:8090/inputAudio.ffm
instead of

Code: Select all

ffmpeg -f alsa -i plughw -acodec pcm_s32le -v 48 -f ffm http://192.168.1.88:8090/inputAudio.wav
Found the right pointer on the comment portions of ffserver.conf.
Now I can see on the server side that the stream is going and the .wav file is finally receiveing data.

flatmax
Posts: 609
Joined: Sat Jul 23, 2016 11:39 pm

Re: Streaming from the input

Post by flatmax » Thu May 18, 2017 5:56 pm

Great ! good going ... can you hear the audio now ?
Check out our audiophile quality crossovers : https://bit.ly/2kb1nzZ
Please review the Zero sound card on Amazon USA : https://www.amazon.com/dp/B075V1VNDD
---
Check out our new forum on github : https://github.com/Audio-Injector

abonam
Posts: 20
Joined: Sat May 13, 2017 7:21 am

Re: Streaming from the input

Post by abonam » Thu May 18, 2017 6:08 pm

I can see the file and it gets downloaded by the client.
For some reason I still can not play it...need more digging. Time to go to sleep, will do more digging tomorrow :)

abonam
Posts: 20
Joined: Sat May 13, 2017 7:21 am

Re: Streaming from the input

Post by abonam » Fri May 19, 2017 9:58 am

Hello,

I managed to stream a wav file using ffplay.
It is tricky, looking at the documentation (mostly the help of the commands and the .conf files) it seems that the ffplay command wants the same exact options that are used by ffmpeg.

First of all, here my ffserver.conf file contents (once again, I stripped off the comments)

Code: Select all

HTTPPort 8090
HTTPBindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 15000
CustomLog -
<Feed inputAudio.ffm>
File /tmp/inputAudio.ffm
FileMaxSize 200K
ACL allow 127.0.0.1 192.168.1.88
</Feed>
<Stream inputAudio.wav>
Feed inputAudio.ffm
Format s16le 
AudioCodec pcm_s16le 
AudioBitRate  1536 
AudioChannels 2
AudioSampleRate 48000
NoVideo
Preroll 15
AVOptionAudio flags +global_header
</Stream>
<Stream stat.html>
Format status
ACL allow localhost
ACL allow 192.168.0.0 192.168.255.255
</Stream>
I added the line Preroll 15 to let the buffer fill up before the player begins, this trick works ok (still some latency while playing the .wav file) and can be used in conjunction with ?buffer=5 postponed to the URL of the file.
The file has format s16le, 2 channel, 48000 sample rate, 16 bit which makes the bitrate 48K * 2 * 16 = 1536K

To kill the previous ffserver instance, I like to use the old trick

Code: Select all

kill -9 `pidof ffserver`

This command will also kill the ffmpeg instance. Very handy while debugging ;-)

I can finally start the ffserver with the command

Code: Select all

ffserver -f /etc/ffserver.conf &

or wherever else the path of your .conf file is. Note the & option to start the server in background, so i can kill it when needed.

I can finally start ffmpeg

Code: Select all

ffmpeg -f alsa  -i plughw -acodec pcm_s16le -v 48 -f ffm http://192.168.1.88:8090/inputAudio.ffm
Remember to adapt the IP address to your device's IP.

On the client side (I'm using Mac terminal, with ffplay already installed) I issue:

Code: Select all

ffplay -i http://192.168.1.88:8090/inputAudio.wav?buffer=5 -v 48 -f s16le -ar 48k -b 1536 -ac 2
Now this took me forever to figure it out :-).
The .wav file was not read properly, ffplay was complaining about some generic error, no message errors and no clue on what was wrong. Oh happy day!
Only after reading the comment sections of the ffserver command I was able to find out that ffplay will play the stream only if the stream options are specified on the command itself and they must match the options given to the stream inside the .conf file.
So, there you go:
-f s16le is the format;
-ar 48k is the sample rate
-b 1536 is the bitrate
-ac 2 are the channels (stereo)

the option
-v 48
is the debug on to visualize errors and system messages, you can reduce to less verbose if needed. I like to see what is going on ;-)
Under these conditions, the overall load of the PI3 CPU is less than 30% and I do not notice any interruption on the stream.


I am still not able to play the stream from the browser.
Right now if I point the browser to the stream's URL, the browser start downloading the file...which is supposed to be infinite :-) and nothing happens.
There is a mention on the documentation about the redirection, if someone could chime on that would be great help!

Also, note the screenshot of the stat.html auto generated page that shows the stream is finally on the RECEIVE DATA state and the bandwidth used by one connection (1536k)
Thanks!!
Screen Shot 2017-05-18 at 5.28.18 PM.png
Screen Shot 2017-05-18 at 5.28.18 PM.png (104.9 KiB) Viewed 5237 times
Last edited by abonam on Tue May 23, 2017 1:20 pm, edited 1 time in total.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests