belos
Posts: 7
Joined: Tue Nov 20, 2018 4:08 pm

Raspberry Pi TV Hat DVB-T2 Gateway (Tvheadend with FFmpeg and realtime hardware video stream transcoding)

Tue Nov 20, 2018 4:23 pm

This is a very-very short installation manual that gives 100% working result.
Hardware: Raspberry Pi 3 Model B and Raspberry Pi TV Hat.

1. Install Raspbian Jessie (not Raspbian Stretch!) and update the system.

2. Install Tvheadend v4.3 (unstable) as described here:
https://tvheadend.org/projects/tvheaden ... tories#fn3

3. Configure Tvheadend, and test viewing your air TV channels using default MPEG-TS Pass-through "pass" stream profile.

4. Download and compile OpenMAX-enabled FFmpeg:
https://www.reddit.com/r/raspberry_pi/c ... ith_ffmpeg

4a. (not necessary!). Run the following command and make sure you can see the test picture. This means that hardware acceleration works properly:

Code: Select all

"gst-launch-1.0 -v videotestsrc ! omxh264enc ! h264parce ! omx264dec ! glimagesink"

5. Create the new streaming profile in Tvheadend web interface (Configuration->Stream->Stream Profiles) using "MPEG-TS Spawn/ built-in" type with the command line:

Code: Select all

"ffmpeg -i - -f mpegts -c:a copy -c:v h264_omx -b:v 368k pipe:1"

This will generate the stream with the bitrate about 500-600 kbit/s instead of several Mbit/s using GPU hardware transcoding.
During the transcoding CPU usage will not be higher than 40-60% comparing to 150% in case if you are using any other software transcoding. CPU temperature will not raise above 60-65°C.

Most probably this configuration will work on any Raspberry Pi (even on RPi Zero), of course, depending on the input signal complexity.
I also have Kodi on my RPi Zero connected to TV that is used as a client system for the described installation.

Hope this info will help someone. I´m open for any comments and questions.
Last edited by belos on Tue Jul 30, 2019 1:53 pm, edited 2 times in total.

fruitoftheloom
Posts: 20493
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Raspberry Pi TV Hat DVB-T2 Gateway (Tvheadend with FFmpeg and realtime hardware video stream transcoding)

Tue Nov 20, 2018 6:23 pm

belos wrote:
Tue Nov 20, 2018 4:23 pm
This is a very-very short installation manual that gives 100% working result.
Hardware: Raspberry Pi 3 Model B and Raspberry Pi TV Hat.

1. Install Raspbian Jessie (not Raspbian Stretch!) and update the system.

2. Install Tvheadend v4.3 (unstable) as described here:
https://tvheadend.org/projects/tvheaden ... tories#fn3

3. Configure Tvheadend, and test viewing your air TV channels using default MPEG-TS Pass-through "pass" stream profile.

4. Download and compile OpenMAX-enabled FFmpeg:
https://www.reddit.com/r/raspberry_pi/c ... ith_ffmpeg

4. Run the following command and make sure you can see the test picture. This means that hardware acceleration works properly:

Code: Select all

"gst-launch-1.0 -v videotestsrc ! omxh264enc ! h264parce ! omx264dec ! glimagesink"

5. Create new streaming profile in Tvheadend web interface (Configuration->Stream->Stream Profiles) using "MPEG-TS Spawn/ built-in" type with the command line:

Code: Select all

"ffmpeg -i - -f mpegts -c:a copy -c:v h264_omx -b:v 368k pipe:1"

This will generate the stream with the bitrate about 500-600 kbit/s instead of several Mbit/s using GPU hardware transcoding.
During the transcoding CPU usage will not be higher than 40-60% comparing to 150% in case if you are using any other software transcoding. CPU temperature will not raise above 60-65°C.

Most probably this configuration will work on any Raspberry Pi (even on RPi Zero), of course, depending on the input signal complexity.
I also have Kodi on my RPi Zero connected to TV that is used as a client system for the described installation.

Hope this info will help someone. I´m open for any comments and questions.

Raspbian Jessie is no longer supported and any user not aware will try this on the 3B+ / 3A+......
Retired disgracefully.....

belos
Posts: 7
Joined: Tue Nov 20, 2018 4:08 pm

Re: Raspberry Pi TV Hat DVB-T2 Gateway (Tvheadend with FFmpeg and realtime hardware video stream transcoding)

Wed Nov 21, 2018 8:35 am

Thanks, that´s right. But sometimes we have to use old, but proved solutions to achieve the desired result.

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

Re: Raspberry Pi TV Hat DVB-T2 Gateway (Tvheadend with FFmpeg and realtime hardware video stream transcoding)

