Internet radio with nginx-rtmp

With nginx-rtmp it’s easy to set up internet radio channel. Here’s a simple bash script for that.

while true; do
    ffmpeg -re -i "`find /var/music -type f -name '*.mp3'|sort -R|head -n 1`" -vn -c:a libfaac -ar 44100 -ac 2 -f flv rtmp://localhost/myapp/radio;
done


The script takes random mp3 files from /var/music hierarchy and publishes them to nginx-rtmp.

Server-side configuration is simple.

application myapp {
    live on;
}

On client side you can use any flash player.

Advertisements
  1. #1 by Vladimir on December 12, 2012 - 12:19 am

    Установил сегодня самый актуальный ffmpeg, но при выполнении выдает:
    “unknown encoder libfaac”

    • #2 by rarut on December 12, 2012 - 5:43 am

      Используйте libmp3lame вместо него или nellymoser. Если вы его собираете руками надо явно указывать libfaac/libmp3lame при конфигурации.

      • #3 by Vladimir on December 12, 2012 - 8:50 pm

        Спасибо, уже разобрался и установил libfaac.
        Дополненный конфиг для ffmpeg будет такой:
        ./configure –prefix=/opt/ffmpeg –disable-yasm –enable-shared –enable-libx264 –enable-libfaac –enable-gpl –enable-nonfree

  2. #4 by Vladimir on December 12, 2012 - 3:03 am

    Использую экспериментальный aac () кодек, но все-равно пока не получается запустить поток.

    Для отладки использую этот сервис: http://support.akamai.com/flash/index.html

    Вывод лога этого сервиса:
    =========== New Test #1 ===========
    [2] Date: Wed Dec 12 2012
    [2] Time: 06:55:33 GMT+0400
    [2] Flash version: WIN 11,5,31,2
    [3] OS: Windows 7
    [3] Client IP: 188.134.46.202
    [3] Override server IP: false
    [3] Stop after first good connection: true
    [4] Preferred buffer length: 3 seconds
    [4] Use fast start buffer: false
    [5] Raw source: rtmp://95.211.125.229/myapp/radio
    [5] Source type: AMD_ONDEMAND
    [9] Host name: 95.211.125.229
    [10] App name: myapp
    [10] Stream name: radio
    [11] Making IDENT request to: http://95.211.125.229/fcs/ident
    [107] Showing alert to user: ERROR CALLING IDENT

    Настройки сервера такие:

    root@stream:~# nginx -V
    nginx version: nginx/1.3.9
    built by gcc 4.4.5 (Debian 4.4.5-8)
    TLS SNI support enabled
    configure arguments: –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-client-body-temp-path=/var/lib/nginx/body –http-fastcgi-temp-path=/var/lib/nginx/fastcgi –http-log-path=/var/log/nginx/access.log –http-proxy-temp-path=/var/lib/nginx/proxy –lock-path=/var/lock/nginx.lock –pid-path=/var/run/nginx.pid –with-debug –with-http_dav_module –with-http_flv_module –with-http_gzip_static_module –with-http_realip_module –with-http_stub_status_module –with-http_ssl_module –with-http_sub_module –with-ipv6 –with-mail –with-mail_ssl_module –add-module=/usr/build/nginx-rtmp-module –add-module=/usr/build/nginx-rtmp-module/hls –with-cc-opt=-I/opt/ffmpeg/include –with-ld-opt=’-L/opt/ffmpeg/lib -Wl,-rpath=/opt/ffmpeg/lib’

    root@stream:~# ffmpeg
    ffmpeg version N-47740-g801b315 Copyright (c) 2000-2012 the FFmpeg developers
    built on Dec 11 2012 23:14:10 with gcc 4.4.5 (Debian 4.4.5-8)
    configuration: –prefix=/opt/ffmpeg –disable-yasm –enable-shared
    libavutil 52. 12.100 / 52. 12.100
    libavcodec 54. 79.102 / 54. 79.102
    libavformat 54. 49.101 / 54. 49.101
    libavdevice 54. 3.102 / 54. 3.102
    libavfilter 3. 26.102 / 3. 26.102
    libswscale 2. 1.103 / 2. 1.103
    libswresample 0. 17.102 / 0. 17.102

    root@stream:~# cat ./radio
    #! /bin/bash
    while true; do
    ffmpeg -re -i “`find /var/music -type f -name ‘*.mp3’|sort -R|head -n 1`” -vn -c:a aac -strict -2 -ar 44100 -ac 2 -f flv rtmp://9 5.211.125.229/myapp/radio;

    root@stream:~# ./radio
    ffmpeg version N-47740-g801b315 Copyright (c) 2000-2012 the FFmpeg developers
    built on Dec 11 2012 23:14:10 with gcc 4.4.5 (Debian 4.4.5-8)
    configuration: –prefix=/opt/ffmpeg –disable-yasm –enable-shared
    libavutil 52. 12.100 / 52. 12.100
    libavcodec 54. 79.102 / 54. 79.102
    libavformat 54. 49.101 / 54. 49.101
    libavdevice 54. 3.102 / 54. 3.102
    libavfilter 3. 26.102 / 3. 26.102
    libswscale 2. 1.103 / 2. 1.103
    libswresample 0. 17.102 / 0. 17.102
    [mp3 @ 0x19f8280] max_analyze_duration 5000000 reached at 5015510
    Input #0, mp3, from ‘/var/music/Vecherniy Leningrad (mp3)/2 б▀б·б│б┬б▓ б█б─б≤ б█б─б░б▌б└ (б╗бґц║ц╒ц═.).mp3’:
    Metadata:
    encoder : LAME 32bits version 3.99.5 (http://lame.sf.net)
    artist : п⌡п╣пҐп╦пҐпЁя─п╟пЄ
    album : п▓п╣я┤п╣я─пҐп╦п╧ п⌡п╣пҐп╦пҐпЁя─п╟пЄ
    track : 2/11
    copyright : http://www.sosimc.ru
    publisher : http://www.sosimc.ru
    title : п⌡п╝п▒п≤п╒ п²п░п╗ п²п░п═п·п■ (п╦пҐя│я┌я─.)
    date : 2012
    Duration: 00:03:03.82, start: 0.000000, bitrate: 321 kb/s
    Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 320 kb/s
    Stream #0:1: Video: mjpeg, yuvj420p, 450×450 [SAR 72:72 DAR 1:1], 90k tbr, 90k tbn, 90k tbc
    Metadata:
    title :
    comment : Cover (front)
    Output #0, flv, to ‘rtmp://95.211.125.229/myapp/radio’:
    Metadata:
    date : 2012
    artist : п⌡п╣пҐп╦пҐпЁя─п╟пЄ
    album : п▓п╣я┤п╣я─пҐп╦п╧ п⌡п╣пҐп╦пҐпЁя─п╟пЄ
    track : 2/11
    copyright :
    publisher :
    title : п⌡п╝п▒п≤п╒ п²п░п╗ п²п░п═п·п■ (п╦пҐя│я┌я─.)
    encoder : Lavf54.49.101
    Stream #0:0: Audio: aac ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, 128 kb/s
    Stream mapping:
    Stream #0:0 -> #0:0 (mp3 -> aac)
    Press [q] to stop, [?] for help
    size= 148kB time=00:00:08.87 bitrate= 136.5kbits/s

  3. #5 by rarut on December 12, 2012 - 9:40 pm

    По логу все нормально. А в чем, собственно, проблема? Не играет? Попробуйте ffplay для начала. Кстати сайт аналогичный вашему есть у JWPlayer, попробуйте там.

    • #6 by Vladimir on December 12, 2012 - 9:54 pm

      С этим разобрался, спасибо.

      Теперь буду разбираться, как брать сторонний rtmp поток с CDN сервиса и транслировать его на iOS в HLS.

  4. #7 by Vineet on January 8, 2013 - 10:32 am

    Hi,
    The problem with looping through ffmpeg command is that rtmp service “ends” the transmission upon completion of first song. And the flash player stops there thinking the broadcast has ended. The next published stream can be played after pressing the play button on flash player. However, this issue doesn’t happen always

    Thanks

    • #8 by rarut on January 9, 2013 - 5:30 am

      what’s your player? Jw doesn’t stop.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: