How to stream videos from Ubuntu to DirecTV MediaShare

Geek, Lighting Tech, Maker

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.



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



# 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


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


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

echo $aspect

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

now run 

chmod +x /usr/bin/ffmpegvideo



# 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





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

now run

chmod +x /usr/bin/vlcaudio


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

<?xml version="1.0" encoding="UTF-8"?>

<config version="2" xmlns="" xmlns:xsi="" xsi:schemaLocation=""><!--

     Read /usr/share/doc/mediatomb-common/README.gz section 6 for more

     information on creating and using config.xml configration files.



    <ui enabled="yes" show-tooltips="yes">

      <accounts enabled="no" session-timeout="30">

        <account user="mediatomb" password="mediatomb"/>







    <storage caching="yes">

      <sqlite3 enabled="yes">



      <mysql enabled="no">






    <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



      <add header="X-User-Agent: redsonic"/>




    --><!-- Uncomment the line below if you have a Telegent TG100 --><!--




      <ffmpegthumbnailer enabled="no">






      <mark-played-items enabled="no" suppress-cds-updates="yes">

        <string mode="prepend">*</string>




  <import hidden-files="no">

    <scripting script-charset="UTF-8">



      <virtual-layout type="builtin">






      <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"/> -->



        <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"/>



        <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"/>



    <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"/>


      <Weborama enabled="no" refresh="28800" update-at-start="no">

        <playlist name="Active" type="playlist" mood="active"/>

        <playlist name="Metal" type="playlist">






      <AppleTrailers enabled="no" refresh="43200" update-at-start="no" resolution="640"/>



  <transcoding enabled="yes">


      <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"/>



      <profile name="transvideo" enabled="yes" type="external">




        <agent command="ffmpegvideo" arguments="%in %out 8300k 256k"/>

        <buffer size="57600000" chunk-size="128000" fill-size="10000000"/>


      <profile name="mpeg2trans" enabled="yes" type="external">





        <agent command="ffmpegvideo" arguments="%in %out 8000k 256k"/>

        <buffer size="28800000" chunk-size="512000" fill-size="120000"/>


      <profile name="ffmpegwav" enabled="yes" type="external">





        <agent command="ffmpegaudio" arguments="%in %out"/>

        <buffer size="1048576" chunk-size="131072" fill-size="262144"/>


      <profile name="vlcwav" enabled="yes" type="external">





        <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 name="rescalejpeg" enabled="yes" type="external">





        <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 name="ffyoutube" enabled="no" type="external">





        <agent command="ffmpegyoutube" arguments="%in %out"/>

        <buffer size="14400000" chunk-size="256000" fill-size="80000"/>


      <profile name="vlcyoutube" enabled="yes" type="external">





        <agent command="vlc" arguments="-I dummy %in

           --sout #transcode{vcodec=mp2v,vb=4096,canvas-width=448,canvas-height=252,


                                                       mux=ts,dst=%out} vlc:quit"/> 

        <buffer size="14400000" chunk-size="256000" fill-size="80000"/>





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 

you should have an output similar to this

cpyarger@friday:~$ mediatomb 

MediaTomb UPnP Server version 0.12.1 -


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

                             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:

2012-11-16 03:13:50    INFO: MediaTomb Web UI can be reached by following this link:

2012-11-16 03:13:50    INFO:

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:

Comments: 5

  1. Anonymous says:


  2. PictureMan says:

    Is there a way to do this with a PC?

  3. PictureMan says:

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

  4. Chris Yarger says:

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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.