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

Re: Real Time Transcoding of DVB TV Streams

Wed Jan 30, 2019 12:03 pm

Jonny_Muc wrote:
Wed Jan 30, 2019 7:59 am
Thank you for that awesome work! The real time transcoding performs really good on a Raspberry 3 with Jessie. Much better that other solutions I tried, even on powerful desktops.

Unfortunately my cheap STB accepts only ts-streams, but not mkv-streams. Is there any way to create ts-streams as output?

Regards
JM
I've tested it with the mpegtsmux module but could not get it to work.
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

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

Re: Real Time Transcoding of DVB TV Streams

Tue Feb 26, 2019 3:18 pm

Would you be prepared to do some experimentation for me?

We now have V4L2 codecs and resizer merged into the 4.19 kernel branch, and the rpi-update kernel has been updated to be 4.19. They use CMA for their memory allocations, so you'll need to add "cma=256M" or similar to the start of /boot/cmdline.txt. (CMA is not the same as gpu_mem in that Linux can still hand it out to other users, but may move those about in memory should a user request a CMA allocation it can't otherwise fulfil).

GStreamer (>1.10 IIRC) supports these through
video4linux2: v4l2jpegdec: V4L2 JPEG Decoder
video4linux2: v4l2mpeg4dec: V4L2 MPEG4 Decoder
video4linux2: v4l2mpeg2dec: V4L2 MPEG2 Decoder
video4linux2: v4l2h263dec: V4L2 H263 Decoder
video4linux2: v4l2h264dec: V4L2 H264 Decoder
video4linux2: v4l2vp8dec: V4L2 VP8 Decoder
video4linux2: v4l2h264enc: V4L2 H.264 Encoder
video4linux2: v4l2jpegenc: V4L2 JPEG Encoder
video4linux2: v4l2convert: V4L2 Video Converter
It obviously detects MJPEG as JPEG even though they are currently distinct formats within V4L2.

Being V4L2 they also support passing dmabufs for zero copying of the data - this should be a moderate gain over the OMX components which will always copy the images between components.
Transcoding and resizing off the command-line I'm getting x1.2 of realtime (took 8min13 for a 9min56 clip) for a 1080P decode, resize to 800x480 with v4l2convert, and then reencode that.
Command line:

Code: Select all

gst-launch-1.0 -e -vvv filesrc location=big_buck_bunny_1080p_h264.mov ! qtdemux name=mux ! queue ! h264parse ! v4l2h264dec capture-io-mode=4 ! v4l2convert output-io-mode=4 capture-io-mode=4 ! video/x-raw,format=I420,width=800,height=480 ! v4l2h264enc output-io-mode=5 ! h264parse ! qtmux ! filesink location=transcode.mov
Any chance you could try dropping this into your pipelines and see what performance you get? In theory it should be faster than the OMX versions due to the reduced copying.

I haven't read this whole thread, but it looks like you're currently having to use the GStreamer deinterlace component. It may be possible to wrap the GPU deinterlace as well, but I'm not sure GStreamer supports that function through V4L2 at present. Interlacing as a whole is one thing I need to check through - I suspect there are various bits of plumbing missing in the signalling. Always more to do.

Thanks in advance.
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.

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

Re: Real Time Transcoding of DVB TV Streams

Wed Feb 27, 2019 9:55 am

6by9 wrote:
Tue Feb 26, 2019 3:18 pm
Would you be prepared to do some experimentation for me?

We now have V4L2 codecs and resizer merged into the 4.19 kernel branch, and the rpi-update kernel has been updated to be 4.19. They use CMA for their memory allocations, so you'll need to add "cma=256M" or similar to the start of /boot/cmdline.txt. (CMA is not the same as gpu_mem in that Linux can still hand it out to other users, but may move those about in memory should a user request a CMA allocation it can't otherwise fulfil).

GStreamer (>1.10 IIRC) supports these through
video4linux2: v4l2jpegdec: V4L2 JPEG Decoder
video4linux2: v4l2mpeg4dec: V4L2 MPEG4 Decoder
video4linux2: v4l2mpeg2dec: V4L2 MPEG2 Decoder
video4linux2: v4l2h263dec: V4L2 H263 Decoder
video4linux2: v4l2h264dec: V4L2 H264 Decoder
video4linux2: v4l2vp8dec: V4L2 VP8 Decoder
video4linux2: v4l2h264enc: V4L2 H.264 Encoder
video4linux2: v4l2jpegenc: V4L2 JPEG Encoder
video4linux2: v4l2convert: V4L2 Video Converter
It obviously detects MJPEG as JPEG even though they are currently distinct formats within V4L2.

