savonet / liquidsoap

Liquidsoap is a statically typed scripting general-purpose language with dedicated operators and backend for all thing media, streaming, file generation, automation, HTTP backend and more.
http://liquidsoap.info
GNU General Public License v2.0
1.4k stars 130 forks source link

Flac stream is not playable. #328

Closed AttilaVM closed 8 years ago

AttilaVM commented 8 years ago

After succesfuly streaming aac and mp3 I tried to stream flac in a testing environment:

source client Liquidsoap-1.1.1-7 OS: Raspbian Jessie Hardware: Raspberry Pi 3 + Cirrus Logic Audio card notes: kernel rebuilt with official cross toolchain. source: https://github.com/HiassofT/rpi-linux The offical Cirrus Logic image and kernel are not working with rpi 3. Liquidsoap had to be rebuilt because of a packaging bug, causes "input.alsa undefined"

server icecast2-2.4.0-1.1+deb8u OS: Raspbian Jessie Hardware: Raspberry Pi 3

Listener mplayer-1.2.1 OS: Gentoo amd64 Hardware: a simple hp workstation note: it plays flac streams perfectly from othe sources like: http://ai-radio.org/44.flac

While aac and mp3 streams work (Not tested with many conditions), flac streams are not playable with mplayer.

Lquidsoap script:

output.icecast(
        %flac,
        host = "192.168.0.50",
        port = 8000,
        password = "test",
        mount = "test-stream",
        input.alsa()
)

Liquidsoap log:

2016/05/10 14:14:20 >>> LOG START
2016/05/10 14:14:19 [protocols.external:3] Found "/usr/bin/wget".
2016/05/10 14:14:19 [main:3] Liquidsoap 1.1.1
2016/05/10 14:14:19 [main:3] Using: graphics=[distributed with Ocaml] pcre=7.0.4 dtools=0.3.1 duppy=0.5.1 duppy.syntax=0.5.1 cry=0.2.2 mm=0.2.1 xmlplaylist=0.1.3 lastfm=0.3.0 ogg=0.4.5 vorbis=0.6.1 opus=0.1.0 speex=0.2.0 mad=0.4.4 flac=0.1.1 flac.ogg=0.1.1 dynlink=[distributed with Ocaml] lame=0.3.2 shine=0.2.0 gstreamer=0.2.0 frei0r=0.1.0 voaacenc=0.1.0 theora=0.3.0 schroedinger=0.1.0 gavl=0.1.5 bjack=0.1.4 alsa=0.2.1 ao=0.2.0 samplerate=0.1.2 taglib=0.3.1 magic=0.7.3 camomile=0.8.4 inotify=1.0 faad=0.3.2 soundtouch=0.1.7 portaudio=0.2.0 pulseaudio=0.1.2 ladspa=0.1.4 dssi=0.1.1 sdl=0.9.1 camlimages=4.0.0 lo=0.1.0 yojson=1.1.8 gd=1.0a5
2016/05/10 14:14:19 [dynamic.loader:3] Could not find dynamic module for fdkaac encoder.
2016/05/10 14:14:19 [dynamic.loader:3] Could not find dynamic module for aacplus encoder.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/lame.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/voaacenc.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/ao.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/mad.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/frei0r.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/flac.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/graphics.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/taglib.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/bjack.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/oss.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/pulseaudio.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/sdl.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/portaudio.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/cry.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/alsa.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/xmlplaylist.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/lo.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/soundtouch.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/samplerate.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/camlimages.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/ogg.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/speex.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/gavl.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/gd.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/shine.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/faad.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/gstreamer.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/ladspa.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/vorbis.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/flac_ogg.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/lastfm.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/dssi.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/theora.cmxs.
2016/05/10 14:14:19 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/opus.cmxs.
2016/05/10 14:14:20 [dynamic.loader:2] Loaded plugin file /usr/lib/liquidsoap/1.1.1/plugins/schroedinger.cmxs.
2016/05/10 14:14:20 [frame:3] Using 44100Hz audio, 25Hz video, 44100Hz master.
2016/05/10 14:14:20 [frame:3] Frame size must be a multiple of 1764 ticks = 1764 audio samples = 1 video samples.
2016/05/10 14:14:20 [frame:3] Targetting 'frame.duration': 0.04s = 1764 audio samples = 1764 ticks.
2016/05/10 14:14:20 [frame:3] Frames last 0.04s = 1764 audio samples = 1 video samples = 1764 ticks.
2016/05/10 14:14:20 [threads:3] Created thread "generic queue #1".
2016/05/10 14:14:20 [threads:3] Created thread "generic queue #2".
2016/05/10 14:14:20 [threads:3] Created thread "non-blocking queue #1".
2016/05/10 14:14:20 [threads:3] Created thread "non-blocking queue #2".
2016/05/10 14:14:20 [threads:3] Created thread "input.alsa_6149" (1 total).
2016/05/10 14:14:20 [input.alsa_6149:3] Using ALSA 1.0.28.
2016/05/10 14:14:20 [test-stream:3] Connecting mount test-stream for source@192.168.0.50...
2016/05/10 14:14:20 [test-stream:3] Connection setup was successful.
2016/05/10 14:14:20 [threads:3] Created thread "wallclock_alsa" (2 total).

