Announcement: Watch live TV with the HDHomeRun TV tuner

Third-party modifications and add-ons, Apps and Clients

Moderator: moderators

Announcement: Watch live TV with the HDHomeRun TV tuner

Postby diego_dambra » Fri Jan 28, 2011 8:40 pm

Using the video feature in Subsonic it's possible to setup and stream a live TV channel using the HDHomeRun TV tuner.

Image

How it works: Allows you to select a TV channel and view it through Subsonics JW flash player (ffmpeg is then used to transcode the HDHomeRun video stream and play it).

Requirements: HDHomeRun TV tuner, hdhomerun.pl script (to be placed in the Subsonic transcode folder), hdhomerun_config tool and Perl.

How to set it up:
- download the hdhomerun.pl script and copy it to your Subsonic transcode folder (/var/subsonic/transcode/)
- ensure the script has execute permission (chmod 755 hdhomerun.pl)
- add folder with HDHomeRun .strm files to Subsonic - Settings -> Music folders -> Add music folder (see below, if you need help with .strm files)
- add .strm extension to Subsonics Video mask - Settings -> General -> Video mask -> add .strm to the end of the listed extensions
- add new transcoding to Subsonic - Settings -> Transcoding:
Name: strm > flv, Convert from: strm, Convert to: flv, Step 1: hdhomerun.pl -s %s, Step 2: ffmpeg -ss %o -i - -async 1 -b %bk -s %wx%h -ar 44100 -ac 2 -v 0 -f flv - (and ensure Default and Enable are checked and then click the Save button)
- the new transcoding must then be enabled for the Players you've configured - Settings -> Players -> Select player -> Active transcoding: check strm > flv and then click Save (repeat for each player you plan to use)
- done

How to use:
- Navigate to your folder with .strm files and click play on any of the listed channel files - streaming will be shortly.

Advanced configuration:
- see hdhomerun.pl -h for advanced usage, e.g. set specific tuner or select first available. Add options to the Subsonic transcoding step.

Issues:
- video stutter - check CPU usage, transcoding requires a lot of CPU and if it hits 100% you'll probably experience bad quality. Try lower quality, e.g. 400kps through the JW flash player.
- MS Windows support, the script will need some tweaking to work. Post if of any interest.

How to create HDHomeRun .strm files with TV channel information:
- you can use the hdhomerun.pl script to create .strm files, see -h for usage (hdhomerun.pl -h)
- or, head to Silicondust for information using the HDHomeRun tools to create .strm files
Last edited by diego_dambra on Wed Feb 02, 2011 10:42 am, edited 2 times in total.
diego_dambra
 
Posts: 5
Joined: Tue Jan 25, 2011 8:12 pm

Reserved for updates

Postby diego_dambra » Fri Jan 28, 2011 8:41 pm

Reserved
diego_dambra
 
Posts: 5
Joined: Tue Jan 25, 2011 8:12 pm

Postby alphonse55 » Fri Feb 04, 2011 12:34 am

This looks pretty great. Anyone get this to work in OS X?
alphonse55
 
Posts: 8
Joined: Tue Nov 09, 2010 3:29 pm

Re: Announcement: Watch live TV with the HDHomeRun TV tuner

Postby pbjr » Fri Aug 24, 2012 5:36 pm

Does anyone have this script file and can post it? The original link has expired.

Thanks!
pbjr
 
Posts: 1
Joined: Fri Aug 24, 2012 4:58 pm

Re: Announcement: Watch live TV with the HDHomeRun TV tuner

Postby lousyg » Sun Oct 14, 2012 10:28 am

I hate to resurrect an old post, but I too am unable to find the "hdhomerun.pl" script anywhere. Is there a chance someone still has a copy and could post it here or somewhere else so that we could access it? I would greatly appreciate it.

Thank you!
lousyg
 
Posts: 2
Joined: Sun Jul 08, 2012 12:14 pm

Re: Announcement: Watch live TV with the HDHomeRun TV tuner

Postby sircurmudgeon » Mon Oct 15, 2012 1:15 am

For anyone still looking for this script, I did a cat to a terminal so we're not just looking for mirrors constantly (code follows)
select all, paste to a file in /var/subsonic/transcode/
You may need root depending on how you installed ss. You're welcome!

