gkreidl
Posts: 5306
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Real Time Transcoding of DVB TV Streams

Wed Oct 21, 2015 4:35 pm

This has been treated here in different threads already (more problems than success usually). I've successfully implemented real time transcoding of TV (mpeg TS over http) streams for SD mpeg2 streams in my SAT-TV-Server application (German version only right now). I'm using (a slightly modified version of) Sebastian Droege's http-launch with matching gstreamer1-0 toolchains.

Meanwhile I can transcode all types of (European) TV streams. Here's a snapshot of a 720p50 video stream, transcoded to 768x432p50 with a video bitrate of 640 KBit (and audio also transcoded to 32 KBit).

Image

The next posting gives you access to my transcoder package V. 3.0
Last edited by gkreidl on Thu Mar 02, 2017 10:18 am, edited 2 times in total.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

gkreidl
Posts: 5306
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Transcoding software

Thu Oct 29, 2015 10:52 am

Important note: This software currently only works on Raspbian Jessie!

Update March, 2nd, 2017: New version 3.0
The main executable is now a binary compiled with nuitka and has been renamed to rtranscode, to avoid conflicts with the Debian transcode package.


I've created a small transcoder package for real time transcoding of DVB TS http streams (support for udp streams has also been added, but is considered experimental) to lower bitrate and image size mkv http streams that can be served with small upload bandwidth (across the internet, for example). It can transcode MPEG2 SD streames (you need the MPEG codec license!) and H264 streams of all usual TV resolutions (576i, 720p50, 1080i). You can also use it to record transcoded streams. Audio transcoding is also supported, but you can optionally use one of the original audio streams.

WARNING: This is experimental software. I've only tested it with mumudvb unicast http streams myself, but other people have successfully used it with other programs (VDR, for example). It might also work with HDHOMERUN or similar hardware, using the new (experimental) udp support. I couldn't get it to work with tvheadend and gave up after trying it for four days. People with more experience using tvheadend might get it to work (and should report it here), but the official startement right now is: tvheadend is not supported.

Edit: It seems, that kazuko.nakamura got it to work with tvheadend. See viewtopic.php?f=38&t=123876&start=150#p1225612 and the following posts.

The default configuration contains settings for typical European TV formats (576i25, 720p50, 1080i25). Other formats can be added (the manual contains an example).

The transcoder uses the GPU of the Raspberry Pi and gstreamer-1.0 modules and requires a Rasbpian Jessie installation. It installs the following components:

1) a slightly extended version of Sebastian Droege's http-launch
2) a binary "rtranscode" which really simplifies working with http-launch (written in Python and compiled with nuitka)
3) a script "bg_rtranscode.sh" to start rtranscode in quiet mode, suitable for use from other applications.
4) a configuration file and an empty "channels.dat" in /usr/local/share/rtranscode

If you have my kweb suite (Minimal Kiosk Browser, omxplayerGUI) installed, an additional binary "create_kpages" will be installed, which can create a local web interface (HTML files) from a channel database.

Installation:

Code: Select all

wget http://steinerdatenbank.de/software/transcoder3.tar.gz
tar -xzf transcoder3.tar.gz
cd transcoder3
sudo ./install
Inside the transcoder3 directory you will find a large README file and a comprehensive manual in PDF format. The manual is also available online.

The sources directory includes the Python sources of rtranscode and create_kpages and the modified C source of http-launch.

The examples directory contains examples of channel database files. They cannot be used by anyone, but show, how a database file might look like.

Note: If you have used an older version of my transcoder package and have built a channel database you can continue to use it. Just copy it to /usr/local/share/rtranscode
Attachments
rtckewinterface.jpg
kweb interface of the transcoder package
rtckewinterface.jpg (62.03 KiB) Viewed 3846 times
Last edited by gkreidl on Fri Nov 10, 2017 9:37 am, edited 8 times in total.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

gkreidl
Posts: 5306
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Usage of the Transcoder Package

Thu Oct 29, 2015 10:54 am

Originally this post contained the whole README file of the transcoder package, but in version 3 the README file is too long to be published here.

After installing rtranscode, you can run
rtranscode -h (or --help)
to get a list of possible usages and command line options:

Usage: rtranscode [options] uri videomode audiomode audiopid'
uri = URL of your local TV http server (MPEG TS only)
videomode must be one of the following:
sd1 for MPEG2 SD video
sd2 for H264 SD video
hd1 for 720p50 HD video
hd2 for 1080i HD video
audiomode must be either 'mpeg' or 'ac3'
audiopid must match your TS stream (decimal or hex starting with 0x)