Being V4L2 they also support passing dmabufs for zero copying of the data - this should be a moderate gain over the OMX components which will always copy the images between components.
Transcoding and resizing off the command-line I'm getting x1.2 of realtime (took 8min13 for a 9min56 clip) for a 1080P decode, resize to 800x480 with v4l2convert, and then reencode that.
Command line:

Code: Select all

gst-launch-1.0 -e -vvv filesrc location=big_buck_bunny_1080p_h264.mov ! qtdemux name=mux ! queue ! h264parse ! v4l2h264dec capture-io-mode=4 ! v4l2convert output-io-mode=4 capture-io-mode=4 ! video/x-raw,format=I420,width=800,height=480 ! v4l2h264enc output-io-mode=5 ! h264parse ! qtmux ! filesink location=transcode.mov
Any chance you could try dropping this into your pipelines and see what performance you get? In theory it should be faster than the OMX versions due to the reduced copying.

I haven't read this whole thread, but it looks like you're currently having to use the GStreamer deinterlace component. It may be possible to wrap the GPU deinterlace as well, but I'm not sure GStreamer supports that function through V4L2 at present. Interlacing as a whole is one thing I need to check through - I suspect there are various bits of plumbing missing in the signalling. Always more to do.

Thanks in advance.
This looks very promising! Unfortunately I cannot test it for DVB-Transcoding at the moment. I can't afford to install a new and possibly unstable kernel and firmware on any system right now (all running from HDD with boot partition on SD card). I have to wait until the new kernel becomes standard.
Does the video scaling use the GPU?
And having a chance to deinterlace using the GPU would really make a big difference. Most TV-Transmissions are interlaced (all SD channels and 1080i HD channels) and you may get "teared" images, especially on live sports channels without deinterlacing before you scale the image down to a lower 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

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

Re: Real Time Transcoding of DVB TV Streams

Wed Feb 27, 2019 1:21 pm

gkreidl wrote:
Wed Feb 27, 2019 9:55 am
This looks very promising! Unfortunately I cannot test it for DVB-Transcoding at the moment. I can't afford to install a new and possibly unstable kernel and firmware on any system right now (all running from HDD with boot partition on SD card). I have to wait until the new kernel becomes standard.
OK, I guess I'll grab your scripts and try hacking it myself.
gkreidl wrote:Does the video scaling use the GPU?
Yes, it's done on the ISP, so dedicated hardware.
gkreidl wrote:And having a chance to deinterlace using the GPU would really make a big difference. Most TV-Transmissions are interlaced (all SD channels and 1080i HD channels) and you may get "teared" images, especially on live sports channels without deinterlacing before you scale the image down to a lower resolution.
GStreamer crowd don't appear to have decided how they'd like deinterlacing to be represented by V4L2, and the V4L2 crowd don't seem to have specified it, therefore it's all in limbo and unsupported. I don't fancy trying to add it into GStreamer as I get lost in their classes.

The GPU deinterlacing routines only support a couple of field layouts, so trying to convince it to take the data could be tricky. It also needs the decoder to advertise the interlacing mode correctly, and at the moment I don't believe it does at all. There are some discussions as to how to handle this best for Kodi, so the same may be able to apply here.
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.

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

Re: Real Time Transcoding of DVB TV Streams

Thu Feb 28, 2019 9:45 am

6by9 wrote:
Wed Feb 27, 2019 1:21 pm
gkreidl wrote:
Wed Feb 27, 2019 9:55 am
This looks very promising! Unfortunately I cannot test it for DVB-Transcoding at the moment. I can't afford to install a new and possibly unstable kernel and firmware on any system right now (all running from HDD with boot partition on SD card). I have to wait until the new kernel becomes standard.
OK, I guess I'll grab your scripts and try hacking it myself.
gkreidl wrote:Does the video scaling use the GPU?
Yes, it's done on the ISP, so dedicated hardware.
gkreidl wrote:And having a chance to deinterlace using the GPU would really make a big difference. Most TV-Transmissions are interlaced (all SD channels and 1080i HD channels) and you may get "teared" images, especially on live sports channels without deinterlacing before you scale the image down to a lower resolution.
GStreamer crowd don't appear to have decided how they'd like deinterlacing to be represented by V4L2, and the V4L2 crowd don't seem to have specified it, therefore it's all in limbo and unsupported. I don't fancy trying to add it into GStreamer as I get lost in their classes.