Code: Select all
#!/usr/bin/perl
#safety
use strict;
use warnings;

#includes
use Getopt::Long;

#secure shell
$ENV{'PATH'} = '/bin:/usr/bin';
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};

=head1 NAME

hdhomerun.pl - setup and stream channel from HDHomeRun

=head1 VERSION

Version 0.01

=cut

my $VERSION = "0.01";

=head1 SYNOPSIS

Setup and stream HDHomeRun channel to STDOUT.

To use it, do:

    hdhomerun.pl -h

=head1 EXPORT

All private methods listed below.

=head1 SUBROUTINES/METHODS

=cut

#help text
sub usage {
    print <<"EOT";
Usage: hdhomerun.pl [ options ]

    -s, --stream-channel PATH
        Path to .strm file with frequence and program of HDHomeRun TV channel

    -t, --tuner ID
        HDHomeRun Tuner ID to stream from (if set to [any], first available is used)
        (default: 0)

    -i, --id ID
        HDHomeRun device ID
        (default: FFFFFFFF)

    --scan
        Channel scan and create .strm files (requires [--folder] option)
   
    --folder PATH
        Path to folder where channels found during scan are saved as .strm files

    --version
        Show version information
       
    --help
        This message

Example:
    # hdhomerun.pl -s PATH/CNN.strm > /tmp/stream.mpeg
    (stream to file)
   
    # hdhomerun.pl -s PATH/CNN.strm | ffmpeg -ss 0 -i - -async 1 -b 400k -s 480x320 -ar 22050 -ac 1 -v 0 -f flv -
    (stream to ffmpeg and convert it to Flash Video)

EOT
    exit 0;
}

#vars we need
my $tuner = 0;
my $id    = 'FFFFFFFF';
my ( $folder, $stream_channel, $scan );

#get arguments
GetOptions(
    's|stream-channel=s' => \$stream_channel,
    'i|id=s'             => \$id,
    't|tuner=s'          => \$tuner,
    'folder=s'           => \$folder,
    'scan'               => \$scan,
    'help'               => \&usage,
    'version'            => sub { print "Setup and stream HDHomeRun channel - version $VERSION\n"; exit 0; },
) || &usage;

#check environment
my $hd_cmd = `which hdhomerun_config`;
die "FATAL: unable to locate needed HDHomeRun util: hdhomerun_config - please install it to use this script..."
  unless ($hd_cmd);

#get available tuner
if ( $tuner eq 'any' ) {
    $tuner = get_available_tuner($id);
    die "FATAL: unable to find available HDHomeRun tuner" unless ( defined($tuner) && $tuner =~ /^\d$/ );
}

#type of action
if ($stream_channel) {

    #read channel file
    open( CH, "<$stream_channel" ) || die "unable to open for read: <$stream_channel> - $!";
    my $hd = <CH>;
    close(CH);
    my ( $channel, $program );
    if ( $hd =~ /channel=([^\&]+)\&program=(\d+)/ ) {
        $channel = $1;
        $program = $2;
    }
    else {
        die "FATAL: unable to read program and channel frequence - <$hd>";
    }

    #setup HDHomeRun
    setup_hdhomerun( $id, $tuner, $channel, $program );

}
elsif ($scan) {

    #scan for channels
    print "Channel scan HDHomeRun device: <$id>, tuner: <$tuner>"
      . " - this will take some time, please be patient...\n";
    scan_hdhomerun( $id, $tuner, $folder );
}

=head2 get_available_tuner($id)

    Get a HDHomeRun tuner currently available
    arg0: str with HDHomeRun ID
    ret0: int 0|1 with tuner (undef if unable to find available tuner)

=cut

sub get_available_tuner {
    my $id = shift;

    #HDHomeRun command to get tuner target
    my $hdhomerun = "hdhomerun_config";
    foreach my $t ( 0, 1 ) {
        my $target = `$hdhomerun $id get /tuner$t/target`;
        return $t if ( $target =~ /none/ );
    }
}