Wed Nov 21, 2018 9:36 am

My rtranscode V4 package offers a complete transcoding solution which works with different backends on both Jessie and Stretch. Transcoding on Jessie is more efficient though because the gst-omx module has implemented hardware scaling, which is missing in the Stretch version.

viewtopic.php?f=38&t=123876
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

fanoush
Posts: 464
Joined: Mon Feb 27, 2012 2:37 pm

Re: Raspberry Pi TV Hat DVB-T2 Gateway (Tvheadend with FFmpeg and realtime hardware video stream transcoding)

Wed Nov 21, 2018 12:47 pm

Just wondering what type of trancoding (resolution? codec types?) is this targeted for? Can this transcode HEVC/h265 to h264 in realtime on pi3b+? Or does it trancode mpeg-2 to h264? Can it do mpeg-2 in realtime without paid HW codec?

john564
Posts: 87
Joined: Tue Oct 30, 2012 7:05 am

Re: Raspberry Pi TV Hat DVB-T2 Gateway (Tvheadend with FFmpeg and realtime hardware video stream transcoding)

Sun Jul 07, 2019 11:21 am

OMG...

Code: Select all

gst-launch-1.0 -v videotestsrc ! omxh264enc ! h264parce ! omx264dec ! glimagesink
should be

Code: Select all

gst-launch-1.0 -v videotestsrc ! omxh264enc ! h264parse ! omxh264dec ! glimagesink
list parameters with gst-inspect-1.0

you have no idea how long time I spent to find out the 100% working guide was wrong

fruitoftheloom
Posts: 20493
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: Raspberry Pi TV Hat DVB-T2 Gateway (Tvheadend with FFmpeg and realtime hardware video stream transcoding)

Sun Jul 07, 2019 11:57 am

john564 wrote:
Sun Jul 07, 2019 11:21 am
OMG...

Code: Select all

gst-launch-1.0 -v videotestsrc ! omxh264enc ! h264parce ! omx264dec ! glimagesink
should be

Code: Select all

gst-launch-1.0 -v videotestsrc ! omxh264enc ! h264parse ! omxh264dec ! glimagesink
list parameters with gst-inspect-1.0

you have no idea how long time I spent to find out the 100% working guide was wrong

I stated above the guide is for Jessie, not Stretch or Buster :shock:
Retired disgracefully.....

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7149
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Raspberry Pi TV Hat DVB-T2 Gateway (Tvheadend with FFmpeg and realtime hardware video stream transcoding)

Sun Jul 07, 2019 12:39 pm

It's not a jessie/stretch/buster complaint, but the typo with h264parce instead of h264parse.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

belos
Posts: 7
Joined: Tue Nov 20, 2018 4:08 pm

Re: Raspberry Pi TV Hat DVB-T2 Gateway (Tvheadend with FFmpeg and realtime hardware video stream transcoding)

Sun Jul 07, 2019 2:53 pm

6by9 wrote:
Sun Jul 07, 2019 12:39 pm
It's not a jessie/stretch/buster complaint, but the typo with h264parce instead of h264parse.
Actually, you can skip this gst-launch-1.0 command and go strait to number 5 :)
I am still on Jessie. If you want, you can try to repeat it on Buster and tell the community if it works or not. I can repeat it in August when I have physical access to the system.

Update as of 16.07.2019:
I confirm, that the above instruction also works on Raspbian Buster. It´s easy and free.
Just compile FFmpeg with options, install TVheadend 4.3, and use Spawn profile for the HW-accelerated stream transcoding.
tvh1.png
tvh1.png (80.74 KiB) Viewed 3102 times
tvh3.png
tvh3.png (228.4 KiB) Viewed 3102 times
tvh4.jpg
tvh4.jpg (170.31 KiB) Viewed 3102 times

john564
Posts: 87
Joined: Tue Oct 30, 2012 7:05 am

Re: Raspberry Pi TV Hat DVB-T2 Gateway (Tvheadend with FFmpeg and realtime hardware video stream transcoding)

Sun Jul 21, 2019 12:11 pm

thanks, its beginning to come together now.

# Install tvheadend 4.3 unstable on Raspbian Buster

wget https://markclarkstone.co.uk/downloads/ ... _armhf.deb
sudo dpkg -i tvheadend_4.3-1801~g7f952c2ed~raspbianbuster_armhf.deb
sudo apt --fix-broken install

#test
sudo apt-get install gstreamer1.0-tools
gst-launch-1.0 -v videotestsrc ! omxh264enc ! h264parse ! omxh264dec ! glimagesink

