How to stream videos from Ubuntu to DirecTV MediaShare

DirecTV has the ability to stream videos Pictures and Music from your home computer or laptop. This is called DirecTV MediaShare.

This is normally a simple process and their are a huge slew of ways to get this working on most streaming media boxes. DirecTV is a bit harder. They require a specific format for all of their videos or else they will simply not play.

The simplest way to do this is to use any old upnp Streaming server such as uShare. But you must manually convert every Video to fit DirecTV Specifications. A major problem with this is that the resulting videos are Quite large in size. about 1.4GB for 20 minutes. When you think that most films are roughly 2 hours long, you realize that you will run out of space on your harddrive very quickly.

The optimal solution is on-the-fly transcription. A method of converting the videos into the format required at the moment it is needed.


Below I am going to explain how to set up MediaTomb to offer your videos to DirecTV MediaShare, and transcribe them on-the-fly.

You may have Read a lot of the following information elsewhere, but due to changes in technology. those resources no longer work.  The following configurations have been updated to work on Ubuntu 12.04 and greater.


Install required packages

To start off we need to install a few packages.

sudo apt-get install -y mediatomb vlc ffmpeg imagemagick mediainfo


Create transcoding scripts

Next we need to make a few scripts. The names of each script will be in bold above it.

every script MUST go into /usr/bin. 

First do a
 sudo bash
before beginning these steps. This is just for simplicity's sake you can also put a sudo before every command.

ffmpegaudio

#!/bin/bash

exec /usr/bin/ffmpeg -i "$1" -f wav - > "$2"
now run 
chmod +x /usr/bin/ffmpegaudio

ffmpegvideo

#!/bin/bash

# This script transcodes various video formats to MPEG2 Video and
# AC3 audio in an MPEG2 Transport Stream for the DirecTV HR2x
#
# FFMpeg and Mediainfo must be installed for this script to work.
#
# Input Parameters: Input, Output, Video Bitrate, Audio Bitrate
#
# Revision 2.00  11/29/2008
# Updated to work with the HR2x auto screen size feature

VBITRATE="$3"
ABITRATE="$4"

width=`/usr/local/bin/mediainfo --Inform=Video\;%Width% "$1"`
height=`/usr/local/bin/mediainfo --Inform=Video\;%Height% "$1"`

audcodec="ac3"

aspect=$(echo "scale=2; ($width/$height)*100" | bc | awk -F '.' '{ print $1; exit; }' ) 

echo $aspect
comp=175
bars=0

if [ "$aspect" -gt "$comp" ]; then
   # needs bars top and bottom
   bars=1
   pad=$(echo "scale=2; (($width/1.75)-$height)/2" | bc | awk -F '.' '{ print $1; exit; }' )
   mod=$(($pad % 2))
   compmod=1
   if [ "$mod" -eq "$compmod" ]; then
      # pad must be an even number
      pad=$((pad+1))
   fi
fi
echo $pad

# Make sure the ffmpeg path is correct
if [ "$bars" -eq 1 ]; then
   # bars top and bottom 
  exec avconv -i "$1" -b ${VBITRATE} -maxrate ${VBITRATE} -minrate ${VBITRATE} \
-bufsize 5097k -bt 380k -vf pad=0:${pad}:0:0:black   -threads 2 -ab ${ABITRATE} \
-acodec ${audcodec} -async 1 -f mpegts -y - > "$2"
else
# bars left and right
  exec avconv -i "$1" -b ${VBITRATE} -maxrate ${VBITRATE} -minrate ${VBITRATE} \
-bufsize 5097k -bt 380k -vf pad=${pad}:0:0:0:black -threads 2 -ab ${ABITRATE} \
-acodec ${audcodec} -async 1 -f mpegts -y - > "$2"
fi

now run 
chmod +x /usr/bin/ffmpegvideo

ffmpegyoutube

#!/bin/bash

# bars left and right
exec avconv -i "$1" -r 25 -b 4000k -maxrate 4000k \
     -minrate 4000k -bufsize 1000k -vf pad=44:0:0:0:black -threads 2 \
     -ac 1 -ab 64k -ar 44100 -acodec mp2 -f dvd -y - > "$2"

now run 
chmod +x /usr/bin/ffmpegyoutube

vlcaudio


#!/bin/bash

INPUT="$1"

AUDIO_CHANNELS="2"
FORMAT="wav"

exec /usr/bin/cvlc "${INPUT}" :sout="#transcode{acodec=${AUDIO_CODEC},\
ab=${AUDIO_BITRATE},channels=${AUDIO_CHANNELS}}:\
standard{access=file,mux=${FORMAT},dst=${OUTPUT}}" vlc://quit

