Przesyłanie audio na żywo

Wpis powstał pod wpływem konkursu ogłoszonego na portalu openrouter.info. Zadaniem było przedstawienie kompletnej, i działającej instrukcji instalacji coś w rodzaju podsłuchu na OpenWrt. Generalnie dźwięk z mikrofonu musi być zarejestrowany w postaci nagrania - pliku oraz upubliczniony w postaci strumienia MP3 lub OGG.

Wymagania sprzętowe

Od strony sprzętowej musimy posiadać kartę dźwiękowa lub kamerę z mikrofonem. Poniższy opis dotyczy taniej kartę 3D Audio na chipie CMedia.

Wymagania programowe

Trzeba mieć zainstalowane USB oraz USB Audio. Warto też mieć podmontowany dysk USB do przechowywania nagranego materiału. Pozatym potrzebujemy:

Kodek OGG lub MP3

opkg update 
opkg install libvorbis lame

Serwer strumieni.

opkg install icecast

oraz któreś ze źródeł strumienia

ices(ogg):

 opkg install ices

darkice(mp3):

opkg install http://openwrt.pl/dl/pakiety/darkice_1.0-2_ar71xx.ipk

Dodatkowe narzędzia

Można zainstalować dodatkowo narzędzia alsy np. po to aby wyregulować czułość mikrofonu oraz poziom głośności głośników. W przypadku źródła z oss też można się tym posłużyć.

opkg install alsa-utils

musimy dodać grupę audio

echo "audio:x:1000:" >> /etc/group

Uruchamiamy alsamixer i regulujemy słupkami, wychodzimy ESC

alsamixer --view=all

Składamy do kupy

Źródło - ices (ogg)

Na początku ices, czyli źródło audio

Tworzymy plik /etc/ices.xml o zawartości:

