Transcoding with Gstreamer (for Mortals)
Nov 21 2013
I work with video fairly regularly and a typical task due to various codec issues when working across different apps is transcoding. Historically I’ve been using mencoder and later ffmpeg, but they keep on changing the parameteres so often and due to our distro model of needing to update apps along with the OS and vice versa, it’s impossible for me to keep the transcopding scripts working over time. It reminds me of Imagemagick driving me mad for the same reasons.
I’ve been using Notes to store some common gstreamer pipelines, but perhaps some of these will be useful for mere mortals like me, so I’m sharing them with the world:
Transcoding image sequences (and cropping along the way)
#Sequence of JPEGs to h264:
gst-launch-1.0 qtmux name=mux ! filesink location=\"timelapse.mp4\" multifilesrc location=\"G%07d.JPG\" index=20376 caps=\"image/jpeg,framerate=\(fraction\)30/1\" ! jpegdec ! videoconvert ! videoscale ! video/x-raw,width=1920,height=1440 ! videocrop top=180 left=0 right=0 bottom=180 ! videorate ! x264enc bitrate=10000 ! mux.
#Sequence of PNGs to h264:
gst-launch-1.0 qtmux name=mux ! filesink location=\"timelapse.mp4\" file:///`pwd`/snd/foo.flac ! decodebin ! audioconvert ! avenc_aac ! mux. multifilesrc location=\"composite/%04d.png\" index=1 caps=\"image/png,framerate=\(fraction\)24/1\" ! pngdec ! videoconvert ! videoscale ! videorate ! x264enc threads=12 ! mux.
#PNG to Ogg Theora:
gst-launch-1.0 oggmux name=mux ! filesink location="timelapse.webm" file:///`pwd`/snd/foo.flac ! decodebin ! audioconvert ! vorbisenc ! mux. multifilesrc location="foo/%04d.png" index=1 caps="image/png,framerate=\(fraction\)25/1" ! pngdec ! videoconvert ! videorate ! theoraenc ! mux.
#PNG to WebM:
gst-launch-1.0 webmmux name=mux ! filesink location="timelapse.webm" file:///`pwd`/snd/foo.flac ! decodebin ! audioconvert ! vorbisenc ! mux. multifilesrc location="foo/%04d.png" index=1 caps="image/png,framerate=\(fraction\)25/1" ! pngdec ! videoconvert ! videoscale ! videorate ! vp8enc threads=4 ! mux.
Transcoding to image sequence
#webm to png:
gst-launch-1.0 filesrc location="input.webm" ! decodebin ! videoconvert ! pngenc ! multifilesink location="foo/%04d.png"