The GPU deinterlacing routines only support a couple of field layouts, so trying to convince it to take the data could be tricky. It also needs the decoder to advertise the interlacing mode correctly, and at the moment I don't believe it does at all. There are some discussions as to how to handle this best for Kodi, so the same may be able to apply here.
You don't have to "hack" anything. The best way to test new gstreamer tool chains is to use http-launch directly.
You need a working TV backend which sends a http or udp MPEG TS stream. rtranscode can display the command line argument it uses (-sm argument). Here is a simple example (DVB--Sat, 1080i50 interlaced HD stream):

Code: Select all

$ rtranscode -e=3 -sm -t=http://192.168.0.34:9082/bysid/108

http-launch 9080 /xyz.mkv video/x-matroska default souphttpsrc location="http://192.168.0.34:9082/bysid/108" is-live=true keep-alive=true do-timestamp=true retries=10 typefind=true blocksize=16384 ! tsdemux parse-private-sections=false program-number=-1 name=demux demux.audio_0_0403 ! queue ! ac3parse ! matroskamux name=stream streamable=true demux. ! queue ! h264parse ! video/x-h264,alignment=au ! omxh264dec ! video/x-raw,width=1920,height=1080 ! deinterlace mode=interlaced fields=top method=scalerbob tff=tff ! videoscale method=nearest-neighbour qos=false add-borders=true sharpen=0 envelope=1 ! video/x-raw,width=910,height=512 ! omxh264enc target-bitrate=1294222 control-rate=variable ! h264parse ! queue ! stream.
-e=3 sets deinterlacing to scalerbob ( without the -e argument no deinterlacing is used).

Copy the command line output to a text file and start experimenting with it. The gstreamer tool chain starts with "souphttpsrc". It must have "stream." as last argument (which must be the name of the muxer).
The first 4 arguments are used internally by http-launch (port, path, mime type and a special code word, leave it as "default").
The resulting stream can be accessed by http://localhost:9080/xyz.mkv (with the above settings).
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

gigo1988
Posts: 44
Joined: Wed Sep 07, 2016 11:38 pm

Re: Real Time Transcoding of DVB TV Streams

Wed Mar 13, 2019 3:39 pm

Hi gkreidl,

if you know i have wrote some times ago that i ve issues by transcoding rlt hd and rtl 2 hd. Now i see some differents between other channels. the frame rate is not 25 like by sat1 and pro 7. on my stream test software on my server it show 25,6 by rtl and rtl2 and by pro7 and sat1 the right frame rate. Could you check this? on other transcoding method like on enigma 2 devices with software method i see the same issues.

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

Re: Real Time Transcoding of DVB TV Streams

Sat Mar 16, 2019 6:49 am

gigo1988 wrote:
Wed Mar 13, 2019 3:39 pm
Hi gkreidl,

if you know i have wrote some times ago that i ve issues by transcoding rlt hd and rtl 2 hd. Now i see some differents between other channels. the frame rate is not 25 like by sat1 and pro 7. on my stream test software on my server it show 25,6 by rtl and rtl2 and by pro7 and sat1 the right frame rate. Could you check this? on other transcoding method like on enigma 2 devices with software method i see the same issues.
I cannot test these channels. They are encrypted and and I don't have access to them.
The channel frame rate should not really matter. It is not used in any decoder/encoder settings.
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

kazuko.nakamura
Posts: 58
Joined: Sun May 29, 2016 7:14 am

Re: Real Time Transcoding of DVB TV Streams

Mon Apr 15, 2019 1:12 pm

Hi everyone,

Would be possible to use rtranscode to stream and transcode video from webcam on RPi2 ???

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

Re: Real Time Transcoding of DVB TV Streams

Mon Apr 15, 2019 2:30 pm

kazuko.nakamura wrote:
Mon Apr 15, 2019 1:12 pm
Hi everyone,

Would be possible to use rtranscode to stream and transcode video from webcam on RPi2 ???
No. The whole application is written for DVB TV 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

gigo1988
Posts: 44
Joined: Wed Sep 07, 2016 11:38 pm

Re: Real Time Transcoding of DVB TV Streams

Tue Apr 16, 2019 6:53 pm

Hi gkreidl,

it sounds like a new version is comeing :D is it right?

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

Re: Real Time Transcoding of DVB TV Streams

Wed Apr 17, 2019 6:11 am

gigo1988 wrote:
Tue Apr 16, 2019 6:53 pm
Hi gkreidl,

it sounds like a new version is comeing :D is it right?
No.
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

johndavies
Posts: 176
Joined: Fri Dec 20, 2013 1:00 pm

Using a Pi TVHat, tvheadend URLs and rtranscode4

Thu May 30, 2019 5:55 pm

