User avatar
mstegmann
Posts: 1
Joined: Thu Oct 24, 2013 11:12 pm
Location: Saarbrücken, Germany
Contact: Website

Using GStreamer as transcoder for Dreambox or TVheadend

Mon Oct 28, 2013 11:25 am

Hey

I'm currently experimenting with GStreamer to develop a simple transcoder for live television. It took me all weekend, but I actually put together a nearly perfect working pipeline.

My configuration
- Raspberry Pi (265MB RAM)
- Dreambox 8000
- Raspian (latest)
- Gstreamer 1.0
- gst-omx (latest from git)

I know others have already tried similarly things, so I wanted to share my results with you.

Video without sound (good)

Code: Select all

gst-launch-1.0 souphttpsrc location="http://192.168.1.26:8001/1:0:1:6DCA:44D:1:C00000:0:0:0:" ! decodebin ! queue ! videoconvert ! omxh264enc ! video/x-h264,stream-format=byte-stream,profile=high ! h264parse ! mpegtsmux ! tcpserversink host=192.168.1.68 port=5000
Video with sound (bad)

Code: Select all

gst-launch-1.0 souphttpsrc location="http://192.168.1.26:8001/1:0:1:6DCA:44D:1:C00000:0:0:0:" ! decodebin name=demux demux. ! queue ! audioresample ! audioconvert ! "audio/x-raw,format=F32LE" ! vorbisenc ! mux. matroskamux name=mux ! tcpserversink host=192.168.1.68 port=5000 demux. ! queue ! videoconvert ! omxh264enc ! "video/x-h264,profile=high" ! h264parse ! mux.
Video with sound (raw audio)

Code: Select all

gst-launch-1.0 souphttpsrc location="http://192.168.1.26:8001/1:0:1:6DCA:44D:1:C00000:0:0:0:" is-live=true ! decodebin name=demux demux. ! queue ! audioresample ! mux. matroskamux name=mux streamable=true ! tcpserversink host=192.168.1.68 port=5000 demux. ! queue ! videoconvert ! omxh264enc target-bitrate=2000000 control-rate=variable ! "video/x-h264,profile=high" ! h264parse ! mux.
Video with sound (perfect)

Code: Select all

gst-launch-1.0 souphttpsrc location="http://192.168.1.26:8001/1:0:1:6DCA:44D:1:C00000:0:0:0:" is-live=true ! decodebin name=demux demux. ! queue ! audioresample ! audioconvert dithering=0 ! "audio/x-raw,channels=1" ! flacenc ! mux. matroskamux name=mux streamable=true ! tcpserversink host=192.168.1.68 port=5000 demux. ! queue ! videoconvert ! omxh264enc target-bitrate=2000000 control-rate=variable ! "video/x-h264,profile=high" ! h264parse ! mux.
Unfortunately, there are two problems I could not solve so far.

1. The SPS / PPS issue

The omxh264enc plugin sends not regularly the needed SPS / PPS information with it. You can work around the problem by immediately accessing the stream after the start of gst-launch, otherwise VLC (for example) cannot play it.

I have found this wrapper for the camera:
https://github.com/AndyA/psips

But I could not find any working solution for GStreamer. Apparently you can fix this usually by modifying h264parse, but I had so far no success in combination with omxh264enc.

2. The "wrong track" issue

I cannot find a way to specify which audio track decodebin should use. That is not specifically a problem with omxh264enc, but maybe someone has an idea.

At the moment, he apparently takes the last PCM track, which unfortunately sometimes is the track with audio description (for blind).

Maybe decodebin has simply too much automatism. My attempts to build the pipe together by hand had so far only generated very unstable video.

Code: Select all

gst-launch-1.0 souphttpsrc location="http://192.168.1.26:8001/1:0:1:6DCA:44D:1:C00000:0:0:0:" ! tsdemux ! queue max-size-buffers=0 max-size-time=0 ! mpegvideoparse ! mpeg2dec ! videoconvert ! omxh264enc ! video/x-h264,stream-format=byte-stream,profile=high ! h264parse ! mpegtsmux ! tcpserversink host=192.168.1.68 port=5000
It's just a first experiment, but if all goes well, I want to build a server around it. So far I am very satisfied, the transcoding works extremely stable and very smooth.

I would appreciate any suggestions for improvements and help with the issues :-)

Best Regards,
Marcel
Attachments
IMG_1115.jpg
IMG_1115.jpg (57.45 KiB) Viewed 58952 times

manutoky
Posts: 5
Joined: Tue Jan 08, 2013 10:27 am

