Saturday, February 14, 2009

Oasis y Travis en concierto

Las fotos las hice en ambos conciertos con el android G1, la calidad deja bastante que desear, también mi pulso con una cerveza en la mano no es muy fino ;-)

http://www.youtube.com/watch?v=BseffSA3eTA

Veamos que lal funciona publicar en blogger desde Android.

Sunday, February 01, 2009

How to stream media and TV to your Android G1

The first thing I had in mind when I got the T-mobile G1 was to try a kind of TV streaming to the phone, just in case I have to travel to other countries, for example Sweden, and I would like to hear some Spanish voices :-).

At the end what really you can achieve is a full streaming server with support to stream your music files, videos and of course your dvb-t or dvb-s channels
Another important point for the project was to use open software as much as possible.

So lets go, and I'll explain how I did it:



Main components used:

-Ubuntu Hardy 8.04
-Capture card: Hauppage HVR-4000
-ffmpeg
-x264
-VLC
-Darwin Streaming Server

First thing's first, we will need to compile manually almost all the components to add the necessary features that we want.
We must know also that our beloved phone support some codecs and file containers, as said here, G1 by now doesn't let as port codec library onto it and Adobe says they'll publish flash player 10 for mobile on 2009.

Screen:
3.2-inch TFT-LCD flat touch-sensitive screen with 320 x 480 (HVGA) resolution

Codec:
H.264/AVC
H.263/MPEG4 Part-2
WMV/8 (9 is not playable)
AAC/mp4a/AMR/mp3/wave/wma8 audio

Supported File Container:
.mp4
.3gp

Knowing the requirements lets prepare the server machine for that.
We have to compile the latest ffmpeg and x264 from source, for that you should follow the explanations from:
http://ubuntuforums.org/showthread.php?t=786095

Once finished the installation of ffmpeg, now move to install the latest vlc possible following this guide:

Before building vlc we need the rtsp support that arrive to us thanks to live555, again here we have to compile the sources. To do so follow the tips in:
http://www.live555.com/liveMedia/#config-unix

After that, I built vlc with the next configuration command:

../configure --prefix=/usr --enable-snapshot --enable-debug --enable-dbus-control --enable-musicbrainz --enable-shared-libvlc --enable-mozilla --enable-lirc --enable-x264 --with-x264-tree=/you/path/x264 --enable-shout --enable-taglib --enable-v4l --disable-xvmc --enable-svg --enable-dvdread --enable-dc1394 --enable-dv --enable-twolame --enable-real --enable-flac --enable-tremor --enable-skins2 --enable-qt4 --enable-ncurses --enable-aa --enable-caca --enable-esd --disable-portaudio --enable-jack --enable-xosd --enable-galaktos --enable-goom --enable-ggi --disable-cddax --disable-vcdx --disable-quicktime --enable-lua --enable-sdl --enable-ffmpeg --with-ffmpeg-mp3lame --enable-mad --enable-libdvbpsi --enable-a52 --enable-libmpeg2 --enable-dvdnav --enable-mp4 --enable-faad --enable-vorbis --enable-ogg --enable-theora --enable-x11 --enable-xvideo --enable-dvb --enable-pp --enable-realrtsp --enable-live555 --with-live555-tree=/home/dani/live --enable-faac --enable-mkv --enable-freetype --enable-fribidi --enable-speex --enable-flac --enable-x11 --enable-xvideo --enable-dvb --enable-pp --with-ffmpeg-tree=/your/path/ffmpeg --disable-zvbi --disable-swscale

and using the guide:
http://www.jbkempf.com/blog/post/2008/03/28/Build-VLC-media-player-under-Ubuntu-Hardy-804

If you find problems during make of vlc regarding libdvb read the next link
http://freshmeat.net/projects/libdvbpsi/
If you find any other issues during vlc set-up, read the comments on the above guide, read the output in the screen, copy and paste it in google and look for the solution. Usually this compilations complain about dependencies dev library's that also needs to be installed. Nothing from another world if you use Linux.

Where are we know?, at this point your system is able to convert videos for watching in your G1, so if you feel tired you can rest a bit by trying to convert an avi file to mp4 and pass it to your SD card to see the quality. You will need to install a video player from Android Market.
So try to do a:

ffmpeg -i source-video.avi -s 480x320 -vcodec mpeg4 -acodec libfaac -ac 1 -ar 16000 -r 13 -ab 32000 -aspect 3:2 output-video.G1.mp4

If you want more information about the parameters in that line you can read:
http://androidcommunity.com/forums/showthread.php?p=88879#post88879

