Skip to content

Commit a077f3c

Browse files
committed
Support generic encoders and move config to file
1 parent cbd14ec commit a077f3c

3 files changed

Lines changed: 192 additions & 121 deletions

File tree

README.md

Lines changed: 70 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,57 @@
11
# prime_encoder
22

3-
prime_encoder is network encoder for SageTV which tunes and streams video from an HDHomerunPrime.
3+
prime_encoder is network encoder for SageTV
44

5-
prime_encoder is currently considered beta. There are some things that need to be cleaned up in
6-
the code, but it has been my primary method of recording shows for the last few months with no problems.
5+
prime_encoder has been my primary method of recording shows for about five years and it has been
6+
very reliable.
77

88
## Background
99

10-
When the Silicon Dust HDHomerunPrime was released using a Cable Card suddenly seemed like a possible
11-
option with SageTV since some cable providers have channels marked as "copy freely". However, getting
12-
a working Linux driver for the Prime seemed to be challenging.
10+
When the Silicon Dust HDHomerun Prime was released using a Cable Card with SageTV suddenly seemed like
11+
a possibility since some cable providers have channels marked as "copy freely". However, there was no
12+
direct suport in SageTV for the Prime and no Linux drivers for it (as it is a network attached device).
1313

14-
I realized that the hdhomerun_config setup script allowed you to stream content from the Prime directly
15-
(other tools like ffmpeg can do this as well) - I just needed a way to get SageTV to tune the Prime.
16-
Luckily, SageTV support the concept of "network encoders" - other devices on the local network that act
17-
as tuner that SageTV can direct.
14+
The Silicon Dust hdhomerun_config setup script allowed you to stream content from the Prime directly
15+
(other tools like ffmpeg can do this as well) so I just needed a way to get SageTV to tune the Prime and
16+
start steaming. Luckily, SageTV supports the concept of "network encoders" - other devices on the local
17+
network that act as tuner/recorders that SageTV can direct.
1818

19-
So I created prime_encoder to do this middle-man task.
19+
I created prime_encoder to do this middle-man task.
2020

21-
prime_encoder script doesn't have to run on the same box as the master SageTV server. As long as you
22-
have it running somewhere on your network and have the recording directories set up correctly you
23-
should be fine. I happen to run the script on the same box as the SageTV server because the overhead of
24-
running it is fairly small and doesn't seem to impact the main SageTV performance.
21+
Originally I was using prime_encoder for recording from an HDHomerun Prime device, but it has
22+
been refactored to be more generic so that any command that generates video can be used.
2523

26-
The SageTV server will automatically discover network encoders. It sends commands to the network encoders
27-
to record video and tells the encoders where to dump the video file, so the only config option that needs to
28-
be changed on the SageTV server is to enable discovery.
24+
The full set of network encoding commands is not supported. Primarily this means you can't "preview"
25+
channels from the Setup Video Sources screen.
2926

30-
Be sure to install a startup script so that prime_encoder is started at boot time. A basic example Ubuntu script (<tt>prime_encoder.init</tt>) is included.
27+
## Install
3128

32-
Or, you can add this to the bottom of /opt/sagetv/server/sagesettings, and the encoder will start when
29+
### Notes
30+
31+
prime_encoder script doesn't have to run on the same host as the master SageTV server. You only need to
32+
have it running somewhere on your network and have the recording directories set up correctly using SMB or
33+
another sharing protocol.
34+
35+
I run the script on the same host as the SageTV server because the overhead of running it is fairly small
36+
and doesn't seem to impact SageTV performance. This has the added advantage of not having to deal with
37+
network shares or mapping the recording paths across hosts.
38+
39+
When it starts, the SageTV server will automatically discover network encoders. It sends commands to
40+
the network encoders to record video and tells the encoders where to store the video file. The only config
41+
option that needs to be changed on the SageTV server is to enable network encoder discovery.
42+
43+
### Running at startup
44+
45+
prime_encoder needs to start before the main SageTV process starts.
46+
47+
The easiest way to do this is to use the basic example Ubuntu script (<tt>prime_encoder.init</tt>).
48+
49+
Alternatively, you can add this to the bottom of /opt/sagetv/server/sagesettings, and the encoder will start when
3350
the SageTV process starts:
3451

3552
if [[ ! $(ps aux |grep "[p]rime_encoder: Master") ]]; then /opt/sagetv/hdhomerun/prime_encoder; fi
3653

37-
Note that not all commands are currently supported. Primarily this means you can't yet "preview" channels
38-
from the Setup Video Sources screen.
39-
40-
## Instructions
54+
### Assumptions
4155

4256
These directions assume a few things:
4357

@@ -46,8 +60,9 @@ These directions assume a few things:
4660

4761
IPC::Run
4862
Proc::Daemon
63+
YAML::Tiny
4964

