Mythtv/Plugins/MythTube

From MattWiki
(Redirected from Mythtv\Plugins\MythTube)

Hello Everybody,

I have created a userjob and webpage to play Myth videos in a browser over the internet. I call it MythTube. It's very simple to setup and plays video great. Each flash video is about 80M for an hour long show (minus commercials). It consists of a php page, a transcode script, and a flash player. I run the transcode job after the remove commercials script from the Wiki. The remove commercials may be important as I saw comments about B-Frames being a problem with mencoder. I believe lossless transcoding removes any B-Frames.

To setup Mythtube, first create a directory under your webserver called mythtube. Mine was "/data/www/html/mythtube". You will need to change any references below to whatever your directory is.

Next, get flvplayer.swf. Download http://www.jeroenwijering.com/upload/flash_flv_player.zip and move flash_flv_player/extras/flvplayer.swf into your mythtube directory under your webserver.

Then create "play.php" and put it in the mythtube directory as well. Here's play.php:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
<html>
<head>
    <title>Welcome to MythTube!</title>
</head>
        <body bgcolor="#002650">

Now playing: <?php echo $_GET["movie"]; ?>


<object type="application/x-shockwave-flash" width="<?php echo
$_GET["h"]; ?>" height="<?php echo $_GET["w"]; ?>"
wmode="transparent" data="flvplayer.swf?file=<?php echo $_GET["movie"]; ?>">
<param name="movie" value="flvplayer.swf?file=<?php echo $_GET["movie"]; ?>" />
<param name="wmode" value="transparent" />
</object>

Videos:

<?php $files = scandir("/data/www/html/mythtube"); // filter for only .flv files $movies = array(); foreach($files as $file) { if(substr($file,-4) == ".flv") { echo ""; echo ""; echo ""; $movies[] = $file; } }  ?>
".$file."<a href=\"".$PHP_SELF."?movie=".$file."&h=640&w=480\">Large</a><a href=\"".$PHP_SELF."?movie=".$file."&h=360&w=240\">Small</a>
</body>
</html>


Next you need to create the userjob which generates the flv files.

Here's the MYSQL commands I used in creating userjob 3: use mythconverg;

UPDATE settings SET data='/usr/local/bin/flashtranscode %DIR% %FILE% "%TITLE%" %STARTTIME%' WHERE value='UserJob3';
UPDATE settings SET data='Flash Transcode' WHERE value='UserJobDesc3';
UPDATE settings SET data='1' WHERE value='JobAllowUserJob3';


Here's the /usr/local/bin/flashtranscode script:

#!/bin/sh
# flashtranscode
#
# created by Jeff Volckaert (inspired by Zach White)
# modified 11/03/06 to use Flash
VIDEODIR=$1
FILENAME=$2
TITLE=$3
# Remove non-alpha characters from TITLE
TITLE=${TITLE//[^a-zA-Z0-9]/}
STARTTIME=$4 

# Sanity checking, to make sure everything is in order.
if [ -z "$VIDEODIR" -o -z "$FILENAME" ]; then
        echo "Usage: $0 <VideoDirectory> <FileName> "<Title>" <Starttime>"
        exit 5
fi
if [ ! -f $VIDEODIR/$FILENAME ]; then
        echo "File does not exist: $VIDEODIR/$FILENAME"
        exit 6
fi

# Transcode the file

mencoder -ofps 12 -of lavf -lavfopts
i_certify_that_my_video_stream_does_not_use_b_frames -oac lavc
-lavcopts acodec=mp3:abitrate=32 -channels 1 -srate 22050  -ovc lavc
-lavcopts vcodec=flv:vbitrate=200:cbp:mv0:mbd=2:trell:v4mv:predia=2:dia=2:last_pred=3
-vop spp,scale=360:240,harddup -o
/data/www/html/mythtube/$TITLE-$STARTTIME.flv $VIDEODIR/$FILENAME

# For a smaller file use this instead.
# (It take three times longer to encode though)
# mencoder -ofps 12 -of lavf -lavfopts
i_certify_that_my_video_stream_does_not_use_b_frames -oac lavc
-lavcopts acodec=mp3:abitrate=32 -channels 1 -srate 22050  -ovc lavc
-lavcopts vcodec=flv:vbitrate=100:mbd=2:mv0:trell:v4mv:cbp:last_pred=3:predia=2:dia=2:vmax_b_frames=0:vb_strategy=1:precmp=2:cmp=2:subcmp=2:preme=2:qns=2
-vop spp,scale=320:240 -o
/data/www/html/mythtube/$TITLE-$STARTTIME-2.flv $VIDEODIR/$FILENAME

# Uncomment this if you want to insert MetaData tags into the file
# /usr/bin/flvtool2/flvtool2 -U /data/www/html/mythtube/$TITLE-$STARTTIME.flv

ERROR=$?
if [ $ERROR -ne 0 ]; then
        echo "Transcoding failed for ${FILENAME} with error $ERROR"
        exit 3
fi


After at least one file has been transcoded you can pull up the play.php page and start watching video.