I put the following in the TVHat section and I thought i might as well post it here in case it is of use to anyone. I will accept that VLC produces a higher quality output than omxplayergui but I was curious to see if I could use tvheadend-generated URLs with the Pi TVHat and rtranscode4. My problem is that I am a skim reader after too many years of teaching and marking external GCSE History papers and this makes it very difficult for me to absorb technical information. Gkreidl's work on rtranscode4 is very well documented but I could not see how he produced the URLs so I decided to try tvheadend ones. The Minimal Kiosk Browser needs to be saved on the Pi.This also includes omxplayergui. rtranscode4 includes an install for the latest Minimal Kiosk Browser (aka kweb)
PRODUCING A CHANNELS LIST
It is easy to convert an m3u VLC playlist into one which rtranscode4 can use. Enter the following into a terminal for a playlist called playlist.m3u:
rtranscode -i=playlist.m3u -o=channels.dat
This will produce a channels file in the /home/pi directory which rtranscode can use. This needs to be copied elsewhere if you want a default channels list. The manual explains how you can add other lists of channels.

CREATING A DEFAULT CHANNELS LIST FOR RECORDING
This default playlist is stored as /usr/local/share/rtranscode/channels.dat. The way that I did it was to create an empty file by typing sudo nano and the path just mentioned into a Terminal, opening it up and copying the channels data stored in the home/pi/channels.dat into the /usr/local/share/rtranscode/channels.dat one and then saving it.Other channels in the rtranscode format can be added later.

ERECORDING CHANNELS IN REAL TIME
There is no PVR feature which allows you to record hours or days ahead. Typing rtranscode into a terminal will produce a gui for recording the channels stored in Channels.dat and choosing various settings for quality etc. This puts the saved programme in the home/pi directory. There is a command which allows you to save to a named directory. The command is rtranscode -l=/path/to/chosen/directory and, if this is entered, the gui showing channels available and the settings appears. Other commands are easy to apply. t and Enter allow you to enter a time for recording e.g. 1:00 records for one hour. r and Enter starts recording. s and Enter stops recording at any time. q and Enter quits the rtranscode gui.

WATCHING TV PRORAMMES
As far as I know there is no way of watching a TV programme and recording it at the same time. I do not think that there is a rtranscode command that will show a TV programme. The only way i know how to watch a TV programme is by using the RT-GUI. To do this you open up the rtranscode4 and install kweb (Minimal Kiosk Browser) which also loads omxplayergui. Then you open up the kweb directory to gain access to the RT-GUI. To make your channel list available to it, you run create_kpages.py
This allows your channels.dat to be added. When ever you add extra channels to your channels.dat, file, you need to run create_kpages.py again for these new channels to be recognised. If you put a copy of RT-GUI in your /home/pi directory. There is an added bonus. Entering ./RT-GUI into a Terminal and pressing Enter will produce the RT-GUi entry scheme where you can choose a programme, press the Transcode box , wait a few seconds until the blue bar stops flashing qand then press the Play Transcoded Stream box to watch the programme of your choice.

I shall finish by apologising to gkreidl and to the Raspberry Pi community if I have missed anything glaringly obvious or made any basic errors.

david_Est
Posts: 10
Joined: Sun Jun 17, 2012 4:58 pm

Re: Real Time Transcoding of DVB TV Streams

Mon Jun 24, 2019 7:24 am

Would be great if new rpi4 has the capabilities to support this. Even greater if HEVC codec is selectable for encoding

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

Re: Real Time Transcoding of DVB TV Streams

Mon Jun 24, 2019 7:38 am

david_Est wrote:
Mon Jun 24, 2019 7:24 am
Would be great if new rpi4 has the capabilities to support this. Even greater if HEVC codec is selectable for encoding
Hevc is decode only on the pi4.

We are chasing down an issue that only showed up in the last few days where simultaneous encode and decode with the h264 codec block stalls. We're actively digging into it at the moment. It seems to be some hardware quirk as the same code on Pi3 works fine.
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.

david_Est
Posts: 10
Joined: Sun Jun 17, 2012 4:58 pm

Re: Real Time Transcoding of DVB TV Streams

Mon Jun 24, 2019 12:58 pm

6by9 wrote:
Mon Jun 24, 2019 7:38 am
david_Est wrote:
Mon Jun 24, 2019 7:24 am
Would be great if new rpi4 has the capabilities to support this. Even greater if HEVC codec is selectable for encoding
Hevc is decode only on the pi4.

We are chasing down an issue that only showed up in the last few days where simultaneous encode and decode with the h264 codec block stalls. We're actively digging into it at the moment. It seems to be some hardware quirk as the same code on Pi3 works fine.
OK! thank you guys for your work!

Return to “Graphics, sound and multimedia”