=head2 setup_hdhomerun($id, $tuner, $channel, $program, $target)

    Setup HDHomeRun to begin streaming
    arg0: str with HDHomeRun ID
    arg1: int 0|1 with tuner to use
    arg2: str with channel, e.g. a8qam64-6875:626000000
    arg3: int with program, e.g. 6120

=cut   

sub setup_hdhomerun {
    my $id      = shift;
    my $tuner   = shift;
    my $channel = shift;
    my $program = shift;

    #HDHomeRun commands
    my $hdhomerun   = "hdhomerun_config";
    my $def_args    = "$id set /tuner" . $tuner;
    my $set_channel = $def_args . "/channel $channel";
    my $set_program = $def_args . "/program $program";

    #start HDHomeRun stream
    system("$hdhomerun $set_channel");
    system("$hdhomerun $set_program");
    sleep 1;
    system( "$hdhomerun $id save /tuner" . $tuner . " -" );
}

=head2 scan_hdhomerun($id, $tuner, $folder)

    Setup HDHomeRun to begin streaming
    arg0: str with HDHomeRun ID
    arg1: int with HDHomeRun tuner
    arg2: str with path to folder where files should be created

=cut   

sub scan_hdhomerun {
    my $id     = shift;
    my $tuner  = shift;
    my $folder = shift;

    #check folder exists
    die "FATAL: please enter a valid folder..." unless ( defined($folder) && -d "$folder" );

    #HDHomeRun command
    my $hdhomerun = "hdhomerun_config";
    my $def_args  = "$id scan /tuner" . $tuner;

    #read scanning result from STDIN
    my ( $frequence, $qam, $name, $program );
    my %prg;
    open( SCAN, "$hdhomerun $def_args |" ) || die "FATAL: unable to open for read: <$hdhomerun $def_args>";
    while (<SCAN>) {
        $frequence = $1 if (/^SCANNING: (\d+) /);
        undef($frequence) if (/^LOCK: none/);
        next unless ($frequence);
        $qam = $1 if (/^LOCK: ([\w-]+)/);
        if (/^PROGRAM (\d+): 0 (.+)/) {
            $program = $1;
            $name    = $2;
            next if ( $name =~ /encrypted/ );
            $name =~ s/[\W]//g;
            $prg{$name} =
                "hdhomerun://"
              . $id
              . "-$tuner/tuner"
              . $tuner
              . "?channel="
              . $qam . ":"
              . $frequence
              . "&program="
              . $program;
        }
    }
    close(SCAN);

    #check channels was found
    die "WARN: no channels found - check your HDHomeRun configuration: <$hdhomerun $def_args>" if ( !%prg );

    #write channels to folder
    foreach my $p ( keys %prg ) {
        open( PRG, ">$folder/$p.strm" ) || die "FATAL: unable to open for write: <$folder/$p.strm> - $!";
        print PRG "$prg{$p}\n";
        close(PRG);
    }
}

=head1 ACKNOWLEDGEMENTS


=head1 LICENSE AND COPYRIGHT

Copyright 2010/2011 Diego d'Ambra (diegoatdambra.dk) / Nikolaj Steensgaard (nikolajatsteensgaard.net)

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

=cut
sircurmudgeon
 
Posts: 1
Joined: Mon Oct 15, 2012 1:08 am

Re: Announcement: Watch live TV with the HDHomeRun TV tuner

Postby r3dsk1n » Mon Dec 31, 2012 2:38 am

Is there anyway to get this to work with a different tuner?
r3dsk1n
 
Posts: 4
Joined: Mon Dec 31, 2012 2:36 am

Re: Announcement: Watch live TV with the HDHomeRun TV tuner

Postby tguless » Mon Jan 28, 2013 1:03 am

There's an analog thread to this on the Silicondust website:

http://www.silicondust.com/forum2/viewt ... 950#p83950
tguless
 
Posts: 26
Joined: Fri Jul 23, 2010 6:22 pm

Re: Announcement: Watch live TV with the HDHomeRun TV tuner

Postby lolomm » Sat Nov 30, 2013 7:01 pm

want that for dreambox or vu+ :D
lolomm
 
Posts: 13
Joined: Fri Nov 29, 2013 10:20 am


Return to Mods, Apps and Clients

Who is online

Users browsing this forum: No registered users and 12 guests