now run

chmod +x /usr/bin/vlcaudio


Configuration

Please place this in /etc/mediatomb/config.xml


<?xml version="1.0" encoding="UTF-8"?>
<config version="2" xmlns="http://mediatomb.cc/config/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mediatomb.cc/config/2 http://mediatomb.cc/config/2.xsd"><!--
     Read /usr/share/doc/mediatomb-common/README.gz section 6 for more
     information on creating and using config.xml configration files.
    -->
  <server>
    <ui enabled="yes" show-tooltips="yes">
      <accounts enabled="no" session-timeout="30">
        <account user="mediatomb" password="mediatomb"/>
      </accounts>
    </ui>
    <name>MediaTomb</name>
    <udn>uuid:1f63390d-6412-4c1d-a520-3a7af5119084</udn>
    <home>/var/lib/mediatomb</home>
    <webroot>/usr/share/mediatomb/web</webroot>
    <storage caching="yes">
      <sqlite3 enabled="yes">
        <database-file>mediatomb.db</database-file>
      </sqlite3>
      <mysql enabled="no">
        <host>localhost</host>
        <username>mediatomb</username>
        <database>mediatomb</database>
      </mysql>
    </storage>
    <protocolInfo extend="no"/><!-- For PS3 support change to "yes" --><!--
       Uncomment the lines below to get rid of jerky avi playback on the
       DSM320 or to enable subtitles support on the DSM units
    --><!--
    <custom-http-headers>
      <add header="X-User-Agent: redsonic"/>
    </custom-http-headers>
    <manufacturerURL>redsonic.com</manufacturerURL>
    <modelNumber>105</modelNumber>
    --><!-- Uncomment the line below if you have a Telegent TG100 --><!--
       <upnp-string-limit>101</upnp-string-limit>
    -->
    <extended-runtime-options>
      <ffmpegthumbnailer enabled="no">
        <thumbnail-size>128</thumbnail-size>
        <seek-percentage>5</seek-percentage>
        <filmstrip-overlay>yes</filmstrip-overlay>
        <workaround-bugs>no</workaround-bugs>
      </ffmpegthumbnailer>
      <mark-played-items enabled="no" suppress-cds-updates="yes">
        <string mode="prepend">*</string>
      </mark-played-items>
    </extended-runtime-options>
  </server>
  <import hidden-files="no">
    <scripting script-charset="UTF-8">
      <common-script>/usr/share/mediatomb/js/common.js</common-script>
      <playlist-script>/usr/share/mediatomb/js/playlists.js</playlist-script>
      <virtual-layout type="builtin">
        <import-script>/usr/share/mediatomb/js/import.js</import-script>
        <dvd-script>/usr/share/mediatomb/js/import-dvd.js</dvd-script>
      </virtual-layout>
    </scripting>
    <mappings>
      <extension-mimetype ignore-unknown="no">
<map from="ts" to="video/mpeg"/>
<map from="vob" to="video/mpeg"/>
<map from="wav" to="audio/wav"/>
<map from="mpg" to="video/mpeg"/>
<map from="aac" to="audio/x-aac"/>
  <map from="m4a" to="audio/mp4"/>
  <map from="mkv" to="video/x-matroska"/>