Alternate methods:
rtranscode [options] -f=file_path
read data from file
rtranscode [options] -n=channel_name
select a channel by name from channels file
rtranscode [options] -g=URI
analyze stream URI and return name and arguments
rtranscode [options] -t=URI
analyze stream URI and start transcoding, if possible
rtranscode [options] -i=infile -o=outfile
analyse URIs from infile and append to channels file outfile (created, if missing)
rtranscode [options]
If called without further argments, transcode will try to read
from a channels file and offer a simple selection menu.

Options:
-c=config file
(default = /usr/local/share/rtranscode/config.py)
-d=channels file
(default = /usr/local/share/rtranscode/channels.dat)
-a=Audio bitrate number (0..12), default = 2 (64K)
-v=video bitrate number (0..22), default = 1 (medium)
-s=SD video size number (0..6), default = 3 (360x288)
-h=HD video size number (0..5), default = 2 (768x432)
-p=path output path for stream URL, must start with a "/" and end with ".mkv", default = "/xyz.mkv"
-u=audio_output_format must be either "aac", "ac3" or "both", default = both
-r=delay, start the original stream before running the transcoder, (0..10), default = 0
-l=record_path, full path to recording directory, default = current directory
-q run both rtranscode and http-launch in silent mode, prevents menu mode from working!

For more details, check the README or the PDF manual, which is also available online.
Last edited by gkreidl on Thu Mar 02, 2017 10:41 am, edited 4 times in total.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

mishu77
Posts: 1
Joined: Thu Oct 29, 2015 2:37 pm

Re: Real Time Transcoding of DVB TV Streams

Thu Oct 29, 2015 2:41 pm

Hi,

Do you think is possible to add flvmux and rtmp output to http-launch?

Thank you.

gkreidl
Posts: 5306
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Real Time Transcoding of DVB TV Streams

Thu Oct 29, 2015 3:25 pm

mishu77 wrote:Hi,

Do you think is possible to add flvmux and rtmp output to http-launch?

Thank you.

rtmp: no, not without rewriting it completely.

A gstreamer tool chain which replaces matroskamux by flvmux might work, but the problem is the audio transcoding: flvmux does not support aac and there is no mpeg audio encoder in gstreamer1.0.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

c-o-m-m-a-n-d-e-r
Posts: 3
Joined: Tue Apr 14, 2015 7:22 am
Location: Germany

Re: Real Time Transcoding of DVB TV Streams

Sun Nov 01, 2015 9:59 am

wow cool, i think its exactly what i was looking for ... i will test it with tvheadend as server backend

Thanks!

gkreidl
Posts: 5306
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Real Time Transcoding of DVB TV Streams

Sun Nov 01, 2015 10:49 am

c-o-m-m-a-n-d-e-r wrote:wow cool, i think its exactly what i was looking for ... i will test it with tvheadend as server backend

Thanks!
tvheadend uses it's own streaming protocol. You must make sure that it streams pure TS streams.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

c-o-m-m-a-n-d-e-r
Posts: 3
Joined: Tue Apr 14, 2015 7:22 am
Location: Germany

Re: Real Time Transcoding of DVB TV Streams

Sun Nov 01, 2015 10:57 am

yep, i know ... i use htsp in combination with Kodi ...
For Streaming / Transcoding i use http mpeg-ts output (pass) ...

Thanks / Danke 8-)

c-o-m-m-a-n-d-e-r
Posts: 3
Joined: Tue Apr 14, 2015 7:22 am
Location: Germany

Re: Real Time Transcoding of DVB TV Streams

Mon Nov 02, 2015 8:52 pm

Just a short Information : After some mailing with gkreidl i found the trick.

HD transcoding needs a Rpi2 ... Rpi1 isn't working ...

I test with "Das Erste HD" with transcoding to 1280x720, 1,5 MBit/s and 128 Kbit/s Audio ...
Rpi2 is round about at 85% (with gpu_freq @ 500)

Big Thanks!

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: Transcoding software

Mon Nov 02, 2015 9:18 pm

gkreidl wrote:I've created a small transcoder package for real time transcoding of
I'd be interested in knowing if anyone has transcoding or viewing of full HD from the antenna of North American digital TV working. Specifically I'm talking about the HDHomerun. I've heard some folks make some claims about doing this off cable but the antenna is supposed to be more demanding.

Bastinazo
Posts: 4
Joined: Tue Nov 10, 2015 11:07 am

Re: Real Time Transcoding of DVB TV Streams

Tue Dec 01, 2015 7:17 pm

I have installed your transcoder package tool manually cause I use raspbian wheezy for transcoding. However "http-launch" shows me this error


