Play Recordings On Windows From MythWeb

From MythTV Official Wiki
Revision as of 07:16, 4 March 2008 by Mrsdonovan (talk | contribs) (Time to implement: video code doesn't work, add note about slave recordings)

Jump to: navigation, search


Introduction

Below are instructions on how users can browse the recordings via Mythweb on a Windows machine and with one click, have it play in VideoLan (VLC). Videos can also be played with one click from the MythWeb video listing, but it is necessary to modify code. This no longer works with MythTV v0.20+

Notes

  • These instructions will not work through a firewall or over a slow < 5Mbps connection and assumes the computers are on the same LAN.
  • It just uses VLC to play the files, not the VLC server to stream the recordings.
  • These instructions only work on MythTV 0.20 (or greater)
  • These instructions won't work for slave backends (because of limitations with MythWeb) but the recordings can be shared.
  • Assumes Fedora Core

The instructions consist of three parts, first install and configure the necessary Windows applications, share the recordings directory via Samba, then modify Mythweb.

Time to implement

  • 1/2 hour for recordings and assumes access to MYSQL and setting up Samba via command line
  • 1 hour for recordings from both master and slave back ends.

Installing Required Window Applications

First get and install VideoLan on your Windows machine. Then place the following code (with notepad) into a file called "myth_shellx_vlc_handler.reg" (filename is arbitrary but has to end in .reg). Save the file and run it - "Yes" you want to modify the registry.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\myth]
@="URL:MythTV File playback Protocol"
"EditFlags"=dword:00000002
"Source Filter"="{2D788796-26AD-4457-8097-EF0846CF8C3A}"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\myth\shell]

[HKEY_CLASSES_ROOT\myth\shell\open]

[HKEY_CLASSES_ROOT\myth\shell\open\command]
@="\"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe\" \"%1\""
  • Note: Make sure the vlc.exe file is in the correct directory above.
  • Note: You can use other media players but VLC has much better seek hotkeys, i.e. try the forward/backward buttons on your mouse, CTRL-right arrow or ALT-right arrow!

Configuring Linux Samba Shares

On your MythTV backend we are going to add a Samba share which will allow any Windows machine on the network to see all the recordings in the recordings directory on a read-only basis. First make sure the Samba and Lisa daemons are running and will start automatically on bootup:

# /sbin/chkconfig lisa on
# /sbin/service lisa start
# /sbin/chkconfig smb on
# /sbin/service smb start

Now, you could edit "/etc/exports" file and add a line to it like "/video/recordings/ *(r,async,all_squash)" (and restart samba) but it is easier to use the graphical interface of KDE. From the start menu, go to Control Panel -> Internet & Network -> Samba Configuration. You can then click the "Administrator Mode", enter the Root password, and setup the "Base Settings", i.e. Workgroup, Netbios name (leave as default) and the description. Then click on "File Sharing" above in the sidebar and go into "Administrator Mode" again, and "Add" the directory that contains all the MythTV recordings, for example "/video/recordings". Set the share to "visible" but not "writable" to avoid having recordings deleted. The name of the share is used by windows, you could call it "recodings".

  • Note: If you can't see anything under the "Samba Configuration" or "File Sharing", check if the processes are running:
# ps -A | grep lisa
# ps -A | grep smb

You should also have set the hostname for the machine at this point by

# hostname MyMythBackend

and replace "MyMythBackend" with whatever you want.

  • Note: One of the benefits of having Samba running is that you can now access MythWeb with the hostname, for example http://MyMythBackend/mythweb

Now check if your Windows machine can see the recordings directory because there is little point in continuing if it can't. (Give it a few minutes, finding new shares can be slow as it discovers clients, figures out who is the master, etc.) One way to see the share is to enter the following in the Windows Explorer address bar:

\\MyMythBackend\recordings\

replacing the host and share name with yours. Another way is to click on the Start Menu, click Run, and type that into the run command. ie \\192.168.1.123\\recordings\

Modifying Mythweb to View Recordings

The next step is to pass to VLC a URL from Mythweb that it can then use to play the recording off the samba share.

This would have been dead easy through the MythWeb interface because you can modify the value needed under the MythWeb settings page (Click the icon next to the weather icon) -> "MythTV global defaults" -> "Video URL", but it doesn't work (as of v0.20). Once you hit "Save" any required backward slashes "\" are replaced with "/" forward slashes which windows and VLC won't recognize. In other words, what you need is something like:

myth:\\MyMythBackend\recordings

but hitting save changes it to

myth://MyMythBackend/recordings

The only way is to modify the field directly in the database from a terminal window:

# mysql -u root mythconverg
(enter the password)
mysql> UPDATE `settings` SET `data` = 'myth:\\\\MyMythBackend/recordings/',
`hostname` = NULL WHERE `value` = 'WebVideo_URL' AND `hostname` IS NULL LIMIT 1 ;
  • Note The multiple backslashes are required, and yes there are forward and back slashes in there but VLC figures it out.
  • Note Since this database setting does not exist by default you need to either save something in "MythTV global defaults" -> "Video URL" through MythWeb prior to executing the UPDATE, or change the mysql command to INSERT the setting.
  • Note: You should only have to do this once and no modifications are necessary for future upgrades (Yah!!)

Now if you go back into MythWeb settings page -> MythTV global defaults, you should see the value you modified directly. If you hit the recordings page and hold you mouse over a thumbnail, you should see in the status bar a link like:

myth:\\MyMythbackend/recordings/1043_20060919140000.mpg

and if you click on it, it should bring up VLC and start playing the recording.

