belos
Posts: 8
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: 21650
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.....
......to a more gentile life !

belos
Posts: 8
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: 6195
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: 504
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: 21650
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.....
......to a more gentile life !

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7916
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: 8
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 6455 times
tvh3.png
tvh3.png (228.4 KiB) Viewed 6455 times
tvh4.jpg
tvh4.jpg (170.31 KiB) Viewed 6455 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: 8
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: 8
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

dgilbert2
Posts: 4
Joined: Thu Feb 13, 2020 5:52 am

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

Thu Feb 13, 2020 6:32 am

Does anyone know if this still works with the latest PI4 / Buster release?

I have used TVHeadEnd version 4.3-1801_g7f952c2ed, thanks to the above download link.

In terms of ffmpeg, I'm using the default build as that now seems to be enabled for OpenMAX (version 4.1.4-1+rpt7~deb10u1 .... built with gcc 8 (Raspbian 8.3.0-6+rpi1). ie it reports "V..... h264_omx OpenMAX IL H.264 video encoder (codec h264)" when entering "ffmpeg -encoders | grep h264_omx" into terminal.

In a TVHeadEnd spawn profile I have tried both the following;

Code: Select all

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

Code: Select all

ffmpeg -i - -f mpegts -c:a copy -c:v h264_omx -b:v 600k -maxrate 600k -bufsize 1M pipe:1
Both of these fail to work though, in the TVHeanEnd log, I can see ffmpeg starting the transcode but then it ends with conversion / piping errors.

Any ideas please?
.

belos
Posts: 8
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)

Tue Feb 18, 2020 1:49 pm

It worth to try gst-launch-1.0 command from the previous post.
As for me, Gstreamer gives a better picture with less CPU load comparing to ffmpeg.
Which viewer do you use? Have you tried to view the stream with a different viewer, for example, VLC, Kodi, or Tvhclient for mobile devices)?

michaelgraaf
Posts: 3
Joined: Sat May 05, 2018 1:11 pm

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

Wed Feb 19, 2020 1:19 pm

Have attempted this with a Pi 3 and a Pi 4, both fitted with TV Hat and connected to decent antenna (signal detected and services identified using CLI tool dvbv5-scan). Am located in South Africa where digital TV is DVB-T2. Although I edited the file etc/apt/sources.list.d/tvheadend.list to say

deb [allow-insecure=yes] https://apt.tvheadend.org/unstable raspbian-buster main

after command sudo apt update, I still get

Get:1 http://raspbian.raspberrypi.org/raspbian buster InRelease [15.0 kB]
Hit:2 http://archive.raspberrypi.org/debian buster InRelease
Ign:3 https://apt.tvheadend.org/unstable raspbian-buster InRelease
Get:4 http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages [13.0 MB]
Ign:5 https://apt.tvheadend.org/unstable raspbian-buster Release
Ign:6 https://apt.tvheadend.org/unstable raspbian-buster/main armhf Packages
Ign:7 https://apt.tvheadend.org/unstable raspbian-buster/main all Packages
Ign:8 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en_ZA.UTF-8
Ign:9 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en
Ign:10 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en_ZA
Ign:6 https://apt.tvheadend.org/unstable raspbian-buster/main armhf Packages
Ign:7 https://apt.tvheadend.org/unstable raspbian-buster/main all Packages
Ign:8 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en_ZA.UTF-8
Ign:9 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en
Ign:10 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en_ZA
Ign:6 https://apt.tvheadend.org/unstable raspbian-buster/main armhf Packages
Ign:7 https://apt.tvheadend.org/unstable raspbian-buster/main all Packages
Ign:8 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en_ZA.UTF-8
Ign:9 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en
Ign:10 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en_ZA
Ign:6 https://apt.tvheadend.org/unstable raspbian-buster/main armhf Packages
Ign:7 https://apt.tvheadend.org/unstable raspbian-buster/main all Packages
Ign:8 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en_ZA.UTF-8
Ign:9 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en
Ign:10 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en_ZA
Ign:6 https://apt.tvheadend.org/unstable raspbian-buster/main armhf Packages
Ign:7 https://apt.tvheadend.org/unstable raspbian-buster/main all Packages
Ign:8 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en_ZA.UTF-8
Ign:9 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en
Ign:10 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en_ZA
Ign:6 https://apt.tvheadend.org/unstable raspbian-buster/main armhf Packages
Ign:7 https://apt.tvheadend.org/unstable raspbian-buster/main all Packages
Ign:8 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en_ZA.UTF-8
Ign:9 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en
Ign:10 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en_ZA
Err:6 https://apt.tvheadend.org/unstable raspbian-buster/main armhf Packages
404 Not Found [IP: 104.31.94.73 443]
Ign:7 https://apt.tvheadend.org/unstable raspbian-buster/main all Packages
Ign:8 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en_ZA.UTF-8
Ign:9 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en
Ign:10 https://apt.tvheadend.org/unstable raspbian-buster/main Translation-en_ZA
Fetched 13.0 MB in 24s (551 kB/s)
Reading package lists... Done
W: The repository 'https://apt.tvheadend.org/unstable raspbian-buster Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: Failed to fetch https://apt.tvheadend.org/unstable/dist ... f/Packages 404 Not Found [IP: 104.31.94.73 443]
E: Some index files failed to download. They have been ignored, or old ones used instead.