Re: Using GStreamer as transcoder for Dreambox or TVheadend

Tue Oct 29, 2013 2:22 pm

Wow, thanks. That's what I was looking for! I'll try and report!

manutoky

SilentAl
Posts: 9
Joined: Tue Oct 29, 2013 6:24 pm

Re: Using GStreamer as transcoder for Dreambox or TVheadend

Tue Oct 29, 2013 6:47 pm

Good work Marcel,

did you test it in combination with mediatomb?
With mediatomb you can use it as DLNA-Transcoder.

I tried it out with this setup:

[email protected] ~ $ cat /usr/bin/livetrans.sh

Code: Select all

#!/bin/sh

gst-launch-1.0 souphttpsrc  location="$1" is-live=true ! decodebin name=demux \
demux. ! queue ! audioresample ! audioconvert dithering=0 ! "audio/x-raw,channels=1" ! voaacenc bitrate=64000  ! \
mux. matroskamux name=mux streamable=true ! filesink location="$2"  append=true \
demux. ! queue ! videoconvert ! omxh264enc target-bitrate=1600000 control-rate=variable ! "video/x-h264,profile=high" ! h264parse ! mux.


In /etc/mediatomb/config.xml i created a transcoding profil:

Code: Select all


.
.
.
    <mappings>
      <extension-mimetype ignore-unknown="no">
        <map from="ts" to="video/mpeg"/>
.
.
.
<transcoding enabled="yes">
    <mimetype-profile-mappings>
      <transcode mimetype="video/mpeg" using="mpeg2trans"/>
.
.
.
<profiles>
 <profile name="mpeg2trans" enabled="yes" type="external">
        <use-chunked-encoding>yes</use-chunked-encoding>
        <mimetype>video/mpeg</mimetype>
        <accept-url>yes</accept-url>
        <first-resource>yes</first-resource>
        <hide-original-resource>no</hide-original-resource>
        <agent command="livetrans.sh" arguments="%in %out"/>
        <buffer size="1000000" chunk-size="10000" fill-size="200000"/>
      </profile>
.
.
.
If I start it in cmd, it works, but it did not work in mediatomb. Do you know whats wrong?

Greetings

Al

SilentAl
Posts: 9
Joined: Tue Oct 29, 2013 6:24 pm

Re: Using GStreamer as transcoder for Dreambox or TVheadend

Tue Oct 29, 2013 7:15 pm

Good work Marcel,

to your 2. issue:
you can select a specific track with

Code: Select all

decodebin name=demux demux.audio_00
did you test it in combination with mediatomb?
With mediatomb you can use it as DLNA-Transcoder.

I tried it out with this setup:

[email protected] ~ $ cat /usr/bin/livetrans.sh

Code: Select all

#!/bin/sh

gst-launch-1.0 souphttpsrc  location="$1" is-live=true ! decodebin name=demux \
demux. ! queue ! audioresample ! audioconvert dithering=0 ! "audio/x-raw,channels=1" ! voaacenc bitrate=64000  ! \
mux. matroskamux name=mux streamable=true ! filesink location="$2"  append=true \
demux. ! queue ! videoconvert ! omxh264enc target-bitrate=1600000 control-rate=variable ! "video/x-h264,profile=high" ! h264parse ! mux.


In /etc/mediatomb/config.xml i created a transcoding profil:

Code: Select all

.
.
.
    <mappings>
      <extension-mimetype ignore-unknown="no">
        <map from="ts" to="video/mpeg"/>
.
.
.
<transcoding enabled="yes">
    <mimetype-profile-mappings>
      <transcode mimetype="video/mpeg" using="mpeg2trans"/>
.
.
.
<profiles>
 <profile name="mpeg2trans" enabled="yes" type="external">
        <use-chunked-encoding>yes</use-chunked-encoding>
        <mimetype>video/mpeg</mimetype>
        <accept-url>yes</accept-url>
        <first-resource>yes</first-resource>
        <hide-original-resource>no</hide-original-resource>
        <agent command="livetrans.sh" arguments="%in %out"/>
        <buffer size="1000000" chunk-size="10000" fill-size="200000"/>
      </profile>
.
.
.
If I start it in cmd, it works, but it did not work in mediatomb. Do you know whats wrong?

Greetings

Al

ppumkin
Posts: 82
Joined: Tue May 29, 2012 10:22 pm

Re: Using GStreamer as transcoder for Dreambox or TVheadend

Tue Oct 29, 2013 10:17 pm

Hi Did you manage to solve th eproblem with SPS?