Slave Back End

The problem with the above code is that some of the recordings could be on a slave backend which means the path to the samba share will not work. The code below will modify the path based on which backend the file resides on. Note:

  • It only works for one slave back end
  • It uses the difference in the .filename attribute, which for slave backends in my case starts with "mythtv" and for files on my master backend start with "/MythTV". It maybe different on your system - check the HTML source of the recordings page to know for sure.

First you need another URL in your DB

INSERT `settings` SET `hostname` = NULL WHERE CONVERT( `value` USING utf8 ) = 'WebVideo_URL_slave' AND CONVERT( `data` USING utf8 ) = 'myth:\\\\mythfrontendhd/hdrecordings/' AND CONVERT( `hostname` USING utf8 ) IS NULL LIMIT 1 ;

Modify the "myth:\\\\" part to point to your samba share on your slave, then you will need to modify a file:

#cd /var/www/html/mythweb/modules/tv/tmpl/default
#cp recorded.php recorded.php_old
#nano recorded.php

On line 272 or abouts, inside the IF statement underneath where it says:

if (file_exists(cache_dir.'/'.basename($show->filename).'.png')) {
  list($width, $height, $type, $attr) = getimagesize(cache_dir.'/'.basename($show->filename).'.png');

Add the following code:

               $pos1 = stripos($show->filename, "mythtv");
               $video_url_slave = setting('WebVideo_URL_slave');
               if ($pos1 == "")
                       $modified_url= $video_url_slave.str_replace('%2F', '/',rawurlencode(basename($show->filename)));
               else
                       $modified_url=$show->url;

The first line tests where in the recording's filename the word mythtv is. It then gets the path to the slave's samba share from the database (WebVideo_URL_slave). The IF statement then tests the position of "mythtv" is at the start of the filename, i.e. if the filename starts with "mythtv%2F//192.168.xxx.xxx...", then it is a slave recording. Otherwise if the position of "mythtv" is 1 or greater, i.e. "mythtv" is here "/MythTV/...." then it uses the normal URL. It isn't elegant but it works.

The last change to code is in three places, directly below the IF statement, where it creates the links for the thumbnail, the title and the subtitle, change

"$show->url" to "$modified_url". 

Reload the recordings page and if it works, then backup your file

#cp recorded.php recorded.php_modified

When the next update overwrites your modified file, copy your custom file back over the new file.

Troubleshooting

There are lots of things that can go wrong and the best way to fix it is to track backwards.

  • Can you see the samba share on your windows machine?
  • Is the directory and file in the place you expect, i.e. \\MyMythbackend\recordings\<etc>
  • Can you open that file over the share manually with VLC?
  • Is the path being generated by MythWeb correct?

After working through the section above for Playing Recordings On Windows From MythWeb, when I went to the recordings page and held my mouse over a thumbnail, I didn't see, in the status bar, a link like:

 myth:\\MyMythbackend/recordings/1043_20060919140000.mpg

and, therefore, clicking on the link did nothing. All of the thumbnail links had only the base URL:

 myth:\\MyMythbackend/recordings/

The only way I could fix the problem was to edit the utils.php file (on my system, it's in /var/www/html/mythweb/includes). In the function video_url, I changed it from:

// Global override?
       $video_url = setting('WebVideo_URL');
       if ($video_url)
           return $video_url;

to:

// Global override?
       $video_url_base = setting('WebVideo_URL');
       if ($video_url_base) {
           $video_url = "$video_url_base"
                   .str_replace('%2F', '/', rawurlencode(basename($show->filename)));
           return $video_url;
       }

Modifying MythWeb to View Videos

  • Big Note: This no longer works in the latest versions and I got sick of modifying the files after every upgrade. This needs to be properly address in the root code tree.

If you have videos you want to view directly through MythWeb, you can also share it via samba and modify MythWeb to create the correct links, but it requires modifying one file (assuming you use the default skin): Modify

  • /mythweb/modules/video/handler.php

Change the line at the very bottom which starts with:

$this-url = root . implode (...)

with

$this->url = root . preg_replace('#^'.$mythvideo_dir.'/?#', 'myth:\\\\\\\\\\MyMythBackend\\videos\\', $this->filename);

Note:

  • That's eight backslashes
  • and the URL should point to your videos directory over the samba share.

Now when you visit the video section of MythWeb, the link should be correct and bring up the movie in VLC when clicked on. The link should look something like this:

myth:\\MyMythBackend\videos\myfavoritemovie.avi

Troubleshooting

  • Again, make sure you can get to the video share directly first.
  • It should also handle sub directories.

Modifying MythWEB to point at mapped drives

If you would like MythWEB to send a URL of a locally mapped drive to VLC, simply modify /mythweb/modules/tv/tmpl/default/recorded.php

Case:

  • Remote recordings directory is mapped to a local drive letter, ie:(/mnt/share == Z:)
  • VLC and video player is working correctly.
  • You want to click on the shows thumbnail to play.

--- Fix:

Modify line 274 in /mythweb/modules/tv/tmpl/default/recorded.php from:

echo "<a href=\"$show->url\" name=\"$row\">"

To:

(replace '///Z:/' with the drive and path of choice)

echo "<a href=\"myth:///Z:/".basename($show->filename)."\" name=\"$row\">"

  • Note: Depending on your video player, it might not accept '/' in the URL. Change to accepted path format of video player.

Other alternatives

MythTv Player - MythTv Player is a free and simple Myth client and player for Windows.

Tapeworm - TapeWorm is a "parasitic" Windows front end for MythTV