...and when doing a mux scan, no services are detected.

Any ideas?

dgilbert2
Posts: 4
Joined: Thu Feb 13, 2020 5:52 am

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

Wed Feb 19, 2020 1:59 pm

In the apt.tvheadend.org there are no raspbian-buster releases at the moment, you need to use either of the following;

"apt.tvheadend.org/stable raspbian-stretch main"
"apt.tvheadend.org/unstable raspbian-stretch main"

See https://tvheadend.org/projects/tvheaden ... positories for full instructions.

michaelgraaf
Posts: 3
Joined: Sat May 05, 2018 1:11 pm

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

Thu Feb 20, 2020 6:05 am

Thanks dgilbert2, will try. But seem to remember that Pi 4 doesn't do Stretch. Well I can stick to the Pi 3 while the repo catches up...

User avatar
rpdom
Posts: 16121
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

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

Thu Feb 20, 2020 6:21 am

michaelgraaf wrote:
Thu Feb 20, 2020 6:05 am
Thanks dgilbert2, will try. But seem to remember that Pi 4 doesn't do Stretch. Well I can stick to the Pi 3 while the repo catches up...
You'll still be using Buster, just with the TV-Headend packages for Stretch. It's quite probable that will work.

It's the kernel and bootloader parts of the OS that need to be the ones supplied with Buster. Most of the rest of the software in Stretch should run on a Pi4.

Mixing releases isn't the preferred way of doing things though, but in absence of another method it is sometimes necessary (he says while running Stretch with some packages from Buster and Bullseye on his Debian with RPD laptop :lol: )

dgilbert2
Posts: 4
Joined: Thu Feb 13, 2020 5:52 am

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

Thu Feb 20, 2020 6:31 am

The Stretch builds of TVHeadEnd do work on a PI4 running Buster.

However, in all honesty, the current unstable 4.3 builds have a lot of features disabled at the moment for PI's (eg transcoding, spawn profiles). I would stick with the regular stable 4.2.8 build available through the standard "sudo apt-get install tvheadend" on the PI4.

dgilbert2
Posts: 4
Joined: Thu Feb 13, 2020 5:52 am

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

Thu Feb 20, 2020 6:44 am

belos wrote:
Tue Feb 18, 2020 1:49 pm
It worth to try gst-launch-1.0 command from the previous post.
As for me, Gstreamer gives a better picture with less CPU load comparing to ffmpeg.
Which viewer do you use? Have you tried to view the stream with a different viewer, for example, VLC, Kodi, or Tvhclient for mobile devices)?
Thanks, I will try Gstreamer, but for now I have gone back to 4.2.8 and settled with the software video codecs, making my PI4 work hard :(

It did not seem viewer related, it failed with VLC, TvhClient, Chrome/Firefox/Edge browsers.

EDIT: How are you setting up the Spawn profile to use Gstreamer?

Return to “HATs and other add-ons”