Now we are able to do a lot of types of streaming thanks to VLC, but we miss the important one, stream a mp4 container over rtp to be received via rtsp in the G1 client. As we can see in the Output method/muxer matrix table from VLC features

For doing that we are going to rely on Darwin Streaming Server, that is the open source version of Apple's QuickTime Streaming Server technology that allows you to send streaming media to clients across the Internet using the industry standard RTP and RTSP protocols.
We have to install it in our system, I followed a spanish guide for that, but I'm sure that it is possible to find a lot of guides over the internet for this purpose, so choose the one that you like.

After the installation we have to configure it, in my case I only set up the IP address of the server and checked the ports on the configuration file:

/etc/streaming/streamingserver.xml

http://wiki.dlib.indiana.edu/confluence/display/V3/Darwin+Streaming+Server

After the configuration it is a good idea to kill the server (DarwinStreamingServer) and run it again in order to pick up the changes.
At this point you can put your converted mp4 videos into the /usr/local/movies and access them via rtsp://yourserver:yourport/yourfile.mp4
Take into account that for some reason ffmpeg doesn't prepare the mp4 file to use it directly with Darwin, and you will have to prepare (hint) the file before being accesible. For that use:


MP4Box -hint yourfile.mp4

Well, lets move now to watch live television, in my case dvb-t channels. There are some texts on the internet on how to make vlc read from your tv-card, for example this one. But for this tutorial I prefer to access separately each channel, you would have to know the frequency's and other stuff to set it up, and to know that, you can review your channels.conf file after you scan the card with your country/zone settings.
I did it with Madrid-Spain channels, yes I live here, if you want to take a beer let me know :-).
For example let's test that we can see TV with vlc, for example with:

vlc dvb:// --dvb-adapter=1 --dvb-frequency=706000000 --dvb-bandwidth=8 --program=5001

wow, vlc, probably the best media player of the history of the media players.
If you can't get this working review your parameters with the channels.conf or go back to review the outputs of your installation to solve other problems. More information about this in http://www.videolan.org/doc/videolan-howto/es/ch06.html

Finally we can stream creating a sdp file inside /usr/local/movies with the proper permissions, look at the ones that already have webcam.sdp inside that folder.
If you want to stream h264 codec it could be possible that you have to patch a file, h264.c, see more information here https://trac.videolan.org/vlc/ticket/1494

There are multiple ways to do the streaming, changing supported codecs and more options, the one I choose is the next one:


vlc -vvv --color --ts-es-id-pid dvb:// --dvb-adapter=1 --dvb-frequency=706000000 --dvb-bandwidth=8 --program=5001 --sout-standard-access=udp --sout-standard-mux=mp4 --file-caching=3000 --sout'#transcode{fps=13,width=480,height=320,vcodec=mp4v,vb=96,scale=1,acodec=mp4a,\
ab=32,channels=1,cropleft=20,cropbottom=6,cropright=4,croptop=6}:\
duplicate{dst="rtp{dst=127.0.0.1,port=1230,sdp=file:///usr/local/movies/tv.sdp}"}'

note that I use --dvb-adapter=1 because my card is an hybrid one that has dvb-t and dvb-s and the adapter for dvb-t is 1, usually you would have to use 0, also the codecs used by me are mp4v for video, mp4a for audio and muxer mp4. It is also possible to increase the video bitrate(vb=96) to obtain more image quality. Feel free to change the settings for your case.

You can test first that the streaming is working from another station via wifi, by typing something like

vlc rtsp://yourserver/tv.sdp

don't worry if the size of the image looks weird, the important thing is to have a good image on the G1.
I tried to play it with Meridian player because the rtsp support, I got it from the market, but I didn't have good results with rtsp streams. So I moved to use the G1 built-in, that one that pops up when you visit youtube.
So what I did and because G1 browser doesn't allow to type a rtsp url was to make a little html page on the server machine with the rtsp links:


<html>
<head>
</head>
<body>
<a href="rtsp://serverip:port/tv.sdp">DVB Channel 1</a>
<a href="rtsp://serverip:port/myvideo.mp4">Myvideo.mp4</a>
<a href="rtsp://serverip:port/tv.sdp">DVB_channel_ssh?</a>
<a href="rtsp://myserver.dyndns.net:port/tv.sdp">Internet stream?</a>
</body>
</html>


And then I access the url of that html in the server machine with the G1 browser and click on one of the links.
And there you are, you have live television, live videos, live mp3s wherever you are, streaming from your home.
note: The links with question mark (?) I haven't implemented yet, but looks possible, feel free to add your experience.

 

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.