Icecast2 configuration:

<icecast>
    <location>Earth</location>
    <admin>icemaster@localhost</admin>

    <limits>
        <clients>100</clients>
        <sources>2</sources>
        <threadpool>5</threadpool>
        <queue-size>1048576</queue-size>
        <client-timeout>30</client-timeout>
        <header-timeout>15</header-timeout>
        <source-timeout>20</source-timeout>
        <burst-on-connect>1</burst-on-connect>
        <burst-size>65535</burst-size>
    </limits>

    <authentication>
        <source-password>test</source-password>
        <relay-password>test</relay-password>
        <admin-user>admin</admin-user>
        <admin-password>test</admin-password>
    </authentication>

    <hostname>pi</hostname>    
    <listen-socket>
        <port>8000</port>
    </listen-socket>

    <fileserve>1</fileserve>

    <paths>
        <basedir>/usr/share/icecast2</basedir>
        <logdir>/var/log/icecast2</logdir>
        <webroot>/usr/share/icecast2/web</webroot>
        <adminroot>/usr/share/icecast2/admin</adminroot>
        <alias source="/" destination="/status.xsl"/>
    </paths>

    <logging>
        <accesslog>access.log</accesslog>
        <errorlog>error.log</errorlog>
        <loglevel>3</loglevel> 
        <logsize>10000</logsize> 
    </logging>

    <security>
        <chroot>0</chroot>
    </security>
</icecast>

icecast2 error log:

[2016-05-10  14:14:20] INFO connection/_handle_source_request Source logging in at mountpoint "/test-stream"
[2016-05-10  14:14:20] WARN format/format_get_type Unsupported or legacy stream type: "audio/x-flac". Falling back to generic minimal handler for best effort.
[2016-05-10  14:14:20] INFO source/source_main listener count on /test-stream now 0

note: The working aac and mp3 streams get same errors for their types without any problem.

mplayer output:

MPlayer 1.2.1-4.9.3 (C) 2000-2016 MPlayer Team

Playing http://192.168.0.50:8000/test-stream.
Resolving 192.168.0.50 for AF_INET6...

Couldn't resolve name for AF_INET6: 192.168.0.50
Connecting to server 192.168.0.50[192.168.0.50]: 8000...

Name   : test-stream
Genre  : Misc
Website: http://savonet.sf.net
Public : yes
Cache size set to 320 KBytes
Cache fill:  0.00% (0 bytes)   
ICY Info: StreamTitle='';

Exiting... (End of file)

I also checked the stream between Liquidsoap and Icecast2 with scapy

0316 Ether / IP / TCP 192.168.0.53:50694 > 192.168.0.50:8000 A / Raw
0317 Ether / IP / TCP 192.168.0.53:50694 > 192.168.0.50:8000 A / Raw
0318 Ether / IP / TCP 192.168.0.50:8000 > 192.168.0.53:50694 A
0319 Ether / IP / TCP 192.168.0.53:50694 > 192.168.0.50:8000 A / Raw
0320 Ether / IP / TCP 192.168.0.53:50694 > 192.168.0.50:8000 A / Raw
0321 Ether / IP / TCP 192.168.0.50:8000 > 192.168.0.53:50694 A
0322 Ether / IP / TCP 192.168.0.53:50694 > 192.168.0.50:8000 PA / Raw
0323 Ether / IP / TCP 192.168.0.50:8000 > 192.168.0.53:50694 A
0324 ba:27:eb:f8:fd:f9 > b8:27:eb:f8:fd:f9 (0x886c) / Raw
0325 ba:27:eb:f8:fd:f9 > b8:27:eb:f8:fd:f9 (0x886c) / Raw
0326 ba:27:eb:f8:fd:f9 > b8:27:eb:f8:fd:f9 (0x886c) / Raw
0327 ba:27:eb:f8:fd:f9 > b8:27:eb:f8:fd:f9 (0x886c) / Raw
0328 ba:27:eb:f8:fd:f9 > b8:27:eb:f8:fd:f9 (0x886c) / Raw
0329 ba:27:eb:f8:fd:f9 > b8:27:eb:f8:fd:f9 (0x886c) / Raw
0330 ba:27:eb:f8:fd:f9 > b8:27:eb:f8:fd:f9 (0x886c) / Raw
0331 Ether / IP / TCP 192.168.0.53:50694 > 192.168.0.50:8000 A / Raw
0332 Ether / IP / TCP 192.168.0.53:50694 > 192.168.0.50:8000 A / Raw
0333 Ether / IP / TCP 192.168.0.50:8000 > 192.168.0.53:50694 A
0334 Ether / IP / TCP 192.168.0.53:50694 > 192.168.0.50:8000 A / Raw
0335 Ether / IP / TCP 192.168.0.53:50694 > 192.168.0.50:8000 A / Raw
0336 Ether / IP / TCP 192.168.0.50:8000 > 192.168.0.53:50694 A
0337 Ether / IP / TCP 192.168.0.53:50694 > 192.168.0.50:8000 PA / Raw
0338 Ether / IP / TCP 192.168.0.50:8000 > 192.168.0.53:50694 A

