Gstreamer /ffmpeg /etc examples
playing raw video
DISPLAY=:0.0 ffplay -pixel_format yuv420p -video_size 720x576 -framerate 25 -f rawvideo ffmpeg-2013-09-27.12.45.20-video.raw
videoloopback
apt-get install v4l2loopback-dkms
#parm: debug:if debug output is enabled, values are 0, 1 or 2 (int)
#parm: max_buffers:how many buffers should be allocated (int)
#parm: max_openers:how many users can open loopback device (int)
#parm: devices:how many devices should be created (int)
modprobe v4l2loopback devices=2
v4l2-ctl -d /dev/video0 -i 0 -s pal
GST_DEBUG=2 /usr/bin/gst-launch-0.10 v4l2src device=/dev/video0 ! queue ! tee name=flapperdeflapper pull-mode=1 ! queue ! videoscale ! "video/x-raw-yuv, width=720, height=576" ! v4l2loopback device=/dev/video1 flapperdeflapper. ! queue ! v4l2loopback device=/dev/video2
gstreamer > ffmpeg > dvswitch , the -q is important, because gstreamer sends its stderr to stdout
gst-launch-0.10 -q videotestsrc ! x264enc ! flvmux ! filesink location="/dev/stdout" | ffmpeg -f flv -i "/dev/stdin" -target ntsc-dv -aspect 4:3 -y - | dvsource-file -h 172.31.10.28 -p 9090 /dev/stdin
Gstreamer > ?http://cgit.freedesktop.org/gstreamer/gst-rtsp-server/ > http://dvswitch.alioth.debian.org/wiki/
gst-rtsp-server/examples/test-launch "( videotestsrc is-live=true ! ffenc_dvvideo ! rtpdvpay name=pay0 pt=96 mode=1 )"
dvcam to icecast: http://giss.tv/wiki/images/f/fd/Dvstream.pys
rtmp testsrc
ffmpeg -f alsa -i hw:0,0 -f video4linux2 -s 200x100 -i /dev/video0 -r 15 -v:c 3 -vcodec libx264 -vpre ultrafast -threads 2 -ar 44100 -acodec libmp3lame -ab 96k -f flv rtmp://172.31.10.1/live/test
gst-launch -v videotestsrc is-live=true ! queue ! x264enc ! queue ! \
queue ! flvmux streamable=true name=mux ! queue ! rtmpsink qos=true location=rtmp://172.31.10.1/live/test \
audiotestsrc is-live=true ! audio/x-raw,rate=44100 ! audioconvert ! mux.
raspberry stream to udp with mpegts
gst-launch-1.0 -v videotestsrc is-live=true ! queue ! omxh264enc ! queue ! h264parse ! queue ! mpegtsmux name=mux mux. ! udpsink host=172.31.10.28 port=5000 sync=false enable-last-sample=false
recieve udp stream with mpegts
gst-launch-0.10 udpsrc port=5000 ! tsdemux ! "video/x-h264" ! ffdec_h264 ! "video/x-raw-yuv" ! xvimagesink sync=false
alssrc to udp with opus encoding
gst-launch-0.10 alsasrc ! audioconvert ! audioresample ! opusenc ! \
audio/x-opus,channels=1,depth=32,width=32,rate=48000 ! rtpopuspay ! \
gstrtpbin ! udpsink host=$HOST port=$PORT
udp to alsaink with opusencoding
gst-launch-1.0 udpsrc port=$PORT ! queue leaky=downstream max-size-buffers=$BUFFER_SIZE !\
"application/x-rtp,media=(string)audio, channels=1,depth=32,width=32, clock-rate=(int)48000,\ payload=96, encoding-name=X-GST-OPUS-DRAFT-SPITTKA-00" ! \
queue leaky=downstream max-size-buffers=$BUFFER_SIZE ! rtpbin ! rtpopusdepay !\
opusdec ! audioconvert ! audioresample ! alsasink
v4l device to rtmp on a raspberry
gst-launch-1.0 -v v4l2src ! video/x-raw,framerate=20/1 ! queue ! omxh264enc ! queue ! \
h264parse ! queue ! flvmux name=mux ! queue ! rtmpsink location=rtmp://flu.v89.eu/live/raspi \
audiotestsrc is-live=true ! audio/x-raw,rate=44100 ! audioconvert ! mux.
dv to rtmp
dvgrab -noavc - | ffmpeg -i - -vcodec libx264 -r 25 -vb 800k -threads 8 -acodec libmp3lame -ar 44100 -ab 256k -f flv 'rtmp://flu.v89.eu/live/pinknoise?password=vetgeheim'
multicast rtp stream reciever
gst-launch-0.10 udpsrc uri=udp://239.1.2.3:5000 auto-multicast=true ! \
"application/x-rtp, media=(string)video, clock-rate=(int)90000, \
encoding-name=(string)H264, \
sprop-parameter-sets=(string)\"Z0LAFdkBQfsBEAAAAwAXc1lAAPFi5IAA\\,aMuMsg\\=\\=\", \
payload=(int)96, ssrc=(uint)1518631250, \
clock-base=(uint)3277128407, seqnum-base=(uint)64715" \
! gstrtpbin ! rtph264depay ! decodebin ! xvimagesink
multicast rtp stream transmitter
gst-launch-0.10 -v videotestsrc is-live=true \
! x264enc ! rtph264pay ! gstrtpbin \
! udpsink host=239.1.2.3 port=5000 auto-multicast=true
making titles with gstreamer
MIXERFORMAT="video/x-raw-rgb, bpp=(int)32, depth=(int)32, endianness=(int)4321,\
red_mask=(int)65280, green_mask=(int)16711680, blue_mask=(int)-16777216, \
width=(int)720, height=(int)576, framerate=(fraction)1/1, \
pixel-aspect-ratio=(fraction)1/1, interlaced=(boolean)false"
gst-launch videotestsrc pattern=10 is-live=true ! \
textoverlay text="FEED $1 is DEAD!" \
shadow=true shaded-background=true auto-resize=true\
font-desc="serif,monospace bold italic condensed 36" \
valignment=4 ! $MIXERFORMAT ! multifilesink location=dead-$1.rgba
video +jack audio naar icecast
ffmpeg -f video4linux2 -i /dev/video0 \
-f jack -i libav -acodec libvorbis -ab 64k -vcodec \
libtheora -vb 100k -s 288x216 -f ogg - | \
oggfwd localhost 8000 hackme /test.ogg
file naar rtmp
gst-launch filesrc location=/home/hark/movies/test.ogv ! \
decodebin name=demux ! queue ! videorate ! videoscale method=0 \
! video/x-raw-yuv,width=852,height=480,framerate=\(fraction\)24/1 \
! ffmpegcolorspace ! x264enc pass=pass1 threads=0 bitrate=900 \
tune=zerolatency ! flvmux name=mux streamable=true ! \
rtmpsink location='rtmp://172.31.10.1/live/test' demux. \
! queue ! progressreport ! audioconvert ! audiorate !\
audioresample ! lamemp3enc ! mux.
</code>
#mpegts multicast > rtmp
<code>
ffmpeg -i /home/hark/src/cpu/rtmp/mcast.sdp \
-vcodec libx264 -r 25 -qscale 3 -preset ultrafast -vb 600k -acodec libmp3lame -ar 44100 -ab 256k -f flv 'rtmp://flu.v89.eu/live/pinknoise?password=vetgeheim'
rtp send
gst-launch-0.10 -v gstrtpbin name=rtpbin\
videotestsrc ! jpegenc idct-method=2 quality=100 !\
'image/jpeg, width=(int)720, height=(int)576, framerate=(fraction)25/1' !\
rtpjpegpay ssrc=9996 timestamp-offset=0 seqnum-offset=0 ! rtpbin.send_rtp_sink_0\
rtpbin.send_rtp_src_0 ! multiudpsink clients="127.0.0.1:9996"\
rtpbin.send_rtcp_src_0 ! multiudpsink clients="127.0.0.1:9997" sync=false async=false\
udpsrc port=10000 ! rtpbin.recv_rtcp_sink_0\
audiotestsrc ! audioconvert !\
'audio/x-raw-int, rate=(int)44100, channels=(int)2' !\
rtpL16pay ssrc=9998 timestamp-offset=0 seqnum-offset=0 ! rtpbin.send_rtp_sink_1\
rtpbin.send_rtp_src_1 ! multiudpsink clients="127.0.0.1:9998"\
rtpbin.send_rtcp_src_1 ! multiudpsink clients="127.0.0.1:9999" sync=false async=false\
udpsrc port=10001 ! rtpbin.recv_rtcp_sink_1
rtp recvA
gst-launch-0.10 -v gstrtpbin name=rtpbin\
udpsrc caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)JPEG, ssrc=(guint)469657143, payload=(int)96, clock-base=(guint)2841649723, seqnum-base=(guint)39869" port=9996 !\
rtpbin.recv_rtp_sink_0 \
rtpbin. ! rtpjpegdepay !\
jpegdec ! xvimagesink\
udpsrc port=9997 ! rtpbin.recv_rtcp_sink_0\
rtpbin.send_rtcp_src_0 ! multiudpsink clients="127.0.0.1:10000" sync=false async=false\
udpsrc caps="application/x-rtp, media=(string)audio, clock-rate=(int)44100, encoding-name=(string)L16, encoding-params=(string)2, channels=(int)2, ssrc=(guint)469657143, payload=(int)96, clock-base=(guint)2841649723, seqnum-base=(guint)39869" port=9998 !\
rtpbin.recv_rtp_sink_1 \
rtpbin. ! rtpL16depay !\
autoaudiosink\
udpsrc port=9999 ! rtpbin.recv_rtcp_sink_1\
rtpbin.send_rtcp_src_1 ! multiudpsink clients="127.0.0.1:10001" sync=false async=false
mpegts rtp
nice --15 gst-launch-0.10 -v \
$SRC ! \
$MIXERFORMAT ! \
queue ! \
ffmpegcolorspace ! \
queue ! \
videobox top=0 left=0 right=720 bottom=424 ! \
queue ! timeoverlay ! \
x264enc speed-preset=ultrafast quantizer=0 ! queue ! \
mpegtsmux name=mux ! queue ! rtpmp2tpay pt=33 ! \
udpsink port=5004 host=239.1.2.3 sync=false enable-last-buffer=false auto-multicast=true ttl-mc=16 \
jackaudiosrc client-name=icecast-theora port-pattern=master/out provide-clock=true ! level ! queue !\
audioconvert ! queue ! lamemp3enc bitrate=320 ! queue ! mux. \
Getting stuff in and out dvswitch:
#rtmp output
dvsink-command -h 172.31.123.31 -p 2323 cat | ffmpeg -i - -vcodec libx264 -preset veryfast -acodec libmp3lame -b:a 96k -ar 44100 -f flv rtmp://flu.v89.eu/live/pinknoise
#loop a file
#!/bin/bash
while <span class="createlink"><a href="/ikiwiki.cgi?do=create&from=software%2Fpipelines&page=_true_" rel="nofollow">?</a> true </span> ; do
ffmpeg -i $1 -target pal-dv - | dvsource-file -h 172.31.123.31 -p 2323 /dev/stdin ;
sleep 2
done
#rtmp input#!/bin/bash
while <span class="createlink"><a href="/ikiwiki.cgi?do=create&from=software%2Fpipelines&page=_true_" rel="nofollow">?</a> true </span> ; do
sleep 1
ffmpeg -i rtmp://flu.v89.eu/live/$1 -target pal-dv - | dvsource-file -h 172.31.123.31 -p 2323 /dev/stdin ; done
# rtmp to icecast
ffmpeg -i rtmp://flu.v89.eu/live/pinknoise -acodec vorbis -strict -2 -vcodec theora -threads 6 -f ogg - | oggfwd
deathstar.puscii.nl 8000 icecold /pinknoise.ogv
dvswitch > ffmpeg > rtmp
<code>
dvsink-command -h 172.31.123.31 -p 2323 cat | nice -n -20 ffmpeg -i - \
-vcodec libx264 -crf 25 -preset veryfast -b:v 400k -vf scale=-1:480 \
-acod44100 -f flv rtmp://flu.v89.eu/live/pinknoise