1

I'm using RPi2 with Raspbian. I'm trying to find best solution for transcoding .ts files from tvheadend. At the moment the best is using GStreamer because I can handle best performace. With GStreamer I can transcode 1 minute .ts FHD video file to .mkv 480x270 in 30 seconds which is in my opinion very good performance and I want to keep it.

But I have problem with Gstreamer to make conversion .ts to mkv (or .mp4) with audio. Important is that I have to have output video resized.

Here is example which is working but no audio:

gst-launch-1.0 -v filesrc location=1.ts ! tsdemux parse-private-sections=false name=demux ! queue ! ac3parse ! matroskamux name=stream streamable=true demux. ! queue ! h264parse ! omxh264dec ! omxh264enc target-bitrate=1572864 control-rate=variable ! video/x-h264,stream-format=byte-stream,profile=high,width=480,height=270,framerate=25/1 ! h264parse ! filesink location=1.mkv

Here is another example which working, this time with audio, but I can't resize video by changing omxh264enc parameters from example above:

gst-launch-1.0 filesrc location=1.ts ! decodebin name=demux demux. ! queue ! audioresample ! "audio/x-raw,rate=44100" ! audioconvert ! "audio/x-raw,format=F32LE" ! vorbisenc ! mux. matroskamux name=mux ! filesink location=1.mkv demux. ! queue ! videoconvert ! omxh264enc ! "video/x-h264,profile=high" ! h264parse ! mux.

How to fix these command above to have audio in video files from GStreamer?

2 Answers 2

1

Ok, finally I have two options for converting .ts file.

First option is with audio conversion:

gst-launch-1.0 filesrc location=1.ts \
! tsdemux parse-private-sections=false name=demux \
! queue max-size-buffers=0 max-size-time=0 \
! mpegaudioparse \
! mpg123audiodec \
! audioconvert dithering=0 \
! audio/x-raw,channels=2 \
! avenc_aac compliance=-2 bitrate=65536 \
! matroskamux name=stream \
! queue max-size-buffers=0 max-size-time=0 \
! filesink location=1.mkv demux. \
! queue max-size-buffers=0 max-size-time=0 \
! h264parse \
! omxh264dec \
! omxh264enc target-bitrate=900000 control-rate=variable \
! video/x-h264,stream-format=byte-stream,profile=high,width=576,height=324,framerate=25/1 \
! h264parse \
! stream.

Second option is with audio pass no conversion:

gst-launch-1.0 filesrc location=1.ts \
! tsdemux parse-private-sections=false name=demux \
! queue max-size-buffers=0 max-size-time=0 \
! ac3parse \
! matroskamux name=stream \
! queue max-size-buffers=0 max-size-time=0 \
! filesink location=1.mkv demux. \
! queue max-size-buffers=0 max-size-time=0 \
! h264parse \
! omxh264dec \
! omxh264enc target-bitrate=900000 control-rate=variable \
! video/x-h264,stream-format=byte-stream,profile=high,width=576,height=324,framerate=25/1 \
! h264parse \
! stream.

Better results are with first option because output file is smaller and conversion is about 10% faster. Also with this option overall CPU performance is little bigger compare to second option and equals about 25% on RPi2.

1
  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year.
    – Ingo
    Commented Dec 27, 2019 at 22:43
0

You build your pipeline wrong. This is not what you wanted to archive. In particular you don't do anything with with the ac3 muxed audio. And the video is written to disk as H.264 elementary stream. Just because you named it .mkv doesn't mean it is a MKV file.

You need to feed both media to the muxer and write that result to disk. Something like this:

gst-launch-1.0 -v filesrc location=1.ts ! tsdemux parse-private-sections=false name=demux ! queue ! ac3parse ! matroskamux name=stream streamable=true ! filesink location=1.mkv demux. ! queue ! h264parse ! omxh264dec ! omxh264enc target-bitrate=1572864 control-rate=variable ! video/x-h264,stream-format=byte-stream,profile=high,width=480,height=270,framerate=25/1 ! h264parse ! stream.

4
  • Thanks Florian. With your command GStreamer making just small 1.mkv file and stops - I mean amount of data in 1.mkv doesn't increase.
    – fufu2000
    Commented Oct 19, 2017 at 19:25
  • It may be due to the encoding process needs more frames for lookahead. This may cause the pipeline to stall at prerolling stage. Try increasing the queue sizes in the pipeline. For testing maybe increase all three properties (size, time, num) of all queue to very large numbers. Commented Oct 20, 2017 at 8:08
  • Thanks Florian for suggestion! After few days is progress and is working !!!! :) I've changed all queue to queue2 and conversion works with audio! Also I've removed streamable=true to have end time in 1.mkv file. But... I don't know this queue to queue2 is right - I mean is this good syntax of GStreamer with my all coversion example?
    – fufu2000
    Commented Oct 20, 2017 at 9:44
  • After few tests I see, that instead queue2 is better to put queue max-size-buffers=0 max-size-time=0.
    – fufu2000
    Commented Oct 20, 2017 at 16:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.