note: source client: 192.168.0.53, b8:27:eb:90:55:eb server: 192.168.0.51, b8:27:eb:f8:fd:f9

AttilaVM commented 8 years ago

I found out %ogg(%flac)...

The script below works fine:

output.icecast(
        %ogg(%flac),
        host = "192.168.0.50",
        port = 8000,
        password = "test",
        mount = "test-stream",
        input.alsa()
)
daniel-j commented 8 years ago

Have you tried streaming flac inside the ogg container, as the documentation says: http://liquidsoap.fm/doc-svn/encoding_formats.html Was a while ago I used it, but I remember the flac encoder that's built-in sounded bad in some players. I solved it by using an external flac encoder: https://github.com/daniel-j/parasprite-radio/blob/master/liq/outputs.liq#L114 A downside with that is the lack of metadata, and stream restarts every 6th hour or so.

AttilaVM commented 8 years ago

Thanks, Using external encoder is a good idea The ogg encapsulation works. However it can not encode 32 bit flac. However it would be very nice. The Cirrus Logic card has 24 bit ADCs.

it gives: Source test-stream failed while streaming: Flac.Internal! Maybe an external streamer will solve it, thank you

AttilaVM commented 8 years ago

Thank you. I used your advice and it works with the external streamer perfectly even on 24 bit. Why the stream restarts periodically?

toots commented 8 years ago

Hey guys. The stream restarts periodically prolly because the external encoding binary isn't supposed to run forever. As for the metadata, with icecast and ogg streaming you may want to try to use icy.update_metadata I know that for ogg/vorbis, icecast is capable of inserting metadata into the stream when using this operator.

I will have a look at why our internal encoder may not perform as well as the flac encoding binary.

toots commented 8 years ago

Here's what the flac manual says about quality:

       -0..-8, --compression-level-0..--compression-level-8
              Fastest compression..highest compression (default is -5).  These are synonyms for other options:

              -0, --compression-level-0
                     Synonymous with -l 0 -b 1152 -r 3

              -1, --compression-level-1
                     Synonymous with -l 0 -b 1152 -M -r 3

              -2, --compression-level-2
                     Synonymous with -l 0 -b 1152 -m -r 3

              -3, --compression-level-3
                     Synonymous with -l 6 -b 4096 -r 4

              -4, --compression-level-4
                     Synonymous with -l 8 -b 4096 -M -r 4

              -5, --compression-level-5
                     Synonymous with -l 8 -b 4096 -m -r 5

              -6, --compression-level-6
                     Synonymous with -l 8 -b 4096 -m -r 6 -A tukey(0.5) -A partial_tukey(2)

              -7, --compression-level-7
                     Synonymous with -l 8 -b 4096 -m -e -r 6 -A tukey(0.5) -A partial_tukey(2)

              -8, --compression-level-8
                     Synonymous with -l 12 -b 4096 -m -e -r 6 -A tukey(0.5) -A partial_tukey(2) -A punchout_tukey(3)

       --fast Fastest compression.  Currently synonymous with -0.

       --best Highest compression.  Currently synonymous with -8.

So, I believe that if you set compression=8 in the %flac encoding params, that should be the same as --best using the external flac encoder.

lelos09 commented 8 years ago

Hi, could somebody help me how can i install external flac encoder at liquidsoap? I run it at raspbian with internal encoder but sound is not good.

smimram commented 8 years ago

For such questions, the mailing-list would be more suitable: savonet-users@lists.sf.net