{"id":23,"date":"2011-01-25T23:18:53","date_gmt":"2011-01-25T23:18:53","guid":{"rendered":"http:\/\/www.vidarholen.net\/contents\/blog\/?p=23"},"modified":"2011-03-22T12:47:04","modified_gmt":"2011-03-22T12:47:04","slug":"mp3-to-video-using-gstreamer-visualizations","status":"publish","type":"post","link":"https:\/\/www.vidarholen.net\/contents\/blog\/?p=23","title":{"rendered":"MP3 to Video using GStreamer visualizations"},"content":{"rendered":"<p><a href=\"\/imgs\/blog\/visualization.jpg\"><img decoding=\"async\" class=\"alignleft\" src=\"\/imgs\/blog\/visualization-small.jpg\" alt=\"VLC showing a sparkly shiny visualization\" \/><\/a><br \/>\nEveryone loves music visualization, but not all apps support it in a sensible way. Maybe you want to shuffle a random assortment of video and audio files in a player that doesn&#8217;t handle that well (VLC!), or not at all (mplayer!). Or maybe you want to upload something to youtube, with gorgeous HD visualizations instead of that lame static cover art image?<\/p>\n<p>The few google results on the topic that weren&#8217;t spam suggested screencapping software. Yeah, that&#8217;s great&#8230; until you have more than two files.<\/p>\n<p><a href=\"\/contents\/blog\/?p=6\">Once<\/a> <a href=\"\/contents\/blog\/?p=5\">again<\/a>, everyone&#8217;s favourite multimedia swiss army knife \u2013 GStreamer \u2013 steps up to the plate.<\/p>\n<p>Here&#8217;s an example of encoding an MP3 to an H.264 .mkv file using the gorgeous goom visualizer (requires the mp3 and x264 plugins for gstreamer):<\/p>\n<p><code><br \/>\ngst-launch filesrc location=input.mp3 ! queue ! tee name=stream ! queue ! mp3parse ! matroskamux name=mux ! filesink location=\"output.mkv\" stream. ! queue ! mp3parse ! mad ! audioconvert ! queue ! goom ! ffmpegcolorspace ! video\/x-raw-yuv,width=1280,height=720 ! x264enc ! mux.<br \/>\n<\/code><\/p>\n<p>It&#8217;s beautiful \u2013 and the video is pretty sweet as well.<\/p>\n<p>It&#8217;s worth noting that this approach does not re-encode the MP3, like some less awesome approaches would do (causing loss of quality). It simply muxes it together with the visualizer&#8217;s video stream. x264 even seems to distribute itself well across cores.<\/p>\n<p>No, wait, what? MP3 and H.264? Of course, I meant Vorbis and Theora! Let me rephrase:<\/p>\n<p><code><br \/>\ngst-launch filesrc location=input.ogg ! queue ! tee name=stream ! queue ! oggdemux ! vorbisparse !  oggmux name=mux ! filesink location=\"output.ogg\" stream. ! queue ! oggdemux ! vorbisdec ! audioconvert ! queue ! goom ! ffmpegcolorspace ! video\/x-raw-yuv,width=1920,height=1080 ! theoraenc ! mux.<br \/>\n<\/code><\/p>\n<p>The same goodness applies, except for the parallelism. If you have a multicore CPU, there&#8217;s massive speedup to be had through simple shell script based <a href=\"\/contents\/blog\/?p=9\">multithreading<\/a>.  (Why full HD this time? VLC on Windows crashes on 720p Theora!)<\/p>\n<p>And there you have it. A simple, hack-free, modular and flexible way of encoding visualization videos for MP3 and Ogg Vorbis files. Thanks, GStreamer!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Everyone loves music visualization, but not all apps support it in a sensible way. Maybe you want to shuffle a random assortment of video and audio files in a player that doesn&#8217;t handle that well (VLC!), or not at all (mplayer!). Or maybe you want to upload something to youtube, with gorgeous HD visualizations instead &hellip; <a href=\"https:\/\/www.vidarholen.net\/contents\/blog\/?p=23\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;MP3 to Video using GStreamer visualizations&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[5,4],"tags":[14,53,21],"class_list":["post-23","post","type-post","status-publish","format-standard","hentry","category-advanced-linux","category-linux","tag-gstreamer","tag-linux","tag-shell-script"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/posts\/23","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=23"}],"version-history":[{"count":0,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/posts\/23\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}