50-
(these are libipc-run-perl and libproc-daemon-perl on Ubuntu)
65+
(these are libipc-run-perl, libproc-daemon-perl, and libyaml-tiny-perl on Ubuntu)
5166

5267
* You have a non-root user to run prime_encoder as. I use the user name 'sagetv' in the instructions below.
5368
* The sagetv user can write to the recording directories that the SageTV server uses. This might require
@@ -58,9 +73,9 @@ These directions assume a few things:
5873
* If your Linux box is running a host firewall, you'll need to open holes for UDP port 8271 and TCP
5974
ports you define later for each encoder.
6075

61-
## Install steps
76+
## Installation
6277

63-
* Create a place for the script:
78+
* Create a place for everything:
6479

6580
mkdir -p /opt/sagetv/hdhomerun
6681
chown sagetv:sagetv /opt/sagetv/hdhomerun
@@ -70,31 +85,40 @@ These directions assume a few things:
7085
chown sagetv:sagetv /opt/sagetv/hdhomerun/prime_encoder
7186
chmod +x /opt/sagetv/hdhomerun/prime_encoder
7287

73-
* Get the Linux <tt>hdhomerun_config</tt> from SD and place it in <tt>/opt/sagetv/hdhomerun/</tt>
88+
* Copy the <tt>config.example.yml</tt> to <tt>config.yml</tt>
89+
90+
* Get the Linux <tt>hdhomerun_config</tt> from Silicon Dust and place it in <tt>/opt/sagetv/hdhomerun/</tt>
7491
and make sure it's executable:
7592

7693
chown sagetv:sagetv /opt/sagetv/hdhomerun/hdhomerun_config
7794
chmod +x /opt/sagetv/hdhomerun/hdhomerun_config
7895

79-
* Make sure your HDHR Prime is already configured and enabled for CC reception. Use the SD provided tools
80-
to test that you can view video before continuing.
96+
* Make sure your HDHR Prime is already configured and enabled for CC reception. Use the Silicon Dust
97+
provided tools to test that you can view video before continuing.
8198
* Mount the recording directory from the SageTV server somewhere on your Linux box. This isn't needed if
8299
prime_encoder is running on the same server as the SageTV server.
83100
* Make sure the sagetv user can write to this directory
84-
* Run:
101+
* Discover the ID for the Prime device:
85102

86103
hdhomerun_config discover
87104

88-
* Update the encoders section of the prime_encoder script to have the id(s) of your primes. Each prime
105+
* Update the encoders section of <tt>config.yml</tt> to have the id(s) of your primes. Each prime
89106
should have 3 tuners (0,1,2) (although you don't have to enable or even list them all if you don't want
90107
to). Make sure each encoder has a unique port number and name.
91-
* Update the <tt>prime_encoder</tt> script and change the value of <tt>$ffmpeg_cmd</tt> to point to a
92-
version of ffmpeg that is 1.2.1 or higher. The version shipped with SageTV seems to be older than this,
93-
so get a more recent version. (I have seen crashes on versions earlier than 1.2.1.)
94-
* If your SageTV server is running on another host (either Windows or Linux) you'll have to update
95-
the <tt>remap_file_path</tt> function to make the path from the master server map to the path that the
108+
109+
* Edit the <tt>config.yml</tt> to match how to tune your devices. See the examples in the file.
110+
111+
* (Optional) Edit the <tt>config.yml</tt> so that the <tt>cmd_postprocess</tt> points to a version of ffmpeg
112+
that is 1.2.1 or higher. The version shipped with SageTV seems to be older than this,
113+
but a more recent version as I have seen crashes on versions earlier than 1.2.1.
114+
You do not need to specify a value for <tt>cmd_postprocess</tt> but I have found that it helps
115+
fix timing issues in the video stream that can occur when providers switch between shows and commericals.
116+
117+
* (Optional) If your SageTV server is running on another host (either Windows or Linux) you'll have to update
118+
the <tt>remap_file_path</tt> function in <tt>prime_encoder</tt> to make the path from the master server map to the path that the
96119
prime_encoder process would see. You may need to run the prime_encoder once and try tuning to see
97120
what the master server is expecting.
121+
98122
* Run <tt>prime_encoder</tt>:
99123

100124
cd /opt/sagetv/hdhomerun
@@ -117,8 +141,8 @@ These directions assume a few things:
117141

118142
* Stop your SageTV server.
119143

120-
* Make a backup of your Wiz.bin and any other file you think are important (I usually back up the entire
121-
sage directory).
144+
* *Make a backup of your Wiz.bin and any other files you think are important (I usually back up the entire
145+
sage directory).*
122146

123147
* Edit the Sage.properties file and make sure this line is there and that it's set to true:
124148

@@ -129,8 +153,8 @@ These directions assume a few things:
129153

130154
Fri Aug 9 22:44:40 2013 Discovery service announced 'HDHomerun Prime Tuner 2'
131155

