<div dir="ltr"><div><div><div><div><div><div>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. <br><br></div>1. Install Ubuntu 14.04 LTS as per instructions here:<br><br><a href="https://wiki.ubuntu.com/ARM/RaspberryPi">https://wiki.ubuntu.com/ARM/RaspberryPi</a><br><br></div>-> I installed the lubuntu-desktop<br><br></div>2. Install mythtv and mythweb with apt-get<br><br></div>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:<br><br>[client]<br>port        = 3306<br>socket        = /var/run/mysqld/mysqld.sock<br><br><br>[mysqld_safe]<br>socket        = /var/run/mysqld/mysqld.sock<br>nice        = 0<br><br><br>default-storage-engine=MyISAM<br>default-tmp-storage-engine=MyISAM<br>skip-innodb<br><br>[mysqld]<br>user        = mysql<br>pid-file    = /var/run/mysqld/mysqld.pid<br>socket        = /var/run/mysqld/mysqld.sock<br>port        = 3306<br>basedir        = /usr<br>datadir        = /var/lib/mysql<br>tmpdir        = /tmp<br>lc-messages-dir    = /usr/share/mysql<br>skip-external-locking<br>sort_buffer_size = 4M<br>read_buffer_size = 4M<br>net_buffer_length = 1M<br>key_buffer = 4M<br>max_allowed_packet = 2M<br>myisam_sort_buffer_size = 8M<br>thread_stack =  64k<br>thread_cache_size       = 4<br>table_open_cache = 128<br>table_definition_cache = 400<br><br>myisam-recover         = BACKUP<br>max_connections        = 40<br>thread_concurrency     = 5<br>query_cache_limit    = 4M<br>query_cache_size        = 24M<br>query_cache_type        = 1<br>join_buffer_size        = 260k<br>log_error = /var/log/mysql/error.log<br>expire_logs_days    = 10<br>max_binlog_size         = 100M<br><br><br><br>[mysqldump]<br>quick<br>quote-names<br>max_allowed_packet    = 16M<br><br>[mysql]<br><br>[isamchk]<br>key_buffer = 8M<br>sort_buffer_size = 8M<br>!includedir /etc/mysql/conf.d/<br><br></div>4.  Tweak apache to reduce memory usage:  <br><br><br><br>KeepAlive On<br>MaxKeepAliveRequests 5<br>KeepAliveTimeout 5<br><br><br>and also in mods-available/mpm_prefork.conf:<br><br><IfModule mpm_prefork_module><br>    StartServers             2<br>    MinSpareServers          1<br>    MaxSpareServers         1<br>    MaxRequestWorkers      10<br>    MaxConnectionsPerChild   0<br></IfModule><br><br></div><div>5.  I needed X for mythtv-setup but I turn it off and run the RPI 2 headless with<br></div><div>    service lightdm stop<br><br></div><div>6.  Turn off unecessary daemons such as bluetooth, cups<br><br></div><div>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. <br><br></div><div>8.  If you plan on doing transcoding, then you need the MPEG2 and VC1 licenses activated.  Then proceed to install gstreamer according to :<br>  <a href="http://www.onepitwopi.com/raspberry-pi/gstreamer-1-2-on-the-raspberry-pi/">http://www.onepitwopi.com/raspberry-pi/gstreamer-1-2-on-the-raspberry-pi/</a><br><br></div><div>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 :<br><br><a href="https://blankstechblog.wordpress.com/2015/01/25/hardware-video-encoding-progess-with-the-raspberry-pi/">https://blankstechblog.wordpress.com/2015/01/25/hardware-video-encoding-progess-with-the-raspberry-pi/</a><br><br></div><div>My final encoding pipeline:<br><br>gst-launch-1.0  -e filesrc location="${INPUT}" \<br>! decodebin name=demux \<br>! queue \<br>! avenc_ac3 \<br>! mux. mpegtsmux name=mux \<br>! filesink location="temp.ts" demux. \<br>! queue \<br>! videoconvert \<br>! yadif \<br>! videoconvert \<br>! videoscale \<br>! videoconvert \<br>! omxh264enc target-bitrate=${TARGET_BIT_RATE} control-rate=1 inline-header=true periodicty-idr=250 interval-intraframes=250 \<br>! video/x-h264,width=${TARGET_WIDTH},height=${TARGET_HEIGHT}, \<br>      stream-format=byte-stream,profile=high \<br>! h264parse \<br>! mux.<br><br></div><div>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.   <br><br>gst-launch-1.0 -v -e filesrc location="${INPUT}" \<br>! decodebin name=demux \<br>! queue \<br>! avenc_ac3 \<br>! mux. mpegtsmux name=mux \<br>! filesink location="temp.ts" demux. \<br>! queue \<br>! deinterlace mode=1 method=5 \<br>! videoconvert \<br>! videoscale \<br>! videoconvert \<br>! omxh264enc target-bitrate=2000000 control-rate=1 inline-header=true periodicty-idr=250 interval-intraframes=250 \<br>! video/x-h264,width=${TARGET_WIDTH},height=${TARGET_HEIGHT}, \<br>      stream-format=byte-stream,profile=high \<br>! h264parse \<br>! mux.<br></div><div><br></div><div>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.  <br><br></div><div>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. <br><br></div><div>10.  Only use one external hard drive for USB recordings.  Multiple USB devices will share the throughput along with the ethernet.  <br><br></div><div><br></div><div>I am using Openelec on another pi to connect to the mythbox.  That RPI 2 also includes the MPEG2 and VC1 licenses.  <br><br></div><div>Where to go from here:  <br></div><div>--> 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.  <br><br></div><div>--> Hardrive spin down?<br><br></div><div>--> other power saving parameters, turn off HDMI?<br></div><div><br></div><div>--> get watchdog properly working<br><br></div><div>--> get a RTC module<br><br></div><div>--> will it run asterisk alongside? <br><br></div><div>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 :<br><br> <a href="http://harmdelaat.com/home-automation-with-x10-raspberry-pi-linux-and-ruby-on-rails/">http://harmdelaat.com/home-automation-with-x10-raspberry-pi-linux-and-ruby-on-rails/</a><br><br></div><div><br></div><div>Have fun tinkering.<br></div><div>Chris<br></div><div><br><br></div><div><br></div><br></div>