<map from="mov" to="video/x-quicktime"/>
        <map from="mp3" to="audio/mpeg"/>
        <map from="ogg" to="application/ogg"/>
        <map from="asf" to="video/x-ms-asf"/>
        <map from="asx" to="video/x-ms-asf"/>
        <map from="wma" to="audio/x-ms-wma"/>
        <map from="wax" to="audio/x-ms-wax"/>
        <map from="wmv" to="video/x-ms-wmv"/>
        <map from="wvx" to="video/x-ms-wvx"/>
        <map from="wm" to="video/x-ms-wm"/>
        <map from="wmx" to="video/x-ms-wmx"/>
        <map from="m3u" to="audio/x-mpegurl"/>
        <map from="pls" to="audio/x-scpls"/>
        <map from="flv" to="video/x-flv"/>
        <map from="mkv" to="video/x-matroska"/>
        <map from="mka" to="audio/x-matroska"/><!-- Uncomment the line below for PS3 divx support --><!-- <map from="avi" to="video/divx"/> --><!-- Uncomment the line below for D-Link DSM / ZyXEL DMA-1000 --><!-- <map from="avi" to="video/avi"/> -->
      </extension-mimetype>
      <mimetype-upnpclass>
        <map from="audio/*" to="object.item.audioItem.musicTrack"/>
        <map from="video/*" to="object.item.videoItem"/>
        <map from="image/*" to="object.item.imageItem"/>
        <map from="application/ogg" to="object.item.audioItem.musicTrack"/>
      </mimetype-upnpclass>
      <mimetype-contenttype>
        <treat mimetype="audio/mpeg" as="mp3"/>
        <treat mimetype="application/ogg" as="ogg"/>
        <treat mimetype="audio/x-flac" as="flac"/>
        <treat mimetype="image/jpeg" as="jpg"/>
        <treat mimetype="audio/x-mpegurl" as="playlist"/>
        <treat mimetype="audio/x-scpls" as="playlist"/>
        <treat mimetype="audio/x-wav" as="pcm"/>
        <treat mimetype="audio/L16" as="pcm"/>
        <treat mimetype="video/x-msvideo" as="avi"/>
        <treat mimetype="video/mp4" as="mp4"/>
        <treat mimetype="audio/mp4" as="mp4"/>
        <treat mimetype="application/x-iso9660" as="dvd"/>
        <treat mimetype="application/x-iso9660-image" as="dvd"/>
        <treat mimetype="video/x-matroska" as="mkv"/>
        <treat mimetype="audio/x-matroska" as="mka"/>
      </mimetype-contenttype>
    </mappings>
    <online-content><!-- Make sure to setup a transcoding profile for flv -->
      <YouTube enabled="no" refresh="28800" update-at-start="no" purge-after="604800" racy-content="exclude" format="flv" hd="no">
        <favorites user="mediatomb"/>
        <standardfeed feed="most_viewed" time-range="today"/>
        <playlists user="mediatomb"/>
        <uploads user="mediatomb"/>
        <standardfeed feed="recently_featured" time-range="today"/>
      </YouTube>
      <Weborama enabled="no" refresh="28800" update-at-start="no">
        <playlist name="Active" type="playlist" mood="active"/>
        <playlist name="Metal" type="playlist">
          <filter>
            <genres>metal</genres>
          </filter>
        </playlist>
      </Weborama>
      <AppleTrailers enabled="no" refresh="43200" update-at-start="no" resolution="640"/>
    </online-content>
  </import>
  <transcoding enabled="yes">
    <mimetype-profile-mappings>  
      <transcode mimetype="audio/mpeg" using="vlcwav"/>    
      <transcode mimetype="video/x-flv" using="vlcyoutube"/>
      <transcode mimetype="video/mp4" using="transvideo"/>
      <transcode mimetype="video/x-quicktime" using="transvideo"/>
      <transcode mimetype="application/ogg" using="vlcwav"/>
      <transcode mimetype="audio/x-ms-wma" using="vlcwav"/>
      <transcode mimetype="audio/x-ms-asf" using="vlcwav"/>
      <transcode mimetype="audio/x-flac" using="ffmpegwav"/>
      <transcode mimetype="audio/x-aac" using="vlcwav"/>
      <transcode mimetype="audio/mp4" using="vlcwav"/>
      <transcode mimetype="video/x-msvideo" using="transvideo"/>
      <transcode mimetype="video/x-ms-wmv" using="transvideo"/>
      <transcode mimetype="video/mpeg" using="mpeg2trans"/>
      <transcode mimetype="video/x-matroska" using="transvideo"/>
      <transcode mimetype="image/jpeg" using="rescalejpeg"/>
    </mimetype-profile-mappings>
    <profiles>
      <profile name="transvideo" enabled="yes" type="external">
        <mimetype>video/mpeg</mimetype>
        <accept-url>no</accept-url>
        <first-resource>yes</first-resource>
        <agent command="ffmpegvideo" arguments="%in %out 8300k 256k"/>
        <buffer size="57600000" chunk-size="128000" fill-size="10000000"/>
      </profile>
      <profile name="mpeg2trans" enabled="yes" type="external">
        <mimetype>video/mpeg</mimetype>
        <accept-url>no</accept-url>
        <first-resource>yes</first-resource>
        <hide-original-resource>yes</hide-original-resource>
        <agent command="ffmpegvideo" arguments="%in %out 8000k 256k"/>
        <buffer size="28800000" chunk-size="512000" fill-size="120000"/>
      </profile>
      <profile name="ffmpegwav" enabled="yes" type="external">
        <use-chunked-encoding>no</use-chunked-encoding>
        <mimetype>audio/wav</mimetype>
        <accept-url>no</accept-url>
        <first-resource>yes</first-resource>
        <agent command="ffmpegaudio" arguments="%in %out"/>
        <buffer size="1048576" chunk-size="131072" fill-size="262144"/>
      </profile>
      <profile name="vlcwav" enabled="yes" type="external">
