News:

Latest versions:
Server plugin: 0.5.1
MVP dongle: 0.5.2
Raspberry Pi client: 0.5.2
Windows client: 0.5.2-1

Main Menu

Howto get ATSC and IPTV working on Vomp.

Started by rdoac, October 10, 2009, 01:11:41

Previous topic - Next topic

rdoac

I now have my US ATSC SD channels working.  It's quite convoluted but I will do my best to explain.  This procedure will also allow you to watch Internet Streams..

Theory
---------

ATSC streams only broadcast ac-3 audio.  Vomp cannot handle these streams so will not display the channels.  However, a VDR systems with the IPTV and Streamdev plugins can re-encode the channel using ffmpeg.

Requirements:
-------------------
VDR / Vompserver
iptv plugin (with quick patch if you want more than one "device".)
ATSC patch and plugin.
ATSC source. (and / or some URL's of internet streams).
ffmpeg installed on your system. 
Enough processor to re encode the stream "on the fly".  I have a Quad Core Phenom, so am not sure how much you need.

Problems
------------
Normally, with IPTV and VDR, when you stop watching a channel, SIGTERM is sent to the script which IPTV called.  This can be trapped in the script and ffmpeg can be killed.  However, on my setup, when using with Vompserver, the script ignores SIGTERM, so the IPTV patch sends SIGKILL, which kills the script, but not ffmpeg. If you watch another channel, the first is still being reencoded, so you will get a mash of both streams together which is not pretty.  I have hacked the script I call to run a little process in the background.  Every second it checks to see if the original script is still being run, if not it kills off ffmpeg and mencoder.

Howto
---------
Get ATSC working, and install the IPTV plugin.  Instructions for these can be found elsewhere.  IPTV requires the  pluginparam patch.

To use more than one IPTV device at a time, add  --plugin=iptv --devices=7  to VDR's command line, and the following patch to IPTV's source..  (thanks Rolf Ahrenburg for the tip).


--- a/device.c
+++ b/device.c
@@ -248,7 +248,7 @@ bool cIptvDevice::ProvidesTransponder(const cChannel *Channel) const
bool cIptvDevice::ProvidesChannel(const cChannel *Channel, int Priority, bool *NeedsDetachReceivers) const
{
   bool result = false;
-  bool needsDetachReceivers = false;
+  bool needsDetachReceivers = true;

   debug("cIptvDevice::ProvidesChannel(%d)\n", deviceIndex);
   if (ProvidesTransponder(Channel))



My Channels.conf ATSC channels had this type of entry for an ATSC channel.

WREX;(null):525000:M256:T:0:2240:0;2241,2242:0:0:1:0:0:0
WTVO;(null):525000:M256:T:0:2304:0;2305,2306:0:0:4:0:0:0

A reencoded channel has a channels.conf entry of:

WREX-SD-Remux;FFmpeg:290:IPTV|S0P0|EXT|streamdev.sh|109:P:0:256:257:0:0:109:1:1:0
WTVO-SD-Remux;FFmpeg:300:IPTV|S0P0|EXT|streamdev.sh|110:P:0:256:257:0:0:110:1:1:0

Where 109 and 110 are the channel positions of WREX and WTVO in my setup.

In /etc/vdr/plugins/iptv  I have streamdev.sh

/etc/vdr/plugins/iptv/streamdev.sh
#!/bin/sh
#
# iptvstream.sh can be used by the VDR iptv plugin to transcode external
# sources
#
# (C) 2007 Rolf Ahrenberg, Antti Seppälä
#
# iptvstream.sh is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this package; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA.

if [ $# -ne 2 ]; then
    logger "$0: error: Invalid parameter count '$#' $*"
    exit 1
fi

#killall -9 ffmpeg.streamdev

echo >/tmp/iptvstream

# Channels.conf parameter
PARAMETER=${1}

# Iptv plugin listens this port
PORT=${2}

# Default settings for stream transcoding
LOG=/tmp/iptvstream
VCODEC=mpeg2video
VBITRATE=4000
ACODEC=mp2
ABITRATE=192
fr=29
resx=720
resy=480
fifo=/tmp/streamdev${PARAMETER}.fifo

{
echo Script started $1 $2 >>/tmp/iptvstream
# There is a way to specify multiple URLs in the same script. The selection is
# then controlled by the extra parameter passed by IPTV plugin to the script

echo "Getting new URL">>$LOG
URL="http://oac:3000/TS/${PARAMETER}+1"
echo $PLX $URL >>$LOG

if [ -z "${URL}" ]; then
    logger "$0: error: URL not defined!"
    exit 1
fi

if [ -z "${URL}" ]; then
    logger "$0: error: URL not defined!"
    exit 1
fi
MYPID=$$
echo "Streamdev.sh PID is $MYPID" >>$LOG
# Create transcoding options
echo "Streamdev Plugin $PARAMETER $URL" >>$LOG
# Capture VLC pid for further management in IPTV plugin
mkfifo $fifo
mplayer $mplayeropts -nocache "$URL" -dumpstream -dumpfile $fifo >>${LOG} &
MPID=${!}
     

ffmpeg.streamdev -v 1 \
         -i $fifo -debug 0 \
         -f mpegts -r $fr -vcodec copy -vsync $fr \
          -acodec ${ACODEC} -ac 2 -ab ${ABITRATE}k -ar 48000 \
          "udp://127.0.0.1:${PORT}?pkt_size=16356" &


PID=${!}
echo "pid of ffmpeg.streamdev $PID" >> $LOG
echo $PID >/tmp/iptv-$MYPID
echo $MPID >>/tmp/iptv-$MYPID

/etc/vdr/plugins/iptv/procchk ${MYPID} &

trap 'echo Trap activated; kill -9 ${PID}; kill -9 ${MPID} 2>> $LOG ' KILL INT EXIT QUIT TERM

# Waiting for the given PID to terminate
wait ${PID}
kill -9 $PID
kill -9 ${MPID}
} >> ${LOG} 2>&1

and
/etc/vdr/plugins/iptv/procchk
#!/bin/bash
PIDOFSCRIPT=$1
echo $PIDOFSCRIPT
while ps -p $PIDOFSCRIPT >/dev/null
do
sleep 1
done
echo Killing ffmpeg
cat /tmp/iptv-$PIDOFSCRIPT | xargs kill -9
rm /tmp/iptv-$PIDOFSCRIPT


NB, ffmpeg.streamdev is symlinked to ffmpeg.  I have done this for debugging purposes so I can find out what type of script called ffmpeg.

This will simply reencode the ATSC channel with MP3 audio.

However, some other things you can do are:

RTL 102.5;IPTV:590:IPTV|S0P0|EXT|brit.sh|59:P:0:256:257:0:0:59:0:0:0

/etc/vdr/plugins/iptv/brit.sh
#!/bin/sh
#
# iptvstream.sh can be used by the VDR iptv plugin to transcode external
# sources
#
# (C) 2007 Rolf Ahrenberg, Antti Seppälä
#
# iptvstream.sh is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This package is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this package; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA.

if [ $# -ne 2 ]; then
    logger "$0: error: Invalid parameter count '$#' $*"
    exit 1
fi

#killall -9 ffmpeg.brit

echo >/tmp/iptvstream

# Channels.conf parameter
PARAMETER=${1}

# Iptv plugin listens this port
PORT=${2}

# Default settings for stream transcoding
LOG=/tmp/iptvstream
VCODEC=mpeg2video
VBITRATE=2000
ACODEC=mp2
ABITRATE=320
fr=29
resx=720
resy=480
fifo=/tmp/brit${PARAMETER}.fifo
maps=
mplayeropts=
aspect=16:9
{
echo Script started $1 $2 >>/tmp/iptvstream
# There is a way to specify multiple URLs in the same script. The selection is
# then controlled by the extra parameter passed by IPTV plugin to the script

case ${PARAMETER} in

    64)
#SportItalia
PLX="mms://mms.cdn-tiscali.com/sportitalia"
aspect=4:3
;;
    59)
        PLX="mms://151.1.245.36/rtl102.5vs/"
maps=" -map 0:2 -map 0:1"
        ;;
    *)
        URL=""  # Default URL
        ;;
esac

if [ -z "${PLX}" ]; then
    logger "$0: error: URL not defined!"
    exit 1
fi


echo "Getting new URL">>$LOG

URL=$PLX
echo $URL >>$LOG


if [ -z "${URL}" ]; then
    logger "$0: error: URL not defined!"
    exit 1
fi

# Create transcoding options
echo "Brit Plugin $PARAMETER $URL" >>$LOG
# Capture ffmpeg pid for further management in IPTV plugin

ERR=1
while [ $ERR ]
do
ERR=
mkfifo $fifo
mplayer $mplayeropts "$URL" -dumpstream -dumpfile $fifo >>${LOG} &
MPID=${!}
ffmpeg.brit -v 1 \
         -i $fifo -debug 0\
  -aspect $aspect \
          -f mpegts -r $fr -vcodec ${VCODEC} -b ${VBITRATE}k -er 3 -s ${resx}x${resy} -vsync $fr\
          $maps -acodec ${ACODEC} -ac 2 -ab ${ABITRATE}k -ar 48000 \
          "udp://127.0.0.1:${PORT}?pkt_size=16356" &


PID=${!}
echo "pid of ffmpeg.brit $PID" >>${LOG}
MYPID=$$

echo $PID >/tmp/iptv-$MYPID
echo $MPID >>/tmp/iptv-$MYPID
/etc/vdr/plugins/iptv/procchk ${MYPID} &

trap 'echo Trap activated; kill -9 ${PID}; kill -9 ${MPID} 2>> $LOG ' INT EXIT QUIT TERM

# Waiting for the given PID to terminate
wait ${PID}

ffmpegerr=`tail /tmp/iptvstream | grep "Cannot get resampling context" | awk '{printf $1}'`

if [ $ffmpegerr ];then
ERR=1
echo "$ffmpegerr Restart" >>${LOG}
else
ERR=
echo "$ffmpegerr Stop" >>${LOG}
fi
done
} >> ${LOG} 2>&1
kill -9 $MPID
kill -9 $PID

If you want to watch an asx stream you need to add:

         mplayeropts="-playlist"

Under the PLX line in the Case structure.

These settings are US based (NTSC).  PAL ones would probably change resy to 576 and fr to 25.

Any questions, just ask.

A good source of urls for IPTV is to install XBMV and install the navi-xstreme script.  Then have a look through ~/.xbmc/scripts/Navi-X/cache/

If you're good at scripting you can process some urls before asking mplayer to get them.

Mplayer is better at getting streams than wget or curl.  Hence the dumpstream, fifo's etc..

One problem I had was udp didn't have enough buffer space and I got lots of dropped frames when watch streamdeved channels.

I ended up adding:

/etc/sysctl.conf
#Increase buffersize for udp
net.core.rmem_default=8388608
net.core.rmem_max=33554432


Which solved the problem.

Rob