RTMP source to HLS (HTTP Live Streaming) Apple

Traducció de l’original en anglès. Llegeix-lo en: CastellanoEnglish

Acabo de resoldre un problema molt específic i he d'escriure unes notes aquí per recordar la solució. Donada una font RTMP, hem d'enviar el contingut en streaming a dispositius Apple com iPad, iPhone i iPod, perquè l'RTMP no es podia reproduir amb el navegador Safari.

Si necessitem reproduir streaming en dispositius Apple, la millor solució és convertir-lo a HLS i publicar els fitxers generats mitjançant un servidor HTTP.

Per resoldre aquest problema faig servir rtmpdump i vlc. Primer rtmpdump obté el flux de vídeo de la font. Després el flux s'envia a vlc i finalment vlc transcodifica el vídeo i l'àudio i genera petits fitxers .ts i un fitxer índex .m3u8.

La comanda és una cosa com aquesta:

rtmpdump -v -r "$RTMP" | sudo -u xymon vlc -I dummy fd://0 vlc://quit --sout="#transcode{width=320,height=240,fps=25,vcodec=h264,vb=256,venc=x264{aud,profile=baseline,level=30,keyint=30,ref=1,nocabac},acodec=mp3,ab=96,audio-sync,deinterlace,channels=2,samplerate=44100}:std{access=livehttp{seglen=10,delsegs=true,numsegs=5,index=$M3U8,index-url=$TS_URL},mux=ts{use-key-frames},dst=$TSF}"

Les descripcions de les variables són:

RTMP=rtmp://example.tld/path/stream_id
WD=/local_path
TS=live-####.ts
TSF=$WD/$TS
TS_URL=http://example.tld/path/$TS
M3U8=$WD/live.m3u8

A continuació creeu un fitxer HTML, per exemple live.html, amb una referència al fitxer .m3u8; el codi rellevant del fitxer HTML és així:

<video width="320" height="240"><source src="http://example.tld/path/live.m3u8" /></video>

Un codi senzill per publicar fitxers via HTTP:

python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"

Aleshores només cal obrir el navegador Safari al dispositiu Apple i posar l'URL adequada, en el nostre cas:

http://example.tld/path/live.html

NOTA IMPORTANT: la sortida d'àudio ha de ser amb dos canals i una freqüència de mostreig de 44KHz; en altres casos l'àudio falla.

5 comentaris

Els comentaris del blog antic, tal com es van escriure. Els comentaris estan tancats.

  1. Mohammad Ali Fayyaz

    when i entered this:
    rtmpdump -v -r "$RTMP://192.168.2.10:1935/live" -o 1lv --playpath live | sudo -u maf -I dummy fd://0 vlc://quit --sout="#transcode{width=320,height=240,fps=25,vcodec=h264,vb=256,venc=x264{aud,profile=baseline,level=30,keyint=30,ref=1,nocabac},acodec=mp3,ab=96,audio-sync,deinterlace,channels=2,samplerate=44100}:std{access=livehttp{seglen=10,delsegs=true,numsegs=5,index=$M3U8,index-url=$TS_URL},mux=ts{use-key-frames},dst=$TSF}"

    my streaming started but i don't know which address should be use to see streaming on iOS. really i don't realize what is "Variables descriptions" and python code and address.

    please say me, step by step what i should to do?

    1. Oriol Rius

      As you can see the command you run uses some variables. For example, $TSF is a variable. So you have to setup all the variables in 'variables descriptions' before you run the command.

      RTMP= the URL where you have your RTMP source
      WD= working directory where you are going to store small chunks of video, the directory have to be public via HTTP
      TS= the pattern name used to create the chunk video files stored in working directory, you don't need to touch it
      TSF= don't touch it, for a while
      TS_URL= the public URL where your apple device have to connect to find the .m3u file and other video chunks files. Change the first part of the URL and keep the $TS if you want to keep simple.
      M3U8= the name of the .m3u file, keep it to be simple

      does it help you?

  2. Mohammad Ali Fayyaz

    Thanks Oriol.
    I installed rtmpdump with Synapthic. any other program should be install?
    please explain me about directories.
    Thanks.

    1. Oriol Rius

      You only rtmpdump and ffmpeg. I don't know what can I explain about directories? could you make the question in another way. What is your problem exactly?

  3. Hitesh

    What rtmp to mp3 live conversion is possible ?