132-
* In SageTV, add a new encoder. The ones you defined in the encoders config should be listed. Proceed
133-
as normal. Note: Your SageTV server may have auto-detected the Prime on the network as a two-tuner
156+
* In SageTV, add a new encoder. The ones you defined in <tt>config.yml</tt> should be listed. Proceed
157+
as normal. Note: Your SageTV server may have auto-detected the Prime on the network as a two or three tuner
134158
HDHomerun (non-Prime). Do NOT select the HDHomerun devices. Select the names you gave your devices
135159
in the prime_encoder config section, which will appear such as:
136160

@@ -141,5 +165,9 @@ These directions assume a few things:
141165

142166
Fri Aug 9 22:06:52 2013 Tuner 'HDHomerun Prime Tuner 1': Tuning channel 506 on device 131760B8 tuner 1 filename: /var/media/tv/TheBigBangTheory-TheInfestationHypothesis-15413766-0.mpg
143167

144-
* If you need to stop prime_encoder, just <tt>ps -ef | grep prime_encoder</tt>. You should see 2 processes plus
168+
* If you need to stop prime_encoder and you installed the <tt>prime_encoder.init</tt>, you can
169+
use <tt>service prime_encoder stop</tt>
170+
* If you need to stop prime_encoder and you didn't use <tt>prime_encoder.init</tt>, you can do
171+
something like: <tt>ps -ef | grep prime_encoder</tt>. You should see 2 processes plus
145172
one for each encoder you defined. Killing the "Main" process will stop the others.
173+

config.example.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
#
3+
# Where to log messages (if we are logging)
4+
#
5+
logging:
6+
dir: /opt/sagetv/hdhomerun
7+
file: prime_encoder.log
8+
9+
#
10+
# Encoders
11+
#
12+
# name - a name of the device (this will appear in the SageTV UI)
13+
# id - the ID for this device, used to identify the specific device
14+
# enabled - whether to use this encoder or not - 0 or 1
15+
# cmd_tune - command to tune the channel (optional)
16+
# cmd_encode - command to start the video capture
17+
# cmd_postprocess - command to pipe video data through (optional)
18+
#
19+
# Command strings can specify '%%CHANNEL%%' and/or '%%FILE_PATH%%' which will be replaced
20+
# with the appropriate value.
21+
#
22+
encoders:
23+
#
24+
# Example for an HDHomerun Prime
25+
# Change "12345678" to the ID of your Prime device
26+
#
27+
-
28+
name: "HDHomerun Prime Tuner 0"
29+
port: 7000
30+
enabled: 1
31+
cmd_tune: /opt/sagetv/hdhomerun/hdhomerun_config 12345678 set /tuner0/vchannel %%CHANNEL%%
32+
cmd_encode: /opt/sagetv/hdhomerun/hdhomerun_config 12345678 save 0 -
33+
cmd_postprocess: /usr/bin/ffmpeg -y -v quiet -i - -f dvd -vcodec copy -acodec copy %%FILE_PATH%%
34+
-
35+
name: "HDHomerun Prime Tuner 1"
36+
port: 7001
37+
enabled: 1
38+
cmd_tune: /opt/sagetv/hdhomerun/hdhomerun_config 12345678 set /tuner1/vchannel %%CHANNEL%%
39+
cmd_encode: /opt/sagetv/hdhomerun/hdhomerun_config 12345678 save 1 -
40+
cmd_postprocess: /usr/bin/ffmpeg -y -v quiet -i - -f dvd -vcodec copy -acodec copy %%FILE_PATH%%
41+
-
42+
name: "HDHomerun Prime Tuner 2"
43+
port: 7002
44+
enabled: 1
45+
cmd_tune: /opt/sagetv/hdhomerun/hdhomerun_config 12345678 set /tuner2/vchannel %%CHANNEL%%
46+
cmd_encode: /opt/sagetv/hdhomerun/hdhomerun_config 12345678 save 2 -
47+
cmd_postprocess: /usr/bin/ffmpeg -y -v quiet -i - -f dvd -vcodec copy -acodec copy %%FILE_PATH%%
48+
#
49+
# Example for a device attached to an HDPVR2
50+
# Change "E505-00-12345678" to the ID of your HDPVR2 device
51+
# Replace the cmd_tune command with whatever you use to tune your STB
52+
#
53+
-
54+
name: "HDPVR2 STB-1"
55+
port: 7003
56+
enabled: 1
57+
cmd_tune: /opt/sagetv/server/gentuner TUNE STB-1 %%CHANNEL%%
58+
cmd_encode: /opt/Hauppauge/bin/hauppauge2 -s E505-00-12345678 -i 3 -a 3 -d 2 -o /dev/stdout
59+
cmd_postprocess: /usr/bin/ffmpeg -y -v quiet -i - -f dvd -vcodec copy -acodec copy %%FILE_PATH%%

0 commit comments

Comments
 (0)