I am trying to pipe raspivid using this method. I nearly got there by creating my own sdp file for VLC by reading the CAPS data output by gsrteamer... but the video is black and I have no idea what to do now. (It did solve the SPS isue) All it is, is information about the stream, so by creating the sdp file it knows how to decode it.. but creating the sdp can be quite tricky


192.168.1.75 was the PC reciveing the UDP stream on VLC. Important things to change in m is the 1234 which is the udp port and the sprop-parameter(not sure what that is but its a weird random string- remove (string)"....." from gstteamer output) The rest is self explanatory

raspivid -t 999999 -w 640 -h 480 -fps 25 -b 500000 -o - | gst-launch-1.0 -vvvvv fdsrc ! h264parse ! rtph264pay ! udpsink port=1234 host=192.168.1.78

Starting video capture
Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
/GstPipeline:pipeline0/GstH264Parse:h264parse0.GstPad:src: caps = video/x-h264, width=(int)640, height=(int)480, parsed=(boolean)true, stream-format=(string)avc, alignment=(string)au, codec_data=(buffer)01640028ffe1000e27640028ac2b40501ed00f1226a001000528ee025cb0
/GstPipeline:pipeline0/GstRtpH264Pay:rtph264pay0.GstPad:src: caps = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, sprop-parameter-sets=(string)"J2QAKKwrQFAe0A8SJqA\=\,KO4CXLA\=", payload=(int)96, ssrc=(uint)2002636637, timestamp-offset=(uint)2547252088, seqnum-offset=(uint)28515
/GstPipeline:pipeline0/GstUDPSink:udpsink0.GstPad:sink: caps = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, sprop-parameter-sets=(string)"J2QAKKwrQFAe0A8SJqA\=\,KO4CXLA\=", payload=(int)96, ssrc=(uint)2002636637, timestamp-offset=(uint)2547252088, seqnum-offset=(uint)28515
/GstPipeline:pipeline0/GstRtpH264Pay:rtph264pay0.GstPad:sink: caps = video/x-h264, width=(int)640, height=(int)480, parsed=(boolean)true, stream-format=(string)avc, alignment=(string)au, codec_data=(buffer)01640028ffe1000e27640028ac2b40501ed00f1226a001000528ee025cb0
/GstPipeline:pipeline0/GstRtpH264Pay:rtph264pay0: timestamp = 2547252088
/GstPipeline:pipeline0/GstRtpH264Pay:rtph264pay0: seqnum = 28515


v=0
o=- 1208520720 2590316915 IN IP4 192.168.1.78
c=IN IP4 192.168.1.78
s=Gstreamer
m=video 1234 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 media=video; clock-rate=90000; encoding-name=H264; sprop-parameter-sets=J2QAKKwrQFAe0A8SJqA\=\,KO4CXLA\=
a=control:trackID=1


But the other solution that is supposed to fix the SPS junk is adding h264parse config-interval=1 Which is supposed to add the interval frames and force send the SPS frame..... does not work or is very buggy

sabretus
Posts: 2
Joined: Sun Nov 03, 2013 1:33 pm

Re: Using GStreamer as transcoder for Dreambox or TVheadend

Sun Nov 03, 2013 2:39 pm

Hello,

Should I have mpeg2 license key to run this ?

I'm getting next error

Code: Select all

or: X11 initialization failed.\n
ERROR: from element /GstPipeline:pipeline0/GstDecodeBin:demux/GstOMXMPEG2VideoDec-omxmpeg2videodec:omxmpeg2videodec-omxmpeg2videodec0: GStreamer error: negotiation problem.
Additional debug info:
gstvideodecoder.c(1983): gst_video_decoder_chain (): /GstPipeline:pipeline0/GstDecodeBin:demux/GstOMXMPEG2VideoDec-omxmpeg2videodec:omxmpeg2videodec-omxmpeg2videodec0:
encoder not initialized
Execution ended after 0:00:01.672252019
Setting pipeline to PAUSED ...
I have used http://www.trans-omni.co.uk/pi/GStreame ... _gstreamer to setup GStreamer.

SilentAl
Posts: 9
Joined: Tue Oct 29, 2013 6:24 pm

Re: Using GStreamer as transcoder for Dreambox or TVheadend

Sun Nov 03, 2013 4:42 pm

@sabretus
right, you are using omxmpeg2-hardware, here you need the MPEG2 licence.

manutoky
Posts: 5
Joined: Tue Jan 08, 2013 10:27 am

Re: Using GStreamer as transcoder for Dreambox or TVheadend