<use-chunked-encoding>no</use-chunked-encoding> 
        <mimetype>audio/wav</mimetype>
        <accept-url>yes</accept-url>
        <first-resource>yes</first-resource>
        <agent command="vlc" arguments="-I dummy %in
           --sout #transcode{acodec=s16l,ab=192,channels=2}:standard{access=file,
                                                      mux=wav,dst=%out} vlc:quit"/>
        <buffer size="512000" chunk-size="32000" fill-size="64000"/>
      </profile>
      <profile name="rescalejpeg" enabled="yes" type="external">
        <mimetype>image/jpeg</mimetype>
        <accept-url>no</accept-url>
        <first-resource>yes</first-resource>
        <accept-ogg-theora>no</accept-ogg-theora>
        <agent command="convert" arguments="-size 1080x720 %in -auto-orient
                                           -resize 112.5%x100% +profile '*' %out"/>
        <buffer size="50000" chunk-size="100" fill-size="100"/>
      </profile>
      <profile name="ffyoutube" enabled="no" type="external">
        <mimetype>video/mpeg</mimetype>
        <accept-url>no</accept-url>
        <first-resource>yes</first-resource>
        <accept-ogg-theora>yes</accept-ogg-theora>
        <agent command="ffmpegyoutube" arguments="%in %out"/>
        <buffer size="14400000" chunk-size="256000" fill-size="80000"/>
      </profile>
      <profile name="vlcyoutube" enabled="yes" type="external">
        <mimetype>video/mpeg</mimetype>
        <accept-url>yes</accept-url>
        <first-resource>yes</first-resource>
        <accept-ogg-theora>yes</accept-ogg-theora>
        <agent command="vlc" arguments="-I dummy %in
           --sout #transcode{vcodec=mp2v,vb=4096,canvas-width=448,canvas-height=252,
           acodec=mpga,ab=64,samplerate=44100,channels=1}:standard{access=file,
                                                       mux=ts,dst=%out} vlc:quit"/> 
        <buffer size="14400000" chunk-size="256000" fill-size="80000"/>
      </profile>
    </profiles>
  </transcoding>
</config>

Next check that the mediatomb service is not active by running

   service mediatomb stop  

If you ran "sudo bash" at the beginning please type in 'exit' to exit from the root shell.

now run 

  mediatomb 

you should have an output similar to this



cpyarger@friday:~$ mediatomb 
MediaTomb UPnP Server version 0.12.1 - http://mediatomb.cc/
===============================================================================
Copyright 2005-2010 Gena Batsyan, Sergey Bostandzhyan, Leonhard Wimmer.
MediaTomb is free software, covered by the GNU General Public License version 2
2012-11-16 03:13:49    INFO: Loading configuration from: /home/cpyarger/.mediatomb/config.xml
2012-11-16 03:13:49    INFO: Checking configuration...
2012-11-16 03:13:49    INFO: Setting filesystem import charset to UTF-8
2012-11-16 03:13:49    INFO: Setting metadata import charset to UTF-8
2012-11-16 03:13:49    INFO: Setting playlist charset to UTF-8
WARNING: gnome-keyring:: couldn't connect to: /run/user/cpyarger/keyring-umWyG6/pkcs11: No such file or directory
2012-11-16 03:13:49 WARNING: You enabled the YouTube feature, which allows you
                             to watch YouTube videos on your UPnP device!
                             Please check http://www.youtube.com/t/terms
                             By using this feature you may be violating YouTube
                             service terms and conditions!
2012-11-16 03:13:49    INFO: Configuration check succeeded.
2012-11-16 03:13:49    INFO: Initialized port: 49152
2012-11-16 03:13:49    INFO: Server bound to: 192.168.254.46
2012-11-16 03:13:50    INFO: MediaTomb Web UI can be reached by following this link:
2012-11-16 03:13:50    INFO: http://192.168.254.46:49152/

You can now navagate to the Link provided on the last line to add files and folders to the MediaTomb and set up folder syncing.


This will look similar to this:


How to stream videos from Ubuntu to DirecTV MediaShare How to stream videos from Ubuntu to DirecTV MediaShare Reviewed by Chris Yarger on 03:23 Rating: 5

5 comments:

  1. Thank YOU SOOOOOO MUCH!

    ReplyDelete
  2. Is the a way to do this on a PC? I don't have Linux experience.

    ReplyDelete
  3. Is there a way to do this with a PC?

    ReplyDelete
  4. Yes, Take a look into any upnp transcoding media server, I believe MediaTomb has a windows port.

    ReplyDelete

© 2012 cpyarger.com License: (cc) BY-NC-SA. Template images by enot-poloskun. Powered by Blogger.