"** (http-launch:3193): WARNING **: Cannot autolaunch D-Bus without X11 $DISPLAY"

Is there any other option for launching transcoding.py in raspbian wheezy ?


Thxs in advance !!

gkreidl
Posts: 5306
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Real Time Transcoding of DVB TV Streams

Wed Dec 02, 2015 7:10 am

Bastinazo wrote:I have installed your transcoder package tool manually cause I use raspbian wheezy for transcoding. However "http-launch" shows me this error


"** (http-launch:3193): WARNING **: Cannot autolaunch D-Bus without X11 $DISPLAY"

Is there any other option for launching transcoding.py in raspbian wheezy ?


Thxs in advance !!
The message comes from gstreamer. I cannot tell you if will run completely headless, although I have often used it from an SSH terminal (but X-Server was running on the Pi.)
I've done transcoding on Wheezy, but H264 sources did not work because of a bug in gstreamer1.2 which has been fixed in Jessie (version 1.4 now). I could transcode MPEG streams (you need the mpeg codecs).
The bug in the gstreamer-omx Module of Jessie (memory leak) has been fixed recently.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

henkedk
Posts: 1
Joined: Tue Dec 08, 2015 6:52 pm

Re: Real Time Transcoding of DVB TV Streams

Tue Dec 08, 2015 6:57 pm

Seems to be some nice stuff, but how would one do it if the purpose is to be to actually get the stream back to a PVR client remotely, which is also able to change channels, see EPG etc just as if it connected directly to TvHeadend?

What I'm trying to do is using a RPI2 as a TV-server (USB DVB-C) (jessie without any GUI) and use a OpenElec/Kodi remote to get access to the channels I got at home. Whilst SD channels work fine, HD don't, they stutter. I tried compiling TvHeadend with transcoding and adding the MPEG2 license, but the RPI2 doesn't seem to have the power to user the transcoding (no matter which version I choose), since all I get is stutter on both HD and SD.

1kane
Posts: 9
Joined: Fri Feb 26, 2016 8:34 am

Re: Real Time Transcoding of DVB TV Streams

Tue Mar 01, 2016 11:30 am

Hay gkreidl,
im using succesfully ur transcoding script from
but on interlaced channels i get really ugly pictures that look like bad downscaled interlace. bc that final interlace video isnt "real interlace" (like odd lines are double the size) im not able to deinterlace it at the reciving device.

i saw that deinterlacing is possible with gstramer, but im not able to get it working (tried to place the "! deinterlace" pipe at every known position in the config file). do you know how to modify the settings to get the deinterlace working on the PI?
that would be great :)

gkreidl
Posts: 5306
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Real Time Transcoding of DVB TV Streams

Tue Mar 01, 2016 12:02 pm

1kane wrote:Hay gkreidl,
im using succesfully ur transcoding script from
but on interlaced channels i get really ugly pictures that look like bad downscaled interlace. bc that final interlace video isnt "real interlace" (like odd lines are double the size) im not able to deinterlace it at the reciving device.

i saw that deinterlacing is possible with gstramer, but im not able to get it working (tried to place the "! deinterlace" pipe at every known position in the config file). do you know how to modify the settings to get the deinterlace working on the PI?
that would be great :)
Deinterlacing is really a problem I have not solved yet. If the image size is larger than half of the original size it's getting ugly. Software deinterlacing with gstreamer didn't work either (and I'm not sure if that wouldn't be too slow). Unfortunately the omx module doesn't support any interlace function on the GPU.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

1kane
Posts: 9
Joined: Fri Feb 26, 2016 8:34 am

Re: Real Time Transcoding of DVB TV Streams

Tue Mar 01, 2016 12:42 pm

thanks for your fast reply.
thats very sad, because the rest is working very well.
so my resolution will be to set the size of interlaced material at 288p, than it looks proper. and if the stream is progessiv than i gonna set higher resolution.

and thank you again for your transcoding script! its the onliest raspberry hardwareVideo transcoder (that streams to network) i got working!

gkreidl
Posts: 5306
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Real Time Transcoding of DVB TV Streams

Tue Mar 01, 2016 1:14 pm

1kane wrote:thanks for your fast reply.
thats very sad, because the rest is working very well.
so my resolution will be to set the size of interlaced material at 288p, than it looks proper. and if the stream is progessiv than i gonna set higher resolution.

and thank you again for your transcoding script! its the onliest raspberry hardwareVideo transcoder (that streams to network) i got working!
For SD channels I use 360x288, for 1080i channels 768*432 (or 910*512). 720p50 channels can be send with any resolution.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

