Acabo de resolver un problema muy específico y tengo que escribir unas notas aquí para recordar la solución. Dada una fuente RTMP, hemos de enviar el contenido en streaming a dispositivos Apple como iPad, iPhone e iPod, porque el RTMP no se podía reproducir con el navegador Safari.
Si necesitamos reproducir streaming en dispositivos Apple, la mejor solución es convertirlo a HLS y publicar los ficheros generados mediante un servidor HTTP.
Para resolver este problema utilizo rtmpdump y vlc. Primero rtmpdump obtiene el flujo de vídeo de la fuente. Después el flujo se envía a vlc y finalmente vlc transcodifica el vídeo y el audio y genera pequeños ficheros .ts y un fichero índice .m3u8.
El comando es algo como esto:
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}"
Las descripciones de las variables son:
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ón cread un fichero HTML, por ejemplo live.html, con una referencia al fichero .m3u8; el código relevante del fichero HTML es así:
<video width="320" height="240"><source src="http://example.tld/path/live.m3u8" /></video>
Un código sencillo para publicar ficheros vía HTTP:
python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"
Entonces solo tenemos que abrir el navegador Safari en el dispositivo Apple y poner la URL adecuada, en nuestro caso:
http://example.tld/path/live.html
NOTA IMPORTANTE: la salida de audio tiene que ser con dos canales y una frecuencia de muestreo de 44KHz; en otros casos el audio falla.
5 comentarios
Los comentarios del blog antiguo, tal como se escribieron. Los comentarios están cerrados.
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?
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?
Mohammad Ali Fayyaz
Thanks Oriol.
I installed rtmpdump with Synapthic. any other program should be install?
please explain me about directories.
Thanks.
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?
Hitesh
What rtmp to mp3 live conversion is possible ?