From 1b2f043db4920ed3a3ccf5519beb2651ac1d235a Mon Sep 17 00:00:00 2001 From: dvr Date: Wed, 30 Jul 2014 18:17:20 -0400 Subject: [PATCH 1/4] Added support for SRT subtitles & BIF trick files --- INSTALL | 40 +++++++++++++++++++++++++++----- Makefile | 2 +- mythroku/xml_data.php | 8 +++++++ mythroku/xml_utils.php | 3 +++ mythroku/xsl/mythtv_xml_test.xsl | 6 +++++ source/showFeed.brs | 13 +++++++++++ 6 files changed, 65 insertions(+), 7 deletions(-) diff --git a/INSTALL b/INSTALL index 57c43f8..013b2af 100755 --- a/INSTALL +++ b/INSTALL @@ -40,15 +40,43 @@ Setup around line 247: case 'mp4' : return "$url.mp4"; + case 'srt' : return "$url.srt"; + case 'bif' : return "$url.bif"; - Modify /usr/share/mythtv/mythweb/modules/stream/stream_raw.pl by adding an + Modify /usr/share/mythtv/mythweb/modules/stream/stream_raw.pl by adding additonal elseif in the file type section: - elsif ($basename =~ /\.mp4$/) - { - $type = 'video/mp4'; - $suffix = '.mp4'; - } + if ($Path[3] =~ /srt/) { + #TODO language $Path[4] + $filename =~ s/\..+?$/\.srt/g; + $basename =~ s/\..+?$/\.srt/g; + $type = 'text/plain'; + $suffix = '.srt'; + } + elsif ($Path[3] =~ /bif/) { + my $HdSd = ""; + $HdSd = "_$Path[4]" if ($Path[4]); + $filename =~ s/\..+?$/$HdSd\.bif/g; + $basename =~ s/\..+?$/$HdSd\.bif/g; + $type = 'image/jpeg'; + $suffix = '.bif'; + } + elsif ($basename =~ /\.mpe?g2?$/) { + +[...] + + elsif ($basename =~ /\.mp4$/) { + $type = 'video/mp4'; + $suffix = '.mp4'; + } + elsif ($basename =~ /\.srt$/) { + $type = 'text/plain'; + $suffix = '.srt'; + } + elsif ($basename =~ /\.bif$/) { + $type = 'image/jpeg'; + $suffix = '.bif'; + } if you are using authentication to protect your mythweb (best practice) you need to add the following to your mythweb.conf file (near the top) diff --git a/Makefile b/Makefile index 22a159b..30018fc 100755 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ APPNAME = MythRokuPlayer VERSION = 1.1 -ZIP_EXCLUDE= -x mythroku\* -x tools\* -x .\* +ZIP_EXCLUDE= -x mythroku\* -x tools\* -x zips\* -x .\* include app.mk diff --git a/mythroku/xml_data.php b/mythroku/xml_data.php index ded0323..5df49d9 100755 --- a/mythroku/xml_data.php +++ b/mythroku/xml_data.php @@ -161,6 +161,8 @@ function build_xml_vid( $sql_result, $index ) while ( $db_field = mysql_fetch_assoc($sql_result) ) { $filename = $db_field['filename']; + $fname = pathinfo($filename, PATHINFO_FILENAME); + $fpath = pathinfo($filename, PATHINFO_DIRNAME); $contentType = "movie"; $episode = ""; @@ -201,6 +203,9 @@ function build_xml_vid( $sql_result, $index ) 'streamQuality' => $quality, 'streamContentId' => html_cleanup($filename), 'streamFormat' => pathinfo($filename, PATHINFO_EXTENSION), + 'srtUrl' => "$mythtvdata/video/" . html_encode($fpath .'/'. $fname . '.srt'),# todo unless exists + 'hdbifUrl' => "$mythtvdata/video/" . html_encode($fpath .'/'. $fname . '_hd.bif'),# todo unless exists + 'sdbifUrl' => "$mythtvdata/video/" . html_encode($fpath .'/'. $fname . '_sd.bif'),# todo unless exists 'isHD' => $isHD, 'episode' => html_cleanup($episode), 'genres' => html_cleanup($genre), @@ -267,6 +272,9 @@ function build_xml_rec( $sql_result, $index ) 'streamQuality' => $quality, 'streamContentId' => html_cleanup($filename), 'streamFormat' => pathinfo($filename, PATHINFO_EXTENSION), + 'srtUrl' => "$WebServer/pl/stream/" . html_encode($chanid_strtime) . "/srt", + 'hdbifUrl' => "$WebServer/pl/stream/" . html_encode($chanid_strtime) . "/bif/hd", + 'sdbifUrl' => "$WebServer/pl/stream/" . html_encode($chanid_strtime) . "/bif/sd", 'isHD' => $isHD, 'episode' => html_cleanup($episode), 'genres' => html_cleanup($db_field['category']), diff --git a/mythroku/xml_utils.php b/mythroku/xml_utils.php index 0709aa2..d341ab9 100755 --- a/mythroku/xml_utils.php +++ b/mythroku/xml_utils.php @@ -47,6 +47,9 @@ function xml_file( $args ) {$args['streamQuality']} {$args['streamContentId']} {$args['streamFormat']} + {$args['srtUrl']} + {$args['hdbifUrl']} + {$args['sdbifUrl']} {$args['isHD']} {$args['episode']} diff --git a/mythroku/xsl/mythtv_xml_test.xsl b/mythroku/xsl/mythtv_xml_test.xsl index 7fcb394..7d5fb25 100755 --- a/mythroku/xsl/mythtv_xml_test.xsl +++ b/mythroku/xsl/mythtv_xml_test.xsl @@ -46,6 +46,9 @@ + + + [#] @@ -74,6 +77,9 @@ Episode: Stream Url:
+ Srt Url:
+ HDBif Url:
+ SDBif Url:
Synopsis:
diff --git a/source/showFeed.brs b/source/showFeed.brs index 92a92a0..cb67fac 100755 --- a/source/showFeed.brs +++ b/source/showFeed.brs @@ -71,6 +71,11 @@ function init_show_feed_item() as object o.StreamContentIDs = CreateObject("roArray", 1, true) o.StreamFormat = CreateObject("roArray", 1, true) + o.HDBifUrl = "" + o.SDBifUrl = "" + o.SubtitleUrl = "" + o.SubtitleConfig = "" + o.Length = 0 o.BookmarkPosition = 0 o.ReleaseDate = "" @@ -201,6 +206,14 @@ function parse_file(element as object) as object item.StreamContentIDs.Push(validstr(e.streamContentId.GetText())) item.StreamFormat.Push( validstr(e.streamFormat.GetText())) + item.HDBifUrl = validstr(e.hdbifUrl.GetText()) + item.SDBifUrl = validstr(e.sdbifsrtUrl.GetText()) + item.SubtitleUrl = validstr(e.srtUrl.GetText()) + item.SubtitleConfig = { + ShowSubtitle: 1 ' alternatively use screen.ShowSubtitle(true) to toggle Srt + TrackName: item.SubtitleUrl + } + item.Length = strtoi( element.runtime.GetText()) ' item.BookmarkPosition = strtoi( element..GetText()) item.ReleaseDate = validstr(element.date.GetText()) From 92935f77299cddaa77825ce7d5747cb890119932 Mon Sep 17 00:00:00 2001 From: dvr Date: Sat, 2 Aug 2014 21:35:18 -0400 Subject: [PATCH 2/4] Added support for SRT subtitles (and option on/off) & BIF trick files --- source/appDetailScreen.brs | 45 ++++++++++++++++++++++++++++++++++++++ source/appVideoScreen.brs | 17 ++++++++++++++ source/showFeed.brs | 2 +- 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/source/appDetailScreen.brs b/source/appDetailScreen.brs index 8bda21d..1cc4139 100755 --- a/source/appDetailScreen.brs +++ b/source/appDetailScreen.brs @@ -100,6 +100,35 @@ function showDetailScreen(screen as object, showList as object, showIndex as int end if + 'set captions + if msg.GetIndex() = 9 then + srtOnOff = RegRead("MythRokuSrtOnOff") + + 'set to a default value if reg is empty + if (srtOnOff = invalid) then + print "MythRokuSrtOnOff not found in the registry" + srtOnOff = "srtOff" + 'RegWrite("MythRokuSrtOnOff", srtOnOff) + end if + + print "subtitles button pressed. current value: " + srtOnOff + + Dbg("MythRoku: change srtOnOff. current value: " + srtOnOff) + + 'toggle values + if (srtOnOff = "srtOn") + srtOnOff = "srtOff" + else + srtOnOff = "srtOn" + end if + + RegWrite("MythRokuSrtOnOff", srtOnOff) + + Dbg("MythRoku: change srtOnOff. new value: " + srtOnOff) + + refreshShowDetail(screen, showList, showIndex) + end if + end if else print "Unexpected message class: "; type(msg) @@ -138,6 +167,22 @@ Function refreshShowDetail(screen As Object, showList As Object, showIndex as In screen.AddButton(7, "Delete") end if + 'set captions + srtOnOff = RegRead("MythRokuSrtOnOff") + + 'set to a default value if reg is empty + if (srtOnOff = invalid) then + print "MythRokuSrtOnOff not found in the registry" + srtOnOff = "srtOff" + RegWrite("MythRokuSrtOnOff", srtOnOff) + end if + + if (srtOnOff = "srtOn") + screen.AddButton(9, "Subtiles are on") + else + screen.AddButton(9, "Subtiles are off") + end if + screen.SetContent(show) screen.Show() diff --git a/source/appVideoScreen.brs b/source/appVideoScreen.brs index ad02663..4fca269 100755 --- a/source/appVideoScreen.brs +++ b/source/appVideoScreen.brs @@ -27,6 +27,23 @@ Function showVideoScreen(episode As Object) screen.Show() screen.SetPositionNotificationPeriod(30) screen.SetContent(episode) + + 'set captions + srtOnOff = RegRead("MythRokuSrtOnOff") + + 'set to a default value if reg is empty + if (srtOnOff = invalid) then + print "MythRokuSrtOnOff not found in the registry" + srtOnOff = "srtOff" + RegWrite("MythRokuSrtOnOff", srtOnOff) + end if + + if (srtOnOff = "srtOn") + screen.ShowSubtitle(true) + else + screen.ShowSubtitle(false) + end if + screen.Show() 'Uncomment this line to dump the contents of the episode to be played diff --git a/source/showFeed.brs b/source/showFeed.brs index cb67fac..96087e2 100755 --- a/source/showFeed.brs +++ b/source/showFeed.brs @@ -210,7 +210,7 @@ function parse_file(element as object) as object item.SDBifUrl = validstr(e.sdbifsrtUrl.GetText()) item.SubtitleUrl = validstr(e.srtUrl.GetText()) item.SubtitleConfig = { - ShowSubtitle: 1 ' alternatively use screen.ShowSubtitle(true) to toggle Srt + 'ShowSubtitle: 1 ' alternatively use screen.ShowSubtitle(true) to toggle Srt TrackName: item.SubtitleUrl } From e4a95f788f47d277930f77fb3b11a714ab584628 Mon Sep 17 00:00:00 2001 From: dvr Date: Sat, 2 Aug 2014 23:31:58 -0400 Subject: [PATCH 3/4] Updated rokuencode.sh script to output srt & bif files --- INSTALL | 2 ++ tools/rokuencode.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/INSTALL b/INSTALL index 013b2af..a1602df 100755 --- a/INSTALL +++ b/INSTALL @@ -177,4 +177,6 @@ rokuencode.sh: Prerequisites: - HandBrakeCLI: To convert recordings into H.264 format. + - CCExtractor: To extract srt subtitles + - ffmpeg & biftool: To create bif trick files for fast forward/rewind diff --git a/tools/rokuencode.sh b/tools/rokuencode.sh index f85831a..0ee2ccb 100755 --- a/tools/rokuencode.sh +++ b/tools/rokuencode.sh @@ -9,6 +9,14 @@ MPGFILE=$2 DATABASEUSER=mythtv DATABASEPASSWORD=mythtv +# extract subtitles +srtbname=`echo $MPGFILE | sed 's/\(.*\)\..*/\1/'` +srtname="$MYTHDIR/$srtbname.srt" + +# extract subtitles +/usr/bin/ccextractor -90090 --fixpadding --nofontcolor -out=srt --sentencecap "$MYTHDIR/$MPGFILE" -o "$srtname" + +# create mp4 newbname=`echo $MPGFILE | sed 's/\(.*\)\..*/\1/'` newname="$MYTHDIR/$newbname.mp4" @@ -22,5 +30,26 @@ mysql --user=$DATABASEUSER --password=$DATABASEPASSWORD mythconverg < /tmp/updat # update the seek table mythcommflag --file $newname --rebuild +# create bif trick files +bifbname=`echo $MPGFILE | sed 's/\(.*\)\..*/\1/'` +sdbifname="/tmp/${bifbname}_sd" +hdbifname="/tmp/${bifbname}_hd" + +mkdir $sdbifname +mkdir $hdbifname + +/usr/bin/ffmpeg -i "$MYTHDIR/$MPGFILE" -r .1 -s 240x180 "$sdbifname/%08d.jpg" +/usr/bin/ffmpeg -i "$MYTHDIR/$MPGFILE" -r .1 -s 320x240 "$hdbifname/%08d.jpg" + +cd /tmp +/usr/bin/biftool -t 10000 "$sdbifname" +/usr/bin/biftool -t 10000 "$hdbifname" + +rm -rf "$sdbifname" +rm -rf "$hdbifname" + +mv "$sdbifname.bif" $MYTHDIR +mv "$hdbifname.bif" $MYTHDIR + # remove the orignal mpg rm $MYTHDIR/$MPGFILE From 5c165738b6849511d46f5e72ba96ff400cff1937 Mon Sep 17 00:00:00 2001 From: dvr Date: Thu, 7 Aug 2014 21:48:40 -0400 Subject: [PATCH 4/4] Added URLs for subtitle & bif tools; Helper script won't die if these utils are missing --- INSTALL | 7 +++++-- tools/rokuencode.sh | 44 ++++++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/INSTALL b/INSTALL index a1602df..74f3eee 100755 --- a/INSTALL +++ b/INSTALL @@ -138,6 +138,9 @@ Setup http//192.168.1.10/mythweb/mythroku + 6) Copy CCExtractor & biftool to /usr/bin to make them available system wide + if you intend to use subtitles & the Roku FF/REW bif trick files. + -------------------------------------------------------------------------------- Debugging -------------------------------------------------------------------------------- @@ -177,6 +180,6 @@ rokuencode.sh: Prerequisites: - HandBrakeCLI: To convert recordings into H.264 format. - - CCExtractor: To extract srt subtitles - - ffmpeg & biftool: To create bif trick files for fast forward/rewind + - CCExtractor: To extract srt subtitles (download from http://ccextractor.sourceforge.net/download-ccextractor.html) + - ffmpeg & biftool: To create bif trick files for fast forward/rewind; biftool is part of the Roku SDK. You must register your Roku account as a developer to download the SDK at https://owner.roku.com/Developer. diff --git a/tools/rokuencode.sh b/tools/rokuencode.sh index 0ee2ccb..472d244 100755 --- a/tools/rokuencode.sh +++ b/tools/rokuencode.sh @@ -9,12 +9,14 @@ MPGFILE=$2 DATABASEUSER=mythtv DATABASEPASSWORD=mythtv -# extract subtitles -srtbname=`echo $MPGFILE | sed 's/\(.*\)\..*/\1/'` -srtname="$MYTHDIR/$srtbname.srt" +if [ -f /usr/bin/ccextractor ]; then + # extract subtitles + srtbname=`echo $MPGFILE | sed 's/\(.*\)\..*/\1/'` + srtname="$MYTHDIR/$srtbname.srt" -# extract subtitles -/usr/bin/ccextractor -90090 --fixpadding --nofontcolor -out=srt --sentencecap "$MYTHDIR/$MPGFILE" -o "$srtname" + # extract subtitles + /usr/bin/ccextractor -90090 --fixpadding --nofontcolor -out=srt --sentencecap "$MYTHDIR/$MPGFILE" -o "$srtname" +fi # create mp4 newbname=`echo $MPGFILE | sed 's/\(.*\)\..*/\1/'` @@ -30,26 +32,28 @@ mysql --user=$DATABASEUSER --password=$DATABASEPASSWORD mythconverg < /tmp/updat # update the seek table mythcommflag --file $newname --rebuild -# create bif trick files -bifbname=`echo $MPGFILE | sed 's/\(.*\)\..*/\1/'` -sdbifname="/tmp/${bifbname}_sd" -hdbifname="/tmp/${bifbname}_hd" +if [ -f /usr/bin/biftool -a -f /usr/bin/ffmpeg ]; then + # create bif trick files + bifbname=`echo $MPGFILE | sed 's/\(.*\)\..*/\1/'` + sdbifname="/var/tmp/${bifbname}_sd" + hdbifname="/var/tmp/${bifbname}_hd" -mkdir $sdbifname -mkdir $hdbifname + mkdir $sdbifname + mkdir $hdbifname -/usr/bin/ffmpeg -i "$MYTHDIR/$MPGFILE" -r .1 -s 240x180 "$sdbifname/%08d.jpg" -/usr/bin/ffmpeg -i "$MYTHDIR/$MPGFILE" -r .1 -s 320x240 "$hdbifname/%08d.jpg" + /usr/bin/ffmpeg -i "$MYTHDIR/$MPGFILE" -r .1 -s 240x180 "$sdbifname/%08d.jpg" + /usr/bin/ffmpeg -i "$MYTHDIR/$MPGFILE" -r .1 -s 320x240 "$hdbifname/%08d.jpg" -cd /tmp -/usr/bin/biftool -t 10000 "$sdbifname" -/usr/bin/biftool -t 10000 "$hdbifname" + cd /var/tmp + /usr/bin/biftool -t 10000 "$sdbifname" + /usr/bin/biftool -t 10000 "$hdbifname" -rm -rf "$sdbifname" -rm -rf "$hdbifname" + rm -rf "$sdbifname" + rm -rf "$hdbifname" -mv "$sdbifname.bif" $MYTHDIR -mv "$hdbifname.bif" $MYTHDIR + mv "$sdbifname.bif" $MYTHDIR + mv "$hdbifname.bif" $MYTHDIR +fi # remove the orignal mpg rm $MYTHDIR/$MPGFILE