Sun Nov 03, 2013 8:58 pm

I tried some pipelines with a h264 stream from my DM800.
It didn't work, decodebin couldn't find a fitting decoder. Building a pipeline by hand didn't work either, omxh264dec and queue/multiqueue won't connect.

manutoky
Posts: 5
Joined: Tue Jan 08, 2013 10:27 am

Re: Using GStreamer as transcoder for Dreambox or TVheadend

Tue Nov 05, 2013 4:52 pm

My results so far for reference:
I'm able to transcode a mpeg2ts-stream from my dm800 into h264 with audio.
At least VLC shows the audio track but isn't playing anything. Anyone who knows why?

Code: Select all

gst-launch-1.0 souphttpsrc location="http://192.168.100.26:8001/1:0:1:DF:4:85:FFFF0000:0:0:0:" is-live=true ! tsdemux name=demux demux. ! queue ! mpegvideoparse ! omxmpeg2videodec ! queue ! omxh264enc ! h264parse ! matroskamux name=mux streamable=true ! tcpserversink host=192.168.100.37 port=5050 demux.audio_0300 ! queue ! mpegaudioparse ! mux. 
This is the visualized pipeline:
http://imgur.com/Yl7FDZ2

Update:
After switching to mpegtsmux there is audio, too.
Remaining problems are wrong aspect ratio (was okay with matroskamux) and selecting the correct audio channel.
SPS/PPS Problem ist still there, too. "config-interval=1" doesn't seem to work.
Is there a way for testing the number of audio channels and selecting the first? Or at least a way for printing out the available channels to the shell?
BTW, cpu load is between 50% and 60%.

Code: Select all

gst-launch-1.0 souphttpsrc location="http://dm800:8001/1:0:1:6DD1:44D:A401:FFFF0000:0:0:0:" is-live=true ! tsdemux name=demux demux. ! queue ! mpegvideoparse ! omxmpeg2videodec ! queue ! omxh264enc ! h264parse config-interval=1 ! mpegtsmux name=mux ! tcpserversink host=192.168.100.37 port=5050 demux. ! queue ! mpegaudioparse ! mux.


Pipeline:
http://imgur.com/ntQTM4Y

adrianc1982
Posts: 3
Joined: Mon Dec 30, 2013 6:58 am

Re: Using GStreamer as transcoder for Dreambox or TVheadend

Mon Dec 30, 2013 7:05 am

hello mstegmann, im a newbie with gstreamer and havent quite got the handle of how to formulate a proper pipe.

Could you help me rework your example:

gst-launch-1.0 souphttpsrc location="http://192.168.1.26:8001/1:0:1:6DCA:44D:1:C00000:0:0:0:" is-live=true ! decodebin name=demux demux. ! queue ! audioresample ! audioconvert dithering=0 ! "audio/x-raw,channels=1" ! flacenc ! mux. matroskamux name=mux streamable=true ! tcpserversink host=192.168.1.68 port=5000 demux. ! queue ! videoconvert ! omxh264enc target-bitrate=2000000 control-rate=variable ! "video/x-h264,profile=high" ! h264parse ! mux.

to publish this to an rtmp server(wowza)

Thanks in advance.

