andyrblank
Posts: 8
Joined: Wed May 08, 2013 3:19 pm
Location: Rochester, NY
Contact: Website

Hardware Video Transcoding with Gstreamer in BASH script

Fri Feb 06, 2015 6:20 pm

Greetings and thank you for reading so far,

I'm having limited success with transcoding MPEG-2 transport streams (recorded by TVHeadend using a Hauppauge HVR1600 on another machine) to H264 with an MPEG-4 container using my Raspberry Pi (512MB Model B) with Gstreamer and FFMpeg.

For Reference:

I compiled ffmpeg from source as instructed here: http://sirlagz.net/2013/01/07/how-to-st ... pi-part-3/

I installed a pre-compiled gstreamer from here: http://theiopage.blogspot.com/2013/04/e ... -with.html

GPU/RAM spilt is 256/256

My problem:

Some recordings transcode just fine but others have audio/video sync issues later in the video. If I play the original transport stream in vlc it's synced just fine. I'm assuming the sync issue is due to transmission errors in the original file but since those types of things are going to happen I would like to know how to fix them but hopefully keep this process moving as quick as possible through the RPi.

Here's the meat of the code I'm using for this:

Code: Select all

#remove audio track from source and mux into mp4 container
/usr/local/bin/ffmpeg -i "$input" -vn -acodec copy -y "$WorkPath"/temp.m4a

#Transcode Video stream only to mp4 container
gst-launch-1.0 -e filesrc location="$input" \
        ! tsdemux \
        ! mpegvideoparse \
        ! omxmpeg2videodec \
        ! deinterlace \
        ! videoconvert \
        ! omxh264enc inline-header=true periodicty-idr=1 \
        ! "video/x-h264,stream-format=byte-stream,profile=high,control-rate=variable,target-bitrate=5000000,quant-i-frames=250" \
        ! h264parse \
        ! mp4mux ! filesink location="$WorkPath"/"temp.m4v"

#Mux Audio & Video Files
/usr/local/bin/ffmpeg -i "$WorkPath"/"temp.m4v" -i "$WorkPath"/"temp.m4a" -vcodec copy -map 0:0 -acodec copy -map 1:0 -shortest -y "$OutputPath"/"$OutputName"
I have tried having gstreamer handle both audio and video with limited success but I like the speed of copying the audio with ffmpeg that wasn't available with my limited knowledge of gstreamer.

-rst-
Posts: 1317
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: Hardware Video Transcoding with Gstreamer in BASH script

Tue Feb 17, 2015 2:50 pm

I wonder if this would reach better audience in the OpenMAX http://www.raspberrypi.org/forums/viewforum.php?f=70 subforum.
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

andyrblank
Posts: 8
Joined: Wed May 08, 2013 3:19 pm
Location: Rochester, NY
Contact: Website

Re: Hardware Video Transcoding with Gstreamer in BASH script

Tue Feb 17, 2015 2:56 pm

Thanks. Don't know how I missed that forum. I'll have to do some reading in there first to see if someone has already solved this.

andyrblank
Posts: 8
Joined: Wed May 08, 2013 3:19 pm
Location: Rochester, NY
Contact: Website

Re: Hardware Video Transcoding with Gstreamer in BASH script

Mon Feb 23, 2015 2:26 pm

Some issues with audio/video sync have been fixed by the script to build gstreamer 1.2 found here:

http://www.onepitwopi.com/raspberry-pi/ ... pberry-pi/

Return to “General programming discussion”