<?xml version="1.0"?>
<ices>
  <background>1</background>
  <logpath>/var/log/ices</logpath>
  <logfile>ices.log</logfile>
  <logsize>2048</logsize>
  <loglevel>4</loglevel>
  <consolelog>0</consolelog>
  <stream>
      <!-- metadata used for stream listing -->
      <metadata>
          <name>Podsluch</name>
          <genre>Speech</genre>
          <description>Na zywo!</description>
          <url>http://openwrt.pl</url>
      </metadata>   
      <input>
          <module>oss</module>
          <param name="rate">44100</param>
          <param name="channels">2</param>
          <param name="device">/dev/dsp</param>
          <!-- Read metadata (from stdin by default, or -->
          <!-- filename defined below (if the latter, only on SIGUSR1) -->
          <param name="metadata">1</param>
          <param name="metadatafilename">mic.ogg</param>
      </input>
      <instance>
          <hostname>localhost</hostname>
          <port>8000</port>
          <password>tajnehaslozrodla</password>
          <mount>/mic.ogg</mount>
          <yp>0</yp>
          <encode>
              <quality>0</quality>
              <samplerate>22050</samplerate>
              <channels>1</channels>
          </encode>
          <downmix>1</downmix>
          <savefile>/mnt/hdd/stream_mic.ogg</savefile>
          <resample>
              <in-rate>44100</in-rate>
              <out-rate>22050</out-rate>
          </resample>
      </instance>
  </stream>
</ices>

Musimy też utworzyć katalog logów

mkdir /var/log/ices

Ważne opcje:

<savefile>/mnt/hdd/stream_mic.ogg</savefile> - lokalizacja do pliku w którym będzie znajdować się nagrywany materiał

Źródło - darkice (mp3)

Konfiguracja darkice mieści się w pliku /etc/darkice.cfg

# this section describes general aspects of the live streaming session
[general]
duration        = 0        # duration of encoding, in seconds. 0 means forever
bufferSecs      = 25       # size of internal slip buffer, in seconds
reconnect       = yes      # reconnect to the server(s) if disconnected
# this section describes the audio input that will be streamed
[input]
device          = /dev/dsp  # OSS DSP soundcard device for the audio input
sampleRate      = 22050     # sample rate in Hz. try 11025, 22050 or 44100
bitsPerSample   = 16        # bits per sample. try 16
channel         = 1         # channels. 1 = mono, 2 = stereo
# this section describes a streaming connection to an IceCast2 server
# there may be up to 8 of these sections, named [icecast2-0] ... [icecast2-7]
# these can be mixed with [icecast-x] and [shoutcast-x] sections
[icecast2-0]
bitrateMode     = cbr       # average bit rate
format          = mp3       # format of the stream: mp3
bitrate         = 64
server          = localhost
                          # host name of the server
port            = 8000      # port of the IceCast2 server, usually 8000
password        = tajnehaslozrodla    # source password to the IceCast2 server
mountPoint      = mic.mp3  # mount point of this stream on the IceCast2 server
name            = Pluskwa
                          # name of the stream
description     = Podsluch w OpenWrt
                         # description of the stream
url             = http://www.openwrt.pl
                          # URL related to the stream
genre           = Mowa    # genre of the stream
public          = yes       # advertise this stream?
localDumpFile   = /mnt/hdd/dump.mp3  # local dump file

Powyższa konfiguracja jest w sam raz dla źródła z mikrofonu. Lepsza jakość odbija się na większym obciążeniu procesora routera. Hasło, port i adres serwera odpowiadają wartościom ustawionym z icecast.

Serwer icecast

Pozostaje ustawić serwer strumieni:

<icecast>
  <limits>
      <clients>5</clients>
      <sources>2</sources>
      <threadpool>10</threadpool>
      <queue-size>524288</queue-size>
      <client-timeout>15</client-timeout>
      <header-timeout>25</header-timeout>
      <source-timeout>20</source-timeout>
      <burst-on-connect>1</burst-on-connect>
      <burst-size>65535</burst-size>
  </limits>
  <authentication>
      <!-- Sources log in with username 'source' -->
      <source-password>tajnehaslozrodla</source-password>
      <!-- Relays log in username 'relay' -->
      <relay-password>tajnehaslo</relay-password>
      <!-- Admin logs in with the username given below -->
      <admin-user>admin</admin-user>
      <admin-password>tajnehasloadmina</admin-password>
  </authentication>
  <hostname>localhost</hostname>
  <listen-socket>
      <port>8000</port>
  </listen-socket>
  <fileserve>1</fileserve>
  <paths>
      <basedir>/usr/share/icecast</basedir>
      <logdir>/var/log/icecast</logdir>
      <webroot>/usr/share/icecast/web</webroot>
      <adminroot>/usr/share/icecast/admin</adminroot>
      <alias source="/" dest="/status.xsl"/>
  </paths>
  <logging>
      <accesslog>access.log</accesslog>
      <errorlog>error.log</errorlog>
    	<loglevel>3</loglevel> <!-- 4 Debug, 3 Info, 2 Warn, 1 Error -->
    	<logsize>10000</logsize> <!-- Max size of a logfile -->
  </logging>
  <security>
      <chroot>0</chroot>     
      <changeowner>
          <user>nobody</user>
          <group>nogroup</group>
      </changeowner>
  </security>
</icecast>

Katalog do logowania

mkdir /var/log/icecast

Prawa dla nobody do katalogu logowania

chown nobody.nogroup /var/log/icecast

Nadajemy w "eter"

Uruchamiamy serwer(leci w tło):

icecast -b -c /etc/icecast.xml

oraz źródło ices:

ices /etc/ices.xml

lub darkice

darkice & > /dev/null

Podsumowanie

Po uruchomieniu serwera strumieni i źródła możemy wejśc na stronę web serwera icecast pod adresem http://ip-routera:8000. Adres strumienia jako playlistę: http://ip-routera:8000/mic.ogg.m3u lub http://ip-routera:8000/mic.mp3.m3u.

Icecast dostarcza również player we Flashu po adresami http://ip-routera:8000/mic.ogg. lub http://ip-routera:8000/mic.mp3

Autor wpisu zaleca użycie darkice ponieważ nadaje strumień w mp3, co jest kompatybilne z większością odtwarzaczy(WMP, foobar2000, vlc), pozatym darkice ma jeszcze jedna zaletę, małe opóźnienie - zaledwie klika sekund.

W przypadku Windows Media Player i strumienia w ogg niezbędne są kodeki ze strony http://xiph.org/dshow/

zastosowania/streaming-audio.txt · ostatnio zmienione: 2010/10/21 21:19 przez arteq
CC Attribution-Noncommercial-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki Recent changes RSS feed Valid XHTML 1.0
Profesjonalny Hosting