m][sko
Posts: 97
Joined: Fri Jul 20, 2012 6:37 am
Location: Slovakia

Re: Using GStreamer as transcoder for Dreambox or TVheadend

Thu Jan 30, 2014 3:21 pm

If you are still looking for solution for missing SPS/PPS
omxh264 encoder with more settings
http://pastebin.com/b5avcxpm

one of parameter inline-headers add sps/pss befour any IDR(k-frame)
and more

this fix solve problem with aspect ration changes
NAL
http://pastebin.com/JDbuGzyQ

my patch don't solve problem with missing aspect ratio in h264 SPS => in most players you will get 1:1

antmobilogy
Posts: 6
Joined: Wed Apr 16, 2014 2:37 am

Re: Using GStreamer as transcoder for Dreambox or TVheadend

Mon Jun 09, 2014 2:47 pm

Dear mstegmann,

I would want to use Gstreamer to stream YUV data from Raspberry Pi to another PC for processing. The following command would be the most suitable one for my application. But I will need to extract just the Y values only and left out U&V values.

I am new to Gstreamer. Would greatly appreciate someone can assist in solving my problem. Thanks in advance.

"gst-launch-0.10 v4l2src device=/dev/video0 ! 'video/x-raw-yuv,width=320,height=240,framerate=30/1' ! ffmpegcolorspace ! theoraenc quality=15 ! oggmux ! tcpserversink host=127.0.0.1 port=8080"

mstegmann wrote:Hey

I'm currently experimenting with GStreamer to develop a simple transcoder for live television. It took me all weekend, but I actually put together a nearly perfect working pipeline.

My configuration
- Raspberry Pi (265MB RAM)
- Dreambox 8000
- Raspian (latest)
- Gstreamer 1.0
- gst-omx (latest from git)

I know others have already tried similarly things, so I wanted to share my results with you.

Video without sound (good)

Code: Select all

gst-launch-1.0 souphttpsrc location="http://192.168.1.26:8001/1:0:1:6DCA:44D:1:C00000:0:0:0:" ! decodebin ! queue ! videoconvert ! omxh264enc ! video/x-h264,stream-format=byte-stream,profile=high ! h264parse ! mpegtsmux ! tcpserversink host=192.168.1.68 port=5000
Video with sound (bad)

Code: Select all

gst-launch-1.0 souphttpsrc location="http://192.168.1.26:8001/1:0:1:6DCA:44D:1:C00000:0:0:0:" ! decodebin name=demux demux. ! queue ! audioresample ! audioconvert ! "audio/x-raw,format=F32LE" ! vorbisenc ! mux. matroskamux name=mux ! tcpserversink host=192.168.1.68 port=5000 demux. ! queue ! videoconvert ! omxh264enc ! "video/x-h264,profile=high" ! h264parse ! mux.
Video with sound (raw audio)

Code: Select all

gst-launch-1.0 souphttpsrc location="http://192.168.1.26:8001/1:0:1:6DCA:44D:1:C00000:0:0:0:" is-live=true ! decodebin name=demux demux. ! queue ! audioresample ! mux. matroskamux name=mux streamable=true ! tcpserversink host=192.168.1.68 port=5000 demux. ! queue ! videoconvert ! omxh264enc target-bitrate=2000000 control-rate=variable ! "video/x-h264,profile=high" ! h264parse ! mux.
Video with sound (perfect)

Code: Select all

gst-launch-1.0 souphttpsrc location="http://192.168.1.26:8001/1:0:1:6DCA:44D:1:C00000:0:0:0:" is-live=true ! decodebin name=demux demux. ! queue ! audioresample ! audioconvert dithering=0 ! "audio/x-raw,channels=1" ! flacenc ! mux. matroskamux name=mux streamable=true ! tcpserversink host=192.168.1.68 port=5000 demux. ! queue ! videoconvert ! omxh264enc target-bitrate=2000000 control-rate=variable ! "video/x-h264,profile=high" ! h264parse ! mux.
Unfortunately, there are two problems I could not solve so far.

1. The SPS / PPS issue

The omxh264enc plugin sends not regularly the needed SPS / PPS information with it. You can work around the problem by immediately accessing the stream after the start of gst-launch, otherwise VLC (for example) cannot play it.

I have found this wrapper for the camera:
https://github.com/AndyA/psips

But I could not find any working solution for GStreamer. Apparently you can fix this usually by modifying h264parse, but I had so far no success in combination with omxh264enc.

2. The "wrong track" issue

I cannot find a way to specify which audio track decodebin should use. That is not specifically a problem with omxh264enc, but maybe someone has an idea.

At the moment, he apparently takes the last PCM track, which unfortunately sometimes is the track with audio description (for blind).

Maybe decodebin has simply too much automatism. My attempts to build the pipe together by hand had so far only generated very unstable video.

Code: Select all

gst-launch-1.0 souphttpsrc location="http://192.168.1.26:8001/1:0:1:6DCA:44D:1:C00000:0:0:0:" ! tsdemux ! queue max-size-buffers=0 max-size-time=0 ! mpegvideoparse ! mpeg2dec ! videoconvert ! omxh264enc ! video/x-h264,stream-format=byte-stream,profile=high ! h264parse ! mpegtsmux ! tcpserversink host=192.168.1.68 port=5000
It's just a first experiment, but if all goes well, I want to build a server around it. So far I am very satisfied, the transcoding works extremely stable and very smooth.

I would appreciate any suggestions for improvements and help with the issues :-)

Best Regards,
Marcel

xses
Posts: 5
Joined: Thu Jan 26, 2017 8:20 am

Re: Using GStreamer as transcoder for Dreambox or TVheadend

Sun Jan 29, 2017 10:09 am

Is the dev here still active? I would like to get some help maybe.

Return to “OpenMAX”

Who is online

Users browsing this forum: No registered users and 1 guest