[mythtv-users] Raspberry PI 2 as a mythtv backend.
Chris Isip
cmisipster at gmail.com
Sun Aug 9 00:31:02 UTC 2015
I was able to get mythtv backend running in Raspberry PI 2 and it seems to
be running fine. For anybody trying to get the same setup working, here
are the general steps I followed. If anybody has suggestions for improving
things, tweaks, etc please feel free to comment. There's not very much
information about mythtv backend running on Raspberry pi 2 as I have found
out. PLEASE I AM NOT RESPONSIBLE FOR ANY DAMAGE THIS WILL DO TO YOUR
SYSTEM. Use at your own risk. I am using HDhomerun networked MPEG2
recorder.
1. Install Ubuntu 14.04 LTS as per instructions here:
https://wiki.ubuntu.com/ARM/RaspberryPi
-> I installed the lubuntu-desktop
2. Install mythtv and mythweb with apt-get
3. Tweak mysql to reduce memory usage. You need to disable support for
innodb but make sure you have converted existing tables (if any) that use
innodb to myisam. Mythtv uses myisam exclusively. Here are the contents
of my.cnf:
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
default-storage-engine=MyISAM
default-tmp-storage-engine=MyISAM
skip-innodb
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
sort_buffer_size = 4M
read_buffer_size = 4M
net_buffer_length = 1M
key_buffer = 4M
max_allowed_packet = 2M
myisam_sort_buffer_size = 8M
thread_stack = 64k
thread_cache_size = 4
table_open_cache = 128
table_definition_cache = 400
myisam-recover = BACKUP
max_connections = 40
thread_concurrency = 5
query_cache_limit = 4M
query_cache_size = 24M
query_cache_type = 1
join_buffer_size = 260k
log_error = /var/log/mysql/error.log
expire_logs_days = 10
max_binlog_size = 100M
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
[isamchk]
key_buffer = 8M
sort_buffer_size = 8M
!includedir /etc/mysql/conf.d/
4. Tweak apache to reduce memory usage:
KeepAlive On
MaxKeepAliveRequests 5
KeepAliveTimeout 5
and also in mods-available/mpm_prefork.conf:
<IfModule mpm_prefork_module>
StartServers 2
MinSpareServers 1
MaxSpareServers 1
MaxRequestWorkers 10
MaxConnectionsPerChild 0
</IfModule>
5. I needed X for mythtv-setup but I turn it off and run the RPI 2
headless with
service lightdm stop
6. Turn off unecessary daemons such as bluetooth, cups
7. Make sure you have the correct time. Use ntpdate after network is up.
The RPI does not have a real time clock and mythbackend will thrash with
100% cpu usage if it is started with the incorrect date and time. I also
run ntp daemon.
8. If you plan on doing transcoding, then you need the MPEG2 and VC1
licenses activated. Then proceed to install gstreamer according to :
http://www.onepitwopi.com/raspberry-pi/gstreamer-1-2-on-the-raspberry-pi/
gst-inspect-1.0 | grep omx will let you know if you have successfully built
the hardware decoders. The vc1 license actually includes the h264 encoder
as well. This will not build the voaacenc encoder. If you want that, you
need to install liquidsoap. In my experience, though, the files created
with voaacenc will not play on Openelec. Also mkv will not play, and avi
and mp4 had audio sync issues. The solution is to use mpegts container
with h264 video and ac3 audio. If you want to play the video in vlc on the
iphone, you need the extra step of using ffmpeg to convert the audio to
aacplus. The following site was very informative :
https://blankstechblog.wordpress.com/2015/01/25/hardware-video-encoding-progess-with-the-raspberry-pi/
My final encoding pipeline:
gst-launch-1.0 -e filesrc location="${INPUT}" \
! decodebin name=demux \
! queue \
! avenc_ac3 \
! mux. mpegtsmux name=mux \
! filesink location="temp.ts" demux. \
! queue \
! videoconvert \
! yadif \
! videoconvert \
! videoscale \
! videoconvert \
! omxh264enc target-bitrate=${TARGET_BIT_RATE} control-rate=1
inline-header=true periodicty-idr=250 interval-intraframes=250 \
! video/x-h264,width=${TARGET_WIDTH},height=${TARGET_HEIGHT}, \
stream-format=byte-stream,profile=high \
! h264parse \
! mux.
The most basic encoding pipeline will encode a one hour video in about an
hour running at full cpu speed. I found that using the gstreamer
deinterlace plugin linearblend resulted in the best quality below yadif.
Yadif takes a real long time. Its not apparent in the pipeline but
omxmpeg2decoder is being used by decodebin.
gst-launch-1.0 -v -e filesrc location="${INPUT}" \
! decodebin name=demux \
! queue \
! avenc_ac3 \
! mux. mpegtsmux name=mux \
! filesink location="temp.ts" demux. \
! queue \
! deinterlace mode=1 method=5 \
! videoconvert \
! videoscale \
! videoconvert \
! omxh264enc target-bitrate=2000000 control-rate=1 inline-header=true
periodicty-idr=250 interval-intraframes=250 \
! video/x-h264,width=${TARGET_WIDTH},height=${TARGET_HEIGHT}, \
stream-format=byte-stream,profile=high \
! h264parse \
! mux.
I initially had my system overclocked but I ran into stability issues.
Wether from the overclock or high cpu usage by the transcoder script, I am
not sure. I am running now at 800 MHz and I am using cpulimit to limit
gstreamer to 60% cpu. Also, I am only allowing one transcode at a time. (
the script checks for a running gstreamer instance and wil loop forever
unless there are no more gstreamer processes). It also has a recover
script if things go awry. I have attached my transcode script for anyone
interested. It was based on Defcronyke Webmaster script but severely
gutted for my purposes. I used the general format.
9. Disable commflagging and metadata look up in mythtv. I seem to be
unable to do this in mythtv-setup. I unchecked the appropriate settings
but mythtv insists on commflagging. My solution was to run a cron job that
deletes these types of jobs from the jobqueue every 10 minutes.
10. Only use one external hard drive for USB recordings. Multiple USB
devices will share the throughput along with the ethernet.
I am using Openelec on another pi to connect to the mythbox. That RPI 2
also includes the MPEG2 and VC1 licenses.
Where to go from here:
--> improve the encoding pipeline quality and speed. Only the
videodecoding and encoding part is hardware accelerated. The rest is done
by the cpu. At 60% cpulimit, encodes of hour long videos actually last
about 6 hours. Hopefully somebody else has ideas on how to do this. I am
not an expert. Hopefully ffmpeg will catch up with gstreamer and integrate
openmax.
--> Hardrive spin down?
--> other power saving parameters, turn off HDMI?
--> get watchdog properly working
--> get a RTC module
--> will it run asterisk alongside?
I dont know how this system will perform in the long term but it has been
fun putting it together. I have decomissioned my Core I7 from mythttv
backend duties and my laptop from XBMC duties because of this. The cost
saving is my secondary motivation. I am running this 24/7 for the past
week and trying varying encoding pipelines. I will know in about 3 hours
if the yadif pipeline is worth the extra time. This RPI 2 is proving to be
an excellent device. In addition to mythtv, I am running openvpn,
isc-dhcp-server, bind9, ufw, ssh server, heyu using :
http://harmdelaat.com/home-automation-with-x10-raspberry-pi-linux-and-ruby-on-rails/
Have fun tinkering.
Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mythtv.org/pipermail/mythtv-users/attachments/20150808/26d81b5c/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mythtv-transcode-h264.sh
Type: application/x-sh
Size: 5447 bytes
Desc: not available
URL: <http://lists.mythtv.org/pipermail/mythtv-users/attachments/20150808/26d81b5c/attachment.sh>
More information about the mythtv-users
mailing list