lunedì 22 aprile 2013

Sopcast stream via Mediatomb

I'd like to watch a Sopcast stream on my TV, so I'm trying to figure out a way to do it. Internet is great, the solution is very easy. I will use Mediatomb to broadcast the stream to my TV. Mediatomb is running on Ubuntu 12.10 32 bit.

First of all, let's install Sopcast:

 sudo add-apt-repository ppa:ferramroberto/sopcast

 sudo apt-get update

 sudo apt-get install sopcast-player

Let's launch Sopcast from the dash home. If Sopcast returns an error like this:

 sopcast-player : Depends: sp-auth (>= 3.0.1) but it is not installable

We have to search for sp-auth_3.2.6.deb and install it.



Now we need to configure Sopcast to use a specified outgoing port for the stream. In this way, we'll define a static URL to redirect Mediatomb to. Select Edit -> Preferences and check Static ports, select two different port for incoming and outbound port, for example 8901 and 8902 and press apply.





Now it's time to configure Mediatomb. Great solution here. Let's edit /etc/mediatomb/config.xml: we need to add this line

 <transcode mimetype="video/sopcast-x-ms-wmv" using="video-generic"/>

to the <mimetype-profile-mappings> section and this

<profile name="video-generic" enabled="yes" type="external">
         <mimetype>video/mpeg</mimetype>
         <accept-url>yes</accept-url>
         <first-resource>yes</first-resource>
         <hide-original-resource>yes</hide-original-resource>
         <accept-ogg-theora>yes</accept-ogg-theora>
         <agent command="/usr/local/bin/mediatomb-video-generic" arguments="%in %out"/>
         <buffer size="24000000" chunk-size="1024000" fill-size="120000"/>
</profile>

to the transcoding profiles. Let's save the file.

As you can see, the profile above will use the script /usr/local/bin/mediatomb-video-generic to broadcast the stream. You can find the script here. Place it into /usr/local/bin and change its permissions with sudo chmod +x.

Let's have a closer look:

#!/bin/bash
INPUT="$1"
OUTPUT="$2"
VIDEO_CODEC="mpeg2video"
VIDEO_BITRATE="4096k"
AUDIO_CODEC="mp2"
AUDIO_BITRATE="192k"
AUDIO_SAMPLERATE="48000"
AUDIO_CHANNELS="2"
FORMAT="dvd"

exec /usr/bin/ffmpeg -threads 4 -i "${INPUT}" -vcodec ${VIDEO_CODEC} -b ${VIDEO_BITRATE} \
-acodec ${AUDIO_CODEC} -ab ${AUDIO_BITRATE} -ar ${AUDIO_SAMPLERATE} -ac ${AUDIO_CHANNELS} \
-f ${FORMAT} - > "${OUTPUT}" 2>/dev/null

The script will use ffmpeg to transcode the stream in a well known format that a DLNA player can handle.

"Go to the mediatomb web ui, click on videos, click the plus sign to add new item, fill it out like this..."

External Link (URL) 
 Title: Sopcast 
 URL: http://127.0.0.1:8902 
 Protocol: http-get 
 Class: object.item.videoItem
 Description: Sopcast 
 Mimetype: video/sopcast-x-ms-wmv

Done! Restart Mediatomb with this command:

sudo service mediatomb restart

turn on your DLNA player and select the DLNA Server icon. Select the item Sopcast and enjoy the stream.

Best regards!