Difference between revisions of "Dreambox-NetworkRecorder"
(→The channel change script) |
(→The channel change script) |
||
Line 208: | Line 208: | ||
if($DEBUG==1) { echo "Mythtv scan log mode\n"; } | if($DEBUG==1) { echo "Mythtv scan log mode\n"; } | ||
− | + | $fp2=fopen("php://stdin","r"); | |
while(!feof($fp2)) | while(!feof($fp2)) | ||
{ | { |
Revision as of 12:18, 4 January 2010
Contents
Description
With this document i would like to help how to connect one or more dreamboxes (Dreambox/Enigma2 DVB receiver) as a "network recorder/FreeBox" to MythTV. In this configuration the dreambox acts as a tunercard in the MythTV enviroment.
Requirements
- A running MythTV installation (I tested it with 0.21 + 0.22)
- One or more dreamboxes with Enigma2 OS/Firmware
- Skills to install and configure scripts on linux
Base Facts
- The dreambox has the ability to stream a TV-Channel over http protocol.
- MythTV offers an IP/TV Network Recorder called FREEBOX.
- IP/TV Network Recorder supports UDP and RTSP protocols, but not HTTP streaming!
- MythTV supports external channel change script
- VLC is able to read the http stream and send it over udp to the MythTV Network recorder.
In theory, with the above it should be possible to implement everything we need.
Installation/Configuration
Create a directory on your MythBackend to store most of your work. Example: /opt/dreambox
Configure the dreamboxes
Make sure that your dreambox has a static ip-address in your network. On the webinterface of the dreambox you will find the streaming urls for each channel you want to add.
Example URL: http://DREAMBOX_IP:8001/1:0:1:140:39:1:FFFF0222:0:0:0:
Feel free to test it with a VLC player.
Setting up VLC in daemon mode
Create a vlm config file for the vlc daemon. Example: /opt/dreambox/dreambox.vlm This example shows the configuration for 3 Dreambox receivers and two channels. Output goes to your Mythbackend. For each dreambox you should use a different UDP port.
I know, this will get a big config file. Don't worry, read on, later you will find a script that generates this file.
The naming of the broadcast vlc resources is important. D1_1 stands for: Dreambox 1, Channel 1. D2_2 stands for Dreambox 2, Channel 2
# Channel 'SF1' on Dreambox #1 new D1_1 broadcast enabled setup D1_1 input http://DREAMBOX1_IP:8001/1:0:1:2:45:1:FFFF0292:0:0:0: setup D1_1 output udp://MYTHBACKEND_IP:1234 # Channel 'SF1' on Dreambox #2 new D2_1 broadcast enabled setup D2_1 input http://DREAMBOX2_IP:8001/1:0:1:2:45:1:FFFF0292:0:0:0: setup D2_1 output udp://MYTHBACKEND_IP:1235 # Channel 'SF1' on Dreambox #3 new D3_1 broadcast enabled setup D3_1 input http://DREAMBOX3_IP:8001/1:0:1:2:45:1:FFFF0292:0:0:0: setup D3_1 output udp://MYTHBACKEND_IP:1236 # Channel 'SF2' on Dreambox #1 new D1_2 broadcast enabled setup D1_2 input http://DREAMBOX1_IP:8001/1:0:1:3:45:1:FFFF0292:0:0:0: setup D1_2 output udp://MYTHBACKEND_IP:1234 # Channel 'SF2' on Dreambox #2 new D2_2 broadcast enabled setup D2_2 input http://DREAMBOX2_IP:8001/1:0:1:3:45:1:FFFF0292:0:0:0: setup D2_2 output udp://MYTHBACKEND_IP:1235 # Channel 'SF2' on Dreambox #3 new D3_2 broadcast enabled setup D3_2 input http://DREAMBOX3_IP:8001/1:0:1:3:45:1:FFFF0292:0:0:0: setup D3_2 output udp://MYTHBACKEND_IP:1236
You can now start/test your vlc daemon on your backend with the following command:
su - ACCOUNT_NAME -c 'vlc -I telnet --vlm-conf /opt/dreambox/dreambox.vlm --daemon'
ACCOUNT_NAME: Your account, because root is a bad choice.
Telnet to your VLC daemon and check your channels:
telnet MYTHBACKEND_IP 4212
The default password is 'admin'. Type 'show' to list your VLC streams. 'quit' to logout.
Configure MythTV
Creating the .m3u files
Each IP/TV Networkrecorder (FREEBOX), requires a .m3u playlist as a channel list. The channel scanner on Myth fetches the config file via HTTP. Create a new directory on your local webserver:
mkdir /var/www/dreambox
create the config files in there:
>:/var/www/dreambox# ls -l total 12 -rw-r--r-- 1 root root 2444 2010-01-02 22:15 dreambox1.m3u -rw-r--r-- 1 root root 2444 2010-01-02 22:15 dreambox2.m3u -rw-r--r-- 1 root root 2444 2010-01-02 22:15 dreambox3.m3u
It should have the following format:
dreambox1.m3u:
#EXTM3U #EXTINF:0,1 - SF1 #EXTMYTHTV:xmltvid=1.sfdrs.ch udp://MYTHBACKEND_IP:1234 #EXTINF:0,2 - SF2 #EXTMYTHTV:xmltvid=2.sfdrs.ch udp://MYTHBACKEND_IP:1234
dreambox2.m3u:
#EXTM3U #EXTINF:0,1 - SF1 #EXTMYTHTV:xmltvid=1.sfdrs.ch udp://MYTHBACKEND_IP:1235 #EXTINF:0,2 - SF2 #EXTMYTHTV:xmltvid=2.sfdrs.ch udp://MYTHBACKEND_IP:1235
dreambox3.m3u:
#EXTM3U #EXTINF:0,1 - SF1 #EXTMYTHTV:xmltvid=1.sfdrs.ch udp://MYTHBACKEND_IP:1236 #EXTINF:0,2 - SF2 #EXTMYTHTV:xmltvid=2.sfdrs.ch udp://MYTHBACKEND_IP:1236
Take care that the UDP Ports are corresponding to the VLC configuration. The Channel Number 1,2 should also correspond to the VLC Stream Name.
VLC Config: D1_1 -> dreambox.m3u: 0,1 VLC Config: D1_2 -> dreambox.m3u: 0,2
Again, this will be a big config file. Read ahead, you will receive a script that go generate this config file too.
Try to fetch it in your browser: http://MYTHBACKEND_IP/dreambox/dreambox1.m3u
Add the IP/TV Network Recorder
Startup your MythTV Backend Setup.
If you like, you may create a new video source for the dreamboxes:
"3. Video sources" -> "New video source"
For each dreambox you have to add a Network Recorder:
"2. Capture cards" -> "New capture card"
Card Type: Network Recorder M3U URL: http://MYTHBACKEND_IP/dreambox/dreambox1.m3u
Scan the channels:
"4. Input connections" -> "Select the new "FREEBOX..."
Select the video source and "Scan for channels"
The channel change script
Each Network Recorder must have its channel change script. I have implemented it in two scripts. Put this scripts in your /opt/dreambox directory
The first one is an expect script that talks to the VLC daemon via telnet and drops commands to it. It is called "VLC_CMD"
#!/usr/bin/expect log_user 0 set timeout 50 set cmd1 [lindex $argv 0] set cmd2 [lindex $argv 1] spawn telnet localhost 4212 expect "Password: " send "admin\n" expect "> " send "$cmd1\n" expect "> " send "$cmd2\n" expect "> " send "quit\n"
The second script is written in PHP. With help of the first script it changes the channel by stopping the current running stream and starts the new one. The current channel will be stored as well. If you don't have the php interpreter you have to installed it:
apt-get install php-cli
The second script, i called it VLC_CONTROL:
#!/usr/bin/php <? $DEBUG=0; // Log entry witch shows us, that a recorder has stopped. $MYTH_LOG_PATTERN="/.*TVRec\(%d\): Changing from Watching .* to None.*/"; // Encodernumbers for all dreamboxes/enimga2 $DBOX_IDS=array(1,2,3,4); // Nothing to change below $info=pathinfo($argv[0]); $DBOX=$info["basename"]; $DIR=$info["dirname"]; if($DEBUG==1) { echo "Starting as ".$DBOX."\n"; print_r($argv); } if($argv[1]=="SCAN_SWITCH_OFF") { if($DEBUG==1) { echo "Mythtv scan log mode\n"; } $fp2=fopen("php://stdin","r"); while(!feof($fp2)) { $line=fgets($fp2,256); // For each dreambox for($i=0;$i<count($DBOX_IDS);$i++) { $scan=sprintf($MYTH_LOG_PATTERN,$DBOX_IDS[$i]); if(preg_match($scan,$line)==1) { $DBOX="D".$DBOX_IDS[$i]; if($DEBUG==1) { echo "Matched: ".$scan."\nStopping ".$DBOX."\n"; } ## Get previous channel list($prev_channel)=file($DIR."/.".$DBOX); if($DEBUG==1) { echo "Prev. Channel ".$prev_channel."\n"; } $cmd1="control ".$DBOX."_".$prev_channel." stop"; $ex=$DIR."/VLC_CMD '".$cmd1."'"; if($DEBUG==1) { echo "exec ".$ex."\n"; } system($ex); if($DEBUG==1) { echo "done\n"; } } } } exit; } else { ## Get previous channel list($prev_channel)=file($DIR."/.".$DBOX); if($DEBUG==1) { echo "Prev. Channel ".$prev_channel."\n"; } $cmd1="control ".$DBOX."_".$prev_channel." stop"; $cmd2="control ".$DBOX."_".$argv[1]." play"; $ex=$DIR."/VLC_CMD '".$cmd1."' '".$cmd2."'"; if($DEBUG==1) { echo "exec ".$ex."\n"; } system($ex); if($DEBUG==1) { echo "Storing Channel\n"; } $fp2=fopen($DIR."/.".$DBOX,"w"); fputs($fp2,$argv[1]); fclose($fp2); } ?>
Dont forget to make the scripts executable to mythtv:
chmod 755 /opt/dreambox/VLC*