Stream mythtv recordings to mobile devices

From MythTV Official Wiki
Revision as of 09:43, 18 October 2006 by Wiggi (talk | contribs) (Initial page creation)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Streaming MythTV Recordings to mobile devices

This is a quick guide describing how to stream your recordings to mobile devices. It is written for users who have mobile phones or other devices capable of playing video streams as most modern devices can. The phone must be capable of playing a 3GP stream over RTSP, this is pretty standard and can be done on all new Nokia handsets from the last year and prob most other makes.

[Prerequisites are:]

Working MythTV - already making recordings ffmpeg capable of creating 3GP recordings (see my guide to streaming via flash video)

[Concept]

MythTV makes recordings as usual, a user job is ran against the recording to convert it to 3GP and add extra data required for streaming, 3GP files are streamed using Darwin Streaming Server

[Tested on...]

Server: Gentoo box running kernel 2.6.12 with MythTV 0.20 and Darwin Streaming Server 5.5.3. Nokia N80 streaming videos over Wifi and viewing on RealPlayer (comes with phone)

Guide

[Setup Darwin Streaming Server]

Download the sourcecode tarball from: http://developer.apple.com/opensource/server/streaming/index.html

Unpack and run the Buildit script followed by the Install script. This should set everything up simply enough. Check the installation by opening http://localhost:1220 in a web browser to confirm that the server is up and running.

[Setup MP4Box]

To make your 3GP files MPEG4 compliant and to add RTSP hints you need to use a program caled MP4Box, available for download as part of the GPAC framework here: http://sourceforge.net/project/showfiles.php?group_id=84101

Install this somewhere in your path

[Add user job in mythtv]

Next you need to create the script which will be ran as a user job in mythtv. The following is an example:

  1. !/bin/bash

out="/video" outfile=`echo $2 | sed 's/ /_/g' | sed 's/://g'` ffmpeg -y -i "$1" -r 20 -s 352x288 -b 400 -ac 1 -ar 8000 -ab 24 "$out/$outfile.3gp" cd $out MP4Box -3gp -mtu 1450 -hint "$outfile.3gp"

This states that the directory im sharing in darwin streaming server is /video, as this is where the files are outputted to.

Next you need to setup the userjob in mythtv. Run mythtv-setup and go to the General Settings section. Under user jobs find a spare job and give it a name of something apropriate (e MythFlash) and the following command:

/usr/local/bin/myth3gp.sh "%DIR%" "%FILE%"

Set this job to run for all recordings you want to convert and share. On my Athlon 2800 box it takes 11 mins to convert and share a 30min recording.

[Create web page linking to shows]

Finally you need a web page to link to your recordings. The following PHP script will work nicely, set the directory and hostname parameters as apropriate.

<?php

$directory = "/video"; $hostname = "wig.gotdns.org";

print("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"); print("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"); print("<head>\n"); print("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n"); print("<title>MythTV Mobile</title>\n"); print("</head>\n");

print("<body>

\n"); print("MythTV Mobile
 
\n"); /* using shell_exec(ls) because opendir and dir class both give seemingly random ordering of files */ $output = ; $ls = shell_exec(escapeshellcmd("ls $directory")); $files = explode("\n", $ls); foreach($files as $file) { if (preg_match('/.3gp$/', $file)) { $file_trimmed = rtrim($file, '.3gp'); $data = preg_split('/---/', $file_trimmed); $show = preg_replace('/_/', ' ', $data[1]); $show_sub = preg_replace('/_/', ' ', $data[2]); ($data[2]) ? $title = "$show - $show_sub" : $title = $show; $date_formatted = date('D n/j/Y, g:i A', mktime(substr($data[0], 8, 2), substr($data[0], 10, 2), substr($data[0], 12, 2), substr($data[0], 4, 2), substr($data[0], 6, 2), substr($data[0], 0, 4))); $output = "<a href=\"rtsp://$hostname/$file\">$title</a>: $date_formatted
 
\n".$output; } } print($output); print("

</body>\n");

print("</html>\n");

?>