# transcode setting for tvheadend
ffmpeg -i - -f mpegts -c:a copy -c:v h264_omx -b:v 600k -maxrate 600k -bufsize 1M pipe:1
Last edited by john564 on Mon Jul 22, 2019 7:29 am, edited 4 times in total.


belos
Posts: 7
Joined: Tue Nov 20, 2018 4:08 pm

Re: Raspberry Pi TV Hat DVB-T2 Gateway (Tvheadend with FFmpeg and realtime hardware video stream transcoding)

Mon Jul 22, 2019 10:10 am

john564 wrote:
Sun Jul 21, 2019 12:11 pm
thanks, its beginning to come together now.

# Install tvheadend 4.3 unstable on Raspbian Buster

wget https://markclarkstone.co.uk/downloads/ ... _armhf.deb
sudo dpkg -i tvheadend_4.3-1801~g7f952c2ed~raspbianbuster_armhf.deb
sudo apt --fix-broken install

#test
sudo apt-get install gstreamer1.0-tools
gst-launch-1.0 -v videotestsrc ! omxh264enc ! h264parse ! omxh264dec ! glimagesink

# transcode setting for tvheadend
ffmpeg -i - -f mpegts -c:a copy -c:v h264_omx -b:v 600k -maxrate 600k -bufsize 1M pipe:1
Please do not go through the #test section. It is not needed because it is not the test of ffmpeg functionality. This was my mistake.

john564
Posts: 87
Joined: Tue Oct 30, 2012 7:05 am

Re: Raspberry Pi TV Hat DVB-T2 Gateway (Tvheadend with FFmpeg and realtime hardware video stream transcoding)

Fri Aug 16, 2019 9:43 pm

Some more transcoding options, to use with "MPEG-TS Spawn/build-in"

======================================

ffmpeg -i - -f mpegts -c:a copy -c:v h264_omx -threads 4 -crf 28 -b:v 600k -maxrate 900k -bufsize 1M pipe:1

======================================

gst-launch-1.0 fdsrc fd=0 \
! decodebin name=decoder decoder. \
! queue \
! avenc_ac3 \
! mpegtsmux name=mux \
! fdsink fd=1 decoder. \
! omxh264enc target-bitrate=600000 control-rate=variable \
! video/x-h264,stream-format=byte-stream,profile=high \
! mux.

belos
Posts: 7
Joined: Tue Nov 20, 2018 4:08 pm

Re: Raspberry Pi TV Hat DVB-T2 Gateway (Tvheadend with FFmpeg and realtime hardware video stream transcoding)

Sat Aug 17, 2019 8:29 pm

Thank you, John!
This gst-launch is a really good thing! Less CPU usage with better quality. I guess it can transcode Full HD content on my RP3 as good as SD content!

[Update]
But, unfortunately, after several minutes of operation, gst-launch-1.0 crashes and the session does not terminate.
Perhaps this converter is very sensitive to input errors compared to ffmpeg.
I'll try to enable debug messages and see what happens...

john564
Posts: 87
Joined: Tue Oct 30, 2012 7:05 am

Re: Raspberry Pi TV Hat DVB-T2 Gateway (Tvheadend with FFmpeg and realtime hardware video stream transcoding)

Tue Aug 20, 2019 8:30 am

I don't have problem with it crashing when using gst-launch-1.0
EDIT: no problem with SD, HD seems to have issue
But I am using RPi4 and gave more memory to GPU at the start.
in
sudo raspi-config
--> 7 Advanced Options
--> A3 Memory Split

How much memory (MB) should the GPU have ?
--> 512

---------------------------------------------------------------------------

But I don't know how to find out how much memory and processor load the GPU is actually using
to fine tune it.

Any idea ?

-----------------------------------------------------------------------------

also I often use a different profile, with no bitrate control, (but an annoying strange coloured line at the bottom)

gst-launch-1.0 fdsrc fd=0 \
! decodebin name=decoder decoder. \
! queue \
! avenc_ac3 \
! mpegtsmux name=mux \
! fdsink fd=1 decoder. \
! omxh264enc \
! mux.

-----------------------------------------------------------------------------------------------------

Note: the site https://markclarkstone.co.uk is down at the moment
I saved a copy of his deb package to dropbox, just post here, incase its needed

# install

Code: Select all

wget --no-check-cert  https://www.dropbox.com/s/zt5bcsc6126f4mp/tvheadend_4.3-1801_g7f952c2ed_raspbianbuster_armhf.deb
sudo dpkg -i tvheadend_4.3-1801_g7f952c2ed_raspbianbuster_armhf.deb
sudo apt --fix-broken install

Return to “HATs and other add-ons”