kylemassey86
Posts: 1
Joined: Thu Mar 03, 2016 1:10 am
Location: USA

Re: Real Time Transcoding of DVB TV Streams

Thu Mar 03, 2016 1:11 am

This may seem stupid, but I've gotten all the way through configuring and I'm getting the "Listening on http://... message, but how do I actually watch the transcoded stream?? :oops:

gkreidl
Posts: 5306
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Real Time Transcoding of DVB TV Streams

Thu Mar 03, 2016 4:46 am

kylemassey86 wrote:This may seem stupid, but I've gotten all the way through configuring and I'm getting the "Listening on http://... message, but how do I actually watch the transcoded stream?? :oops:
On the Pi:
omxplayer http....
on other computers, use VLC and enter the network stream address
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

spyer
Posts: 6
Joined: Tue Apr 05, 2016 2:17 pm

Re: Real Time Transcoding of DVB TV Streams

Wed Apr 06, 2016 10:13 am

Hello gkreidl,

what does that mean if I try to run transcode.py?

Code: Select all

pi@raspberrypi:~ $ transcode.py
dbox (0)
Enter a channel number or 'q' to quit: 0
http-launch: error while loading shared libraries: libgstreamer-1.0.so.0: cannot open shared object file: No such file or directory
my steps:

Code: Select all

wget http://steinerdatenbank.de/software/transcoder.tar.gz
tar -xzf transcoder.tar.gz
cd transcoder
sudo ./install
sudo ./install_omx
edit/add:

Code: Select all

sudo nano /usr/local/share/transcode/channels.dat
--->>add dbox=http://spyer:xxxxx@192.168.1.6:9981/stream/service/3cf5c667af85ef993947b41ce897758b? sd1 mpeg 2652
-->>source: TVHeadend from dbox2
profil: pass, Mpeg-TS Pass.trough

VLC-tvheadend sad under codec: 
Stream 0
Typ: Video
Originale ID: 2651
Codec: MPEG-1/2 Video (mpgv)
Auflösung: 720x576
Bildschirmauflösung: 720x576
Bildwiederholrate: 25
Decodiertes Format: Planar 4:2:0 YUV

Stream 1
Typ: Audio
Originale ID: 2652 <---[b]AudioPID???[/b]
Codec: MPEG Audio layer 1/2 (mpga)
Sprache: Deutsch
Kanäle: Stereo
Abtastrate: 48000 Hz
Bitrate: 192 kB/s
what I am doing wrong or what is missing?

Best wishes
spyer

PS: I ordered the mpeg-codec activator and wait for the activation to install this in confog.txt. Is this the reason for "No such file or directory" ?

gkreidl
Posts: 5306
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Real Time Transcoding of DVB TV Streams

Wed Apr 06, 2016 10:47 am

1) For MPEG transcoding you need the MPEG codec license. (used by the omx decoder)
2) Check if all gstreamer-1.0 libtraries are isntalled. My preferred way is using synaptic and searching for gstreamer.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

spyer
Posts: 6
Joined: Tue Apr 05, 2016 2:17 pm

Re: Real Time Transcoding of DVB TV Streams

Thu Apr 07, 2016 7:37 am

Good Morning,

do you have any idea how I can install it without synaptic?

edit: i try know:
sudo apt-get install gstreamer1.0*

gkreidl
Posts: 5306
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Real Time Transcoding of DVB TV Streams

Thu Apr 07, 2016 8:35 am

spyer wrote:Good Morning,

do you have any idea how I can install it without synaptic?

edit: i try know:
sudo apt-get install gstreamer1.0*
gstreamer1.0 has quite a lot of packages- Some of them are installed by default (to support epiphany browser), but not all.

If you don't want to install synaptic, you can also use PiPackages. Search for gstreamer1.0-plugins.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

spyer
Posts: 6
Joined: Tue Apr 05, 2016 2:17 pm

Re: Real Time Transcoding of DVB TV Streams

Sat Apr 09, 2016 2:00 pm

hello,

the transcoding works, but with freezes after few minutes.
Unfortunately I can not setup higher bitrate, keeping the transcoding power.

What cann I do, to make it usable?

Spyer

gkreidl
Posts: 5306
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Real Time Transcoding of DVB TV Streams

Sun Apr 10, 2016 4:31 am

spyer wrote:hello,

the transcoding works, but with freezes after few minutes.
Unfortunately I can not setup higher bitrate, keeping the transcoding power.

What cann I do, to make it usable?

Spyer
I need more details what you are trying to do.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

Return to “Graphics, sound and multimedia”

Who is online

Users browsing this forum: kazuko.nakamura and 10 guests