Difference between revisions of "Stream mythtv recordings from mythweb using flash video"

From MythTV Official Wiki
Jump to: navigation, search
(How to stream myth recordings from mythweb using flash video)
(Automatically transcode recordings to flash video and link from mtyhweb)
Line 3: Line 3:
 
Ive just setup my myth box to automatically convet everything it records into flash video which can be played in any web browser with flash 7+. The quality of the videos is more than acceptable for playing in a window on your desktop but you wouldnt want to watch a film over it. It streams straight from my PVR with no buffering issues on a 50kbps upstream connection, if you alter the settings it would work fine over a standard ADSL connection.
 
Ive just setup my myth box to automatically convet everything it records into flash video which can be played in any web browser with flash 7+. The quality of the videos is more than acceptable for playing in a window on your desktop but you wouldnt want to watch a film over it. It streams straight from my PVR with no buffering issues on a 50kbps upstream connection, if you alter the settings it would work fine over a standard ADSL connection.
  
This guide is pretty simple to setup, but is nothing official and has no input from the developers of mythtv or mythweb. Its basically a quick hack I set up when I did a few overnights.
+
This guide could also be used to create .mp4 videos for your ipod or whatever just by changing the ffmpeg arguments... have a play :D
 +
 
 +
This guide is pretty simple to setup, but is not official and has no input from the developers of mythtv or mythweb. Its basically a quick hack I set up when I did a few overnights.
  
 
There are 3 stages to getting this setup:
 
There are 3 stages to getting this setup:
Line 69: Line 71:
 
0  *  * * *    find /your/recordingsdir/ -name '*.flv' -mtime +1 -exec rm {} \;
 
0  *  * * *    find /your/recordingsdir/ -name '*.flv' -mtime +1 -exec rm {} \;
 
</pre>
 
</pre>
 +
 +
 +
'''To do:'''
 +
 +
Link files from mythweb a bit better
 +
Investigate 2 pass encoding in ffmpeg
 +
Find a better method to expiring recordings.
 +
 +
[[Category:HOWTO]]
 +
[[Category:MythWeb]]

Revision as of 23:44, 23 February 2006

Automatically transcode recordings to flash video and link from mtyhweb

Ive just setup my myth box to automatically convet everything it records into flash video which can be played in any web browser with flash 7+. The quality of the videos is more than acceptable for playing in a window on your desktop but you wouldnt want to watch a film over it. It streams straight from my PVR with no buffering issues on a 50kbps upstream connection, if you alter the settings it would work fine over a standard ADSL connection.

This guide could also be used to create .mp4 videos for your ipod or whatever just by changing the ffmpeg arguments... have a play :D

This guide is pretty simple to setup, but is not official and has no input from the developers of mythtv or mythweb. Its basically a quick hack I set up when I did a few overnights.

There are 3 stages to getting this setup:

1) Automatically transcode the files to FLV's using the user job function in myth 2) Alter mythweb to link to the recorded files and setup the flash player 3) Set the files to automatically expire.

Prerequisites:

Working MythTV, mythweb and ffmpeg.


1) Transcode recordings

First create a script as below and put it somewhere in the path of the user that runs mythbackend, eg /usr/local/bin/mythflash.sh

directory=$1;
file=$2;

ffmpeg -hq -y -i $directory/$file -r 20 -s 300x200 -deinterlace -ar 22050 $directory/$file.flv 1>/dev/null 2>/dev/null

This is a simple script which takes 2 arguments, first the folder which stores your recordings and second the file name. It then runs ffmpeg with highwuality settings, only outputting 20 frames per second, a resolution on 300x200, deinterlacing the incoming video and setting an apropriate audio sample rate and outputting the flash video file to the same dir as your recordings. You dont need to run it as a script and could just put the command in the mythtv user job field but i like it in a script to make it a little more managable.

If on a slow connection try reducing the resolution and setting the bitrate to 150 by adding -b 150 to the command.

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/mythflash.sh "%DIR%" "%FILE%"

Now on the recording settings page set it to run this job, which will call the script with the correct arguments and automatically create the flash video.


2) Update mythweb

Mythweb should already be up and running on your system. cd yo tour mtyhweb directory (eg /var/www/localhost/htdocs/mythweb) and check that data/recordings is a link to the driectory which holds your recordings. If not you might have to link it manually (ln -s [your recordings dir] data/recordings

Next get hold of a copy of flvplayer.swf and put the file flvplayer.swf into your data dir, and chmod it apropriatly.

Final bit is to update the mythweb interface to link to your flash recordings. edit the file [your mythweb dir]/themes/default/tv/recorded.php and change the following (line 254):

echo '<a href="'.video_url().'/'.basename($show->filename)."\" name=\"$row\">"

to

echo '<a href="/mythweb/data/flvplayer.swf?file=/mythweb/data/recordings/'.basename($show->filename).".flv\" name=\"$row\" target=\"_new\">"

This will launch the flash player with the video in a new window when you click on the thumbnail next to a recording.


3) Expire transcoded recordings

OK... if this didnt look like a dirty hack yet then this last bit certainly is. MythTV has the great user job function but has no way to run a job when programs are expired. Now there is a good way to do this, someone can write a script which can search through your recordings directory and remove all file.mpg.flv files which do not have a corresponding file.mpg. This is a good approach as anything which has been expired by myth will have its flash video removed.

But I didnt want this behavior as such as I have some myth recordings which I keep for ages, such as films, and I dont really want to have a harddisk full of agine flash videos which ill never watch, so I added the following line to cron to automatically remove flash video files from my recordings directory which are oevr 2 days old. A simpler approach, it may mean some files on mythweb do not have flash videos and vice versa, but works and stops them from building up. Im sure someone will come up with a better way, if so please update the wiki :D

Line in cron below:

0  *  * * *     find /your/recordingsdir/ -name '*.flv' -mtime +1 -exec rm {} \;


To do:

Link files from mythweb a bit better Investigate 2 pass encoding in ffmpeg Find a better method to expiring recordings.