[RFC] RTMP (flash streaming) support
Angelo Arrifano <[email protected]>
| Newsgroups | gmane.comp.video.freevo.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello freevo dev's,
I just happened to setup a freevo box at home, connected to a TV. As it
turns out, TV live streaming was important for my own purposes so I
decided to quickly hack rtmp support (lots of live free TV services are
rtmp) into freevo.
Since this might be useful for others too, I decided to share my setup.
Since this was the first time I messed with freevo, I decided not to
touch the python code and instead wrap the mplayer binary.
So here it is how I made it work:
In freevo.conf I replaced the system's mplayer with the wrapper:
# mplayer = /home/mediacenter/bin/mplayer-wrapper
Then created a webtv.fxd somewhere with something like this inside:
# <movie title="FOO">
# <cover-img>&imgdir;/foo.png</cover-img>
# <video><url
id="p1">"@stream=rtmp://steamhere.com/foo/|path=bar|player=http://www.streamhere.com/player.swf@"</url></video>
# <info>
# <tagline>Foo channel.</tagline>
# <plot>Video: 480x360@25, 600 kbps
Audio: stereo, 96 kbps</plot>
# </info>
# </movie>
Notice the "strange" url there. This will be later parsed by the
mplayer-wrapper:
Note: The double-quotes inside the url tag are important, to keep
special symbols like & away from bash.
--------------------- mplayer-wrapper ----------------------------
#!/bin/bash
INPUT="$(echo "$@" | sed -e 's/\-autosync\ [0-9]*//')"
if [[ ! "$(echo "$INPUT" | grep -Eo "rtmp://")" ]]; then
exec /usr/bin/mplayer $INPUT
exit 0
fi
echo "mplayer rtmp wrapper init" > ~/mplayer-wrapper.log
RTMP_PARAMS="$(echo "$INPUT" | grep -Eo "@[^@]*@" | sed -e 's/^@//' -e
's/@$//')"
echo "RTMP params: $RTMP_PARAMS" >> ~/mplayer-wrapper.log
RTMP_STREAM="$(echo "$RTMP_PARAMS" | grep -Eo "stream=[^|@]*" | sed -e
's/stream=//')"
echo "RTMP stream: $RTMP_STREAM" >> ~/mplayer-wrapper.log
RTMP_PATH="$(echo "$RTMP_PARAMS" | grep -Eo "path=[^|@]*" | sed -e
's/path=//')"
echo " RTMP path: $RTMP_PATH" >> ~/mplayer-wrapper.log
RTMP_PLAYER="$(echo "$RTMP_PARAMS" | grep -Eo "player=[^|@]*" | sed -e
's/player=//')"
echo "RTMP player: $RTMP_PLAYER" >> ~/mplayer-wrapper.log
mkfifo /tmp/freevo.flv &> /dev/null
rtmpdump -r "$RTMP_STREAM" -y "$RTMP_PATH" -W "$RTMP_PLAYER" -k 1 -v -o
- > /tmp/freevo.flv &
MPLAYER_ARGS="$(echo "$INPUT" | sed -e "s@${RTMP_PARAMS}@@" -e 's/@//g'
-e 's@"@@g')"
echo "Executing: /usr/bin/mplayer $MPLAYER_ARGS /tmp/freevo.flv" >>
~/mplayer-wrapper.log
exec /usr/bin/mplayer $MPLAYER_ARGS -loop 0 -autosync 30 \
/tmp/freevo.flv
----------------------------------------------------------------
The wrapper receives as input a concatenation of mplayer arguments
provided by video.mplayer and the url itself, something like this:
-slave -v -vo xv,sdl,x11, -ao alsa -nolirc -nojoystick -autoq 100
-screenw 400 -screenh 300 -fs -cache 1000 -vf pp=de -osdlevel 0
"@stream=rtmp://steamhere.com/foo/|path=bar|player=http://www.streamhere.com/player.swf@"
Then the wrapper parses stream, path and player fields from its input
and gives them to rtmpdump. rtmpdump's output is redirected into a fifo
connected to mplayer's input. rtmpdump's arguments (delimited by @@) are
stripped from the wrappers input to get the correct mplayer's arguments.
Note: if the rtmp:// string is not detected in the wrapper's input,
mplayer is launched as usual.
As you can see this is a _really quick hack_, but it works very well!
Some may ask why the hell all of this fuzz, why using rtmpdump. The
quick answer is that some flash based streaming services check if the
stream client is the crappy flash client located in their ad-filled
websites. The authors of rtmpdump then developed this wonderful tool to
somehow "impersonate" the flash client.
Some info about my system:
Gentoo 2.6.35-hardened-r2
freevo-1.9.0
rtmpdump-2.3
mplayer-1.0_rc4_p20100612
I plan to integrate this into the freevo's video class but since I'm
currently lacking time I decided to push this hack into the mailing list.
Thanks to all freevo's contributors,
we have a wonderful project here.
--
Angelo Arrifano AKA MiKNiX
[email protected]
http://www.arrifano.com
Gentoo Linux OMAP850/Embedded Official Developer
http://www.gentoo.org/~miknix
[email protected]
Linwizard Project Leader/Developer
[email protected]
PGP Pubkey 0x3D92BB0B
------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev