Transcode dvb-s ts radio stream (mp2) to aac for Sonos playback (audio-only)
Added by Marco D almost 6 years ago
Hi,
I want to be able to listen to some radio stations from my DVB-C Linux receiver by using my Sonos speakers. Unfortunately Sonos only accepts mp3, aac or wma for "web radio", no mp2.
input: ts file containing a MPEG-I Layer 2 (mp2) audio stream with 320kbps
desired output: aac 320kbps
I'm using a Raspberry Pi 3b+ for this, already spent 12hrs(+) trying to build a tvheadend from scratch with activated transcoding without success so I gave up on this. But maybe I don't need this in the first place?
I already setup tvheadend (4.3 unstable, raspbian-jessie) to receive the channels and strip the audio using the stream profile "audio" (pass-through). Now I need to convert this on-the-fly using ffmpeg and the MPEG-TS Spawn/built-in template, correct?
How should the ffmpeg command look like? Something like
/usr/local/bin/ffmpeg -i pipe:0 -c:a aac -b:a 320k -threads 2 ...(?)
Thanks in advance!
Replies (22)
RE: Convert dvb ts radio stream to mp3 for Sonos (audio-only) - Added by saen acro almost 6 years ago
Audio stream profile isn't working in you case?
RE: Convert dvb ts radio stream to mp3 for Sonos (audio-only) - Added by Marco D almost 6 years ago
Not with Sonos.
So what I did is select audio as default stream profile and setting Audio-Type to MPEG2-audio.
With VLC, Volumio or Safari I can listen to the stream using this url:
http://sonos:[email protected]:9981/stream/channelnumber/0
But when I try to add this exact stream url to Sonos I get a "Server not found" error message. Nothing in the logs. When I remove the username/password at the beginning of the url, I can see in the TV Headend log:
2019-01-05 12:03:16.784 http: 192.168.178.102: RTSP/1.0 DESCRIBE (4) rtsp://192.168.178.50:9981/stream/channelnumber/0 -- 400
Why rtsp?
RE: Convert dvb ts radio stream to mp3 for Sonos (audio-only) - Added by saen acro almost 6 years ago
in local network you can use access via * user limited to your network 192.168.178.0/24
about audio
https://support.sonos.com/s/article/79?language=en_US
there is FLAC/AAC output in TVH
RE: Convert dvb ts radio stream to mp3 for Sonos (audio-only) - Added by Marco D almost 6 years ago
OK, in the meantime I already granted access to * so the connection from Sonos to tvheadend basically works. The stream still won't play.
Sean Sean arco:
If you scroll down on your link you will see at the end of the article that flac is not supported for web radio, just for local music. But I have to integrate it as a web radio:
Streaming Internet radio
Supported Internet radio audio formats:
MP3
AAC
WMA
And even if it would support flac/aac, I don't get how I can configure the conversion from mp2 to flac in tvheadend.
RE: Convert dvb ts radio stream to mp3 for Sonos (audio-only) - Added by saen acro almost 6 years ago
in Codec profile tab
create AAC profile
tune it as you want
in Stream profiles
create Transcode/av-lib
select container mpegts or mp4 /not sure with will work/
select audio profile you created
http://192.168.178.50:9981/stream/channelnumber/0?profile=YOUR-PROFILE
RE: Convert dvb ts radio stream to mp3 for Sonos (audio-only) - Added by Marco D almost 6 years ago
And this is exactly my problem since I'm using a Raspberry Pi (3b+). There is no transcoding, no codec profile whatsoever. ;-(
As I said I spent the whole day yesterday (12hrs+) trying to build a tvheadend for the pi with transcoding but I failed. I tried hundreds of ways, versions, static and non-static ffmpeg etc. but I never achieved to run through the build.
RE: Convert dvb ts radio stream to mp3 for Sonos (audio-only) - Added by saen acro almost 6 years ago
That's why need to provide as match as possible information.
Start to read about IceCast
RE: Convert dvb ts radio stream to mp3 for Sonos (audio-only) - Added by Marco D almost 6 years ago
All this information has been in my first post.
So this is how far I got:
I created a stream template of type "MPEG-TS Spawn/built-in" with the following command (aac 320kbps as mp3 or liblame is not available):
/usr/local/bin/ffmpeg -re -i pipe:0 -c:a aac -b:a 320k -f matroska pipe:1
Mime-Type is "audio/mp4".
This is the output:
2019-01-05 14:46:18.850 spawn: Executing "/usr/local/bin/ffmpeg"
2019-01-05 14:46:18.866 spawn: ffmpeg version git-2019-01-04-5faa1b8 Copyright (c) 2000-2019 the FFmpeg developers
2019-01-05 14:46:18.867 spawn: built with gcc 4.9.2 (Raspbian 4.9.2-10+deb8u2)
2019-01-05 14:46:18.867 spawn: configuration: --enable-gpl --enable-nonfree --enable-mmal --enable-omx --enable-omx-rpi
2019-01-05 14:46:18.867 spawn: libavutil 56. 25.100 / 56. 25.100
2019-01-05 14:46:18.867 spawn: libavcodec 58. 43.100 / 58. 43.100
2019-01-05 14:46:18.867 spawn: libavformat 58. 25.100 / 58. 25.100
2019-01-05 14:46:18.867 spawn: libavdevice 58. 6.101 / 58. 6.101
2019-01-05 14:46:18.867 spawn: libavfilter 7. 46.101 / 7. 46.101
2019-01-05 14:46:18.867 spawn: libswscale 5. 4.100 / 5. 4.100
2019-01-05 14:46:18.867 spawn: libswresample 3. 4.100 / 3. 4.100
2019-01-05 14:46:18.867 spawn: libpostproc 55. 4.100 / 55. 4.100
2019-01-05 14:46:25.478 spawn: Input #0, mpegts, from 'pipe:0':
2019-01-05 14:46:25.478 spawn: Duration: N/A, start: 79417.273411, bitrate: 320 kb/s
2019-01-05 14:46:25.479 spawn: Program 1
2019-01-05 14:46:25.479 spawn: Stream #0:0[0xf01](deu): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 320 kb/s
2019-01-05 14:46:25.494 spawn: Stream mapping:
2019-01-05 14:46:25.495 spawn: Stream #0:0 -> #0:0 (mp2 (native) -> aac (native))
2019-01-05 14:46:25.508 spawn: Output #0, matroska, to 'pipe:1':
2019-01-05 14:46:25.509 spawn: Metadata:
2019-01-05 14:46:25.509 spawn: encoder : Lavf58.25.100
2019-01-05 14:46:25.509 spawn: Stream #0:0(deu): Audio: aac (LC) ([255][0][0][0] / 0x00FF), 48000 Hz, stereo, fltp, 320 kb/s
2019-01-05 14:46:25.510 spawn: Metadata:
2019-01-05 14:46:25.510 spawn: encoder : Lavc58.43.100 aac
2019-01-05 14:46:26.003 spawn: size= 1kB time=00:00:00.47 bitrate= 9.9kbits/s speed=0.925x
2019-01-05 14:46:26.504 spawn: size= 33kB time=00:00:00.98 bitrate= 274.3kbits/s speed=0.973x
2019-01-05 14:46:27.013 spawn: size= 33kB time=00:00:01.49 bitrate= 180.3kbits/s speed=0.984x
2019-01-05 14:46:27.520 spawn: size= 65kB time=00:00:01.98 bitrate= 270.4kbits/s speed=0.98x
2019-01-05 14:46:28.021 spawn: size= 65kB time=00:00:02.49 bitrate= 215.0kbits/s speed=0.988x
2019-01-05 14:46:28.525 spawn: size= 98kB time=00:00:02.98 bitrate= 268.4kbits/s speed=0.986x
2019-01-05 14:46:29.034 spawn: size= 130kB time=00:00:03.49 bitrate= 304.3kbits/s speed=0.989x
2019-01-05 14:46:29.546 spawn: size= 130kB time=00:00:04.01 bitrate= 265.4kbits/s speed=0.991x
2019-01-05 14:46:30.040 spawn: size= 163kB time=00:00:04.50 bitrate= 296.1kbits/s speed=0.99x
2019-01-05 14:46:30.554 spawn: size= 163kB time=00:00:05.03 bitrate= 264.8kbits/s speed=0.996x
2019-01-05 14:46:31.063 spawn: size= 195kB time=00:00:05.54 bitrate= 288.6kbits/s speed=0.997x
2019-01-05 14:46:31.447 spawn: av_interleaved_write_frame(): Broken pipe
2019-01-05 14:46:31.476 spawn: Error writing trailer of pipe:1: Broken pipe
2019-01-05 14:46:31.476 spawn: size= 195kB time=00:00:05.93 bitrate= 269.9kbits/s speed=0.991x
2019-01-05 14:46:31.476 spawn: video:0kB audio:227kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
2019-01-05 14:46:31.479 spawn: [aac @ 0x1bd0990] Qavg: 24347.391
2019-01-05 14:46:31.479 spawn: Conversion failed!
RE: Convert dvb ts radio stream to mp3 for Sonos (audio-only) - Added by saen acro almost 6 years ago
Are you sure about MKV container?
RE: Convert dvb ts radio stream to mp3 for Sonos (audio-only) - Added by Marco D almost 6 years ago
Absolutely not sure, I tried all kinds of different conainers with different results bot no success. Actually that was my initial question: how should the ffmpeg command look like and what container to use for radio streaming?
RE: Convert dvb ts radio stream to mp3 for Sonos (audio-only) - Added by saen acro almost 6 years ago
RE: Convert dvb ts radio stream to mp3 for Sonos (audio-only) - Added by Marco D almost 6 years ago
Found a docker image for the Pi with activated transcoding.
Configured transcoding > no video > audio aac > mpegts. Works flawless in VLC but not in Sonos. It keeps restarting and after a few attempts the Sonos controller sais that the network audio buffer would be too small. Tried other containers as well (without luck).
Anyway, I give up. If only Sonos would support mp2 playback.
RE: Convert dvb ts radio stream to mp3 for Sonos (audio-only) - Added by saen acro almost 6 years ago
There is lot of settings for AAC switch to Expert in general settings and try different combinations.
Profile for example.
RE: Transcode dvb-s ts radio stream (mp2) to aac for Sonos playback (audio-only) - Added by Marco D almost 6 years ago
I finally have a working stream on Sonos - kind of.
The solution is to choose „Raw Audio Stream“ as output container.
The stream works for about a minute with ~45% CPU usage on the Pi (3b+). Then all of a sudden the tvheadend process eats up >100% CPU, the UI gets unusable and the stream breaks. It might get back to normal after some time but then start all over again. This happens with both the latest 4.2 as well as 4.3 releases. It happens with VLC client as well as with Sonos.
I already tried to deactivate everything which is possible, so no epg crawler, no refresh, no service scans, no magic at all. Still the same behaviour. The log in the GUI doesn’t show anything suspicious. Is there another way how I can try to find the issue?
RE: Transcode dvb-s ts radio stream (mp2) to aac for Sonos playback (audio-only) - Added by saen acro almost 6 years ago
Use command
top -H
RE: Transcode dvb-s ts radio stream (mp2) to aac for Sonos playback (audio-only) - Added by Marco D almost 6 years ago
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
24455 911 20 0 113236 20960 14288 R 99.2 2.2 0:10.41 tvh:sharer
Any clue?
RE: Transcode dvb-s ts radio stream (mp2) to aac for Sonos playback (audio-only) - Added by saen acro almost 6 years ago
Add new issue
RE: Transcode dvb-s ts radio stream (mp2) to aac for Sonos playback (audio-only) - Added by Marco D almost 6 years ago
Coming back to ffmpeg, what would be the equivalent of the "Raw Audio Stream" output from the tvheadend transcoder?
-f ...(?)
RE: Transcode dvb-s ts radio stream (mp2) to aac for Sonos playback (audio-only) - Added by saen acro almost 6 years ago
Raw audio will be same as input
https://www.smarthomebeginner.com/icecast-ices2-music-server-for-raspberry-pi-raspberry-pi-streaming-audio-server/
then you can use playlist from tvh
https://www.instructables.com/id/Add-Aux-to-Sonos-Using-Raspberry-Pi/
RE: Transcode dvb-s ts radio stream (mp2) to aac for Sonos playback (audio-only) - Added by Marco D almost 6 years ago
No, it can't be the same as the input because the input of a dvb radio stream is mp2 (MPEG I, Layer 2) and Sonos needs AAC. Therefore I have to use transcoding which converts mp2 to aac. But it's also important that the output format is set to "Raw Audio Stream" because Sonos doesn't like containers that might contain video like mpegts or mkv. The "Raw audio stream" output format feature has been introduced in tvheadend about 2 years ago (version 4.1-2267 see also https://tvheadend.org/boards/5/topics/22853).
That's why I'm curious if it's possible to configure this output option with ffmpeg manually and how it would look like (instead of "...-f mpegts pipe:1" which definetly won't work).
I would love to use it with plain tvheadend transcoding but unfortunately the CPU goes beyond 100% after some minutes, no matter which version, no. matter which Pi (2, 3b+), no matter whether running it natively or inside a docker container.
RE: Transcode dvb-s ts radio stream (mp2) to aac for Sonos playback (audio-only) - Added by saen acro almost 6 years ago
RE: Transcode dvb-s ts radio stream (mp2) to aac for Sonos playback (audio-only) - Added by asddasd asdasdsa almost 4 years ago
I created an issue: https://tvheadend.org/issues/5989
Addition: I made it work with a custom template using:
/usr/bin/ffmpeg -loglevel error -vn -re -i pipe:0 -ar 44100 -ac 2 -q:a 2 -c:a libmp3lame -f mp3 pipe:1
Mime type: audio/mp3