{"id":1994,"date":"2025-03-14T20:07:37","date_gmt":"2025-03-14T18:07:37","guid":{"rendered":"https:\/\/www.phreekz.de\/wordpress\/?p=1994"},"modified":"2025-03-15T15:14:57","modified_gmt":"2025-03-15T13:14:57","slug":"gstreamer-examples","status":"publish","type":"post","link":"https:\/\/www.phreekz.de\/wordpress\/2025\/03\/gstreamer-examples\/","title":{"rendered":"gstreamer examples"},"content":{"rendered":"\n<p class=\"has-purple-background-color has-background\">before you move on, please check, that this first example works. link a mediafile with video and audio. doublecheck your uri!<\/p>\n\n\n\n<p>copy the sourcecode into a .sh (or .bat) file.<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:10px\"><code>SRCA=\"file:\/\/\/c:\/msys64\/home\/01_clock.mp4\"\n\ngst-launch-1.0 \\\n  uridecodebin uri=$SRCA name=media \\\n  \\\n  media. ! queue ! videoconvert ! queue ! autovideosink \\\n  media. ! queue ! audioconvert ! audioresample ! queue ! autoaudiosink\n<\/code><\/pre>\n\n\n\n<p>the code above works in <mark style=\"background-color:#D1DFE4\" class=\"has-inline-color\">linux<\/mark> as the variable and linebreaks are written that way, in <mark style=\"background-color:#D1DFE4\" class=\"has-inline-color\">windows<\/mark> you have to use set, %% and ^. <\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:10px\"><code>set SRCA=\"file:\/\/\/c:\/msys64\/home\/01_clock.mp4\"\n\ngst-launch-1.0 uridecodebin uri=%SRCA% name=media^\n media. ! queue ! videoconvert ! queue ! autovideosink^\n media. ! queue ! audioconvert ! audioresample ! queue ! autoaudiosink\n<\/code><\/pre>\n\n\n\n<p class=\"has-purple-background-color has-background\">a <mark style=\"background-color:#D1DFE4\" class=\"has-inline-color\">compositor<\/mark> example with a background image, 2 videostreams and a logo. no audio.<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:10px\"><code>SRCA=\"file:\/\/\/c:\/msys64\/home\/01_clock.mp4\"\nSRCB=\"file:\/\/\/c:\/msys64\/home\/02_lakme.mkv\"\nSRCBG=\"file:\/\/\/c:\/msys64\/home\/bg_blue.png\"\nSRCLogo=\"file:\/\/\/c:\/msys64\/home\/logo.png\"\n\nGST_DEBUG=2 gst-launch-1.0 compositor name=comp \\\n  sink_0::alpha=1.0 sink_0::xpos=0    sink_0::ypos=0   sink_0::width=960 sink_0::height=540 \\\n  sink_1::alpha=0.5 sink_1::xpos=0    sink_1::ypos=0   sink_1::width=960 sink_1::height=540 \\\n  sink_2::alpha=1.0 sink_2::xpos=600  sink_2::ypos=320   sink_2::width=320 sink_2::height=180 \\\n  sink_3::alpha=1.0 sink_3::xpos=890  sink_3::ypos=10   sink_3::width=60 sink_3::height=60 \\\n  ! videoscale ! video\/x-raw,width=960,height=540 ! videoconvert ! autovideosink \\\n  uridecodebin uri=$SRCBG ! queue ! videoscale ! video\/x-raw,width=960,height=540 ! imagefreeze ! comp.sink_0 \\\n  uridecodebin uri=$SRCA ! queue ! videoscale ! video\/x-raw,width=960,height=540 ! videoconvert ! queue ! comp.sink_1 \\\n  uridecodebin uri=$SRCB ! queue ! videoscale ! video\/x-raw,width=320,height=180 ! videoconvert ! queue ! comp.sink_2 \\\n  uridecodebin uri=$SRCLogo ! queue ! videoscale ! video\/x-raw,width=60,height=60 ! imagefreeze ! comp.sink_3 \\\n\n   <\/code><\/pre>\n\n\n\n<p class=\"has-extra-small-font-size\">if errors occur, check the file-uri, change the <em>GST_DEBUG to 3<\/em> and look for <em>file not found<\/em> or <em>could not open<\/em>. look for media-resolutions. these examples where built and tested under windows 11 mingw64. <\/p>\n\n\n\n<p class=\"has-purple-background-color has-background\">this is the same compositor example but <mark style=\"background-color:#D1DFE4\" class=\"has-inline-color\">filled with named pad-links<\/mark> and, for readabilty, empty lines  <\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:10px\"><code>GST_DEBUG=2 \\\ngst-launch-1.0 \\\n  compositor name=comp \\\n  sink_0::alpha=1.0 sink_0::xpos=0    sink_0::ypos=0   sink_0::width=960 sink_0::height=540 \\\n  sink_1::alpha=0.5 sink_1::xpos=0    sink_1::ypos=0   sink_1::width=960 sink_1::height=540 \\\n  sink_2::alpha=1.0 sink_2::xpos=600  sink_2::ypos=320   sink_2::width=320 sink_2::height=180 \\\n  sink_3::alpha=1.0 sink_3::xpos=890  sink_3::ypos=10   sink_3::width=60 sink_3::height=60 \\\n  ! videoscale ! video\/x-raw,width=960,height=540 ! videoconvert ! mux_out. \\\n  \\\n  uridecodebin uri=$SRCA name=videoA \\\n  uridecodebin uri=$SRCB name=videoB \\\n  \\\n  uridecodebin uri=$SRCBG ! queue ! videoscale ! video\/x-raw,width=960,height=540 ! imagefreeze ! comp.sink_0 \\\n  videoA. ! queue ! videoscale ! video\/x-raw,width=960,height=540 ! videoconvert ! queue ! comp.sink_1 \\\n  videoB. ! queue ! videoscale ! video\/x-raw,width=320,height=180 ! videoconvert ! queue ! comp.sink_2 \\\n  uridecodebin uri=$SRCLogo ! queue ! videoscale ! video\/x-raw,width=60,height=60 ! imagefreeze ! comp.sink_3 \\\n  \\\n  autovideosink name=mux_out<\/code><\/pre>\n\n\n\n<p class=\"has-purple-background-color has-background\">we re adding audio of one of the videos<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:10px\"><code>SRCA=\"file:\/\/\/c:\/msys64\/home\/01_clock.mp4\"\nSRCB=\"file:\/\/\/c:\/msys64\/home\/02_lakme.mkv\"\nSRCBG=\"file:\/\/\/c:\/msys64\/home\/bg_blue.png\"\nSRCLogo=\"file:\/\/\/c:\/msys64\/home\/logo.png\"\n\nGST_DEBUG=2 \\\ngst-launch-1.0 \\\n  compositor name=comp \\\n  sink_0::alpha=1.0 sink_0::xpos=0    sink_0::ypos=0   sink_0::width=960 sink_0::height=540 \\\n  sink_1::alpha=0.5 sink_1::xpos=0    sink_1::ypos=0   sink_1::width=960 sink_1::height=540 \\\n  sink_2::alpha=1.0 sink_2::xpos=600  sink_2::ypos=320   sink_2::width=320 sink_2::height=180 \\\n  sink_3::alpha=1.0 sink_3::xpos=890  sink_3::ypos=10   sink_3::width=60 sink_3::height=60 \\\n  ! videoscale ! video\/x-raw,width=960,height=540 ! videoconvert ! mux_out. \\\n  \\\n  uridecodebin uri=$SRCA name=videoA \\\n  uridecodebin uri=$SRCB name=videoB \\\n  \\\n  uridecodebin uri=$SRCBG ! queue ! videoscale ! video\/x-raw,width=960,height=540 ! imagefreeze ! comp.sink_0 \\\n  videoA. ! queue ! videoscale ! video\/x-raw,width=960,height=540 ! videoconvert ! queue ! comp.sink_1 \\\n  videoB. ! queue ! videoscale ! video\/x-raw,width=320,height=180 ! videoconvert ! queue ! comp.sink_2 \\\n  uridecodebin uri=$SRCLogo ! queue ! videoscale ! video\/x-raw,width=60,height=60 ! imagefreeze ! comp.sink_3 \\\n  \\\n  videoB. ! queue ! audioconvert ! audioresample ! queue ! autoaudiosink \\\n  \\\n  autovideosink name=mux_out\n   <\/code><\/pre>\n\n\n\n<p class=\"has-purple-background-color has-background\">time to test saving muxed audio and video into a file. stop the encoding with CTRL+C, ensuring the file will be finalized accordingly. look out if the nv264enc encoder works for you<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:10px\"><code>SRCA=\"file:\/\/\/c:\/msys64\/home\/01_clock.mp4\"\nSRCB=\"file:\/\/\/c:\/msys64\/home\/02_lakme.mkv\"\nSRCBG=\"file:\/\/\/c:\/msys64\/home\/bg_blue.png\"\nSRCLogo=\"file:\/\/\/c:\/msys64\/home\/logo.png\"\n\nSRCSave=\"example.mkv\"\n\nGST_DEBUG=2 \\\ngst-launch-1.0 -e \\\n  compositor name=comp \\\n  sink_0::alpha=1.0 sink_0::xpos=0    sink_0::ypos=0   sink_0::width=960 sink_0::height=540 \\\n  sink_1::alpha=0.5 sink_1::xpos=0    sink_1::ypos=0   sink_1::width=960 sink_1::height=540 \\\n  sink_2::alpha=1.0 sink_2::xpos=600  sink_2::ypos=320   sink_2::width=320 sink_2::height=180 \\\n  sink_3::alpha=1.0 sink_3::xpos=890  sink_3::ypos=10   sink_3::width=60 sink_3::height=60 \\\n  ! videoscale ! video\/x-raw,width=960,height=540,framerate=25\/1 ! videoconvert ! enc_video. \\\n  \\\n  uridecodebin uri=$SRCA name=videoA \\\n  uridecodebin uri=$SRCB name=videoB \\\n  \\\n  uridecodebin uri=$SRCBG ! queue ! videoscale ! video\/x-raw,width=960,height=540 ! imagefreeze ! comp.sink_0 \\\n  videoA. ! queue ! videoconvert ! videoscale ! video\/x-raw,width=960,height=540 ! videoconvert ! queue ! comp.sink_1 \\\n  videoB. ! queue ! videoscale ! video\/x-raw,width=320,height=180 ! videoconvert ! queue ! comp.sink_2 \\\n  uridecodebin uri=$SRCLogo ! queue ! videoscale ! video\/x-raw,width=60,height=60 ! imagefreeze ! comp.sink_3 \\\n  \\\n  videoB. ! queue ! audioconvert ! audioresample ! faac ! queue ! mux_out. \\\n  nvh264enc name=enc_video bitrate=1200 ! h264parse ! queue ! mux_out. \\\n  \\\n  matroskamux name=mux_out ! filesink location=$SRCSave\n<\/code><\/pre>\n\n\n\n<p class=\"has-purple-background-color has-background\">finally, a rtsp stream with video and audio. <\/p>\n\n\n\n<p>in this example sending the stream to mediamtx as a stream-server-distributor (you have to install rtspclientserver as its not in the standard packages and of course mediamtx). for webrtc streams you need to change the <em>faac<\/em> encoder to <em>opusenc<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:10px\"><code>SRCA=\"file:\/\/\/c:\/msys64\/home\/01_clock.mp4\"\nSRCB=\"file:\/\/\/c:\/msys64\/home\/02_lakme.mkv\"\nSRCBG=\"file:\/\/\/c:\/msys64\/home\/bg_blue.png\"\nSRCLogo=\"file:\/\/\/c:\/msys64\/home\/logo.png\"\n\nRTSPURL=\"rtsp:\/\/192.168.2.6:8554\/mystream\"\n\nGST_DEBUG=2 \\\ngst-launch-1.0 -e \\\n  compositor name=comp \\\n  sink_0::alpha=1.0 sink_0::xpos=0    sink_0::ypos=0   sink_0::width=960 sink_0::height=540 \\\n  sink_1::alpha=0.5 sink_1::xpos=0    sink_1::ypos=0   sink_1::width=960 sink_1::height=540 \\\n  sink_2::alpha=1.0 sink_2::xpos=600  sink_2::ypos=320   sink_2::width=320 sink_2::height=180 \\\n  sink_3::alpha=1.0 sink_3::xpos=890  sink_3::ypos=10   sink_3::width=60 sink_3::height=60 \\\n  ! videoscale ! video\/x-raw,width=960,height=540,framerate=25\/1 ! videoconvert ! enc_video. \\\n  \\\n  uridecodebin uri=$SRCA name=videoA \\\n  uridecodebin uri=$SRCB name=videoB \\\n  \\\n  uridecodebin uri=$SRCBG ! queue ! videoscale ! video\/x-raw,width=960,height=540 ! imagefreeze ! comp.sink_0 \\\n  videoA. ! queue ! videoconvert ! videoscale ! video\/x-raw,width=960,height=540 ! videoconvert ! queue ! comp.sink_1 \\\n  videoB. ! queue ! videoscale ! video\/x-raw,width=320,height=180 ! videoconvert ! queue ! comp.sink_2 \\\n  uridecodebin uri=$SRCLogo ! queue ! videoscale ! video\/x-raw,width=60,height=60 ! imagefreeze ! comp.sink_3 \\\n  \\\n  videoB. ! queue ! audioconvert ! audioresample ! faac ! queue ! stream.sink_1 \\\n  nvh264enc name=enc_video bitrate=1200 ! queue ! stream.sink_0 \\\n  \\\n  rtspclientsink name=stream location=$RTSPURL \n   \n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>before you move on, please check, that this first example works. link a mediafile with video and audio. doublecheck your uri! copy the sourcecode into a .sh (or .bat) file. the code above works in linux as the variable and linebreaks are written that way, in windows you have to use set, %% and ^.&hellip; <a class=\"more-link\" href=\"https:\/\/www.phreekz.de\/wordpress\/2025\/03\/gstreamer-examples\/\"><span class=\"screen-reader-text\">gstreamer examples<\/span> weiterlesen<\/a><\/p>\n","protected":false},"author":1,"featured_media":1995,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29,7],"tags":[110,431,121],"class_list":["post-1994","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pc-leben-und-leiden","category-video-graphics","tag-coding","tag-gstreamer","tag-video","entry"],"_links":{"self":[{"href":"https:\/\/www.phreekz.de\/wordpress\/wp-json\/wp\/v2\/posts\/1994","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.phreekz.de\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phreekz.de\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phreekz.de\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phreekz.de\/wordpress\/wp-json\/wp\/v2\/comments?post=1994"}],"version-history":[{"count":12,"href":"https:\/\/www.phreekz.de\/wordpress\/wp-json\/wp\/v2\/posts\/1994\/revisions"}],"predecessor-version":[{"id":2009,"href":"https:\/\/www.phreekz.de\/wordpress\/wp-json\/wp\/v2\/posts\/1994\/revisions\/2009"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.phreekz.de\/wordpress\/wp-json\/wp\/v2\/media\/1995"}],"wp:attachment":[{"href":"https:\/\/www.phreekz.de\/wordpress\/wp-json\/wp\/v2\/media?parent=1994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phreekz.de\/wordpress\/wp-json\/wp\/v2\/categories?post=1994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phreekz.de\/wordpress\/wp-json\/wp\/v2\/tags?post=1994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}