{"id":689,"date":"2019-10-24T12:27:23","date_gmt":"2019-10-24T10:27:23","guid":{"rendered":"http:\/\/blogs.igalia.com\/xrcalvar\/?p=689"},"modified":"2019-10-24T12:27:23","modified_gmt":"2019-10-24T10:27:23","slug":"vcr-to-webm-with-gstreamer-and-hardware-encoding","status":"publish","type":"post","link":"https:\/\/blogs.igalia.com\/xrcalvar\/2019\/10\/24\/vcr-to-webm-with-gstreamer-and-hardware-encoding\/","title":{"rendered":"VCR to WebM with GStreamer and hardware encoding"},"content":{"rendered":"<p>My family had bought many years ago a Panasonic VHS video camera and we had recorded quite a lot of things, holidays, some local shows, etc. I even got paid 5000 pesetas (30\u20ac more than 20 years ago) a couple of times to record weddings in a amateur way. Since my father passed less than a year ago I have wanted to convert those VHS tapes into something that can survive better technologically speaking.<\/p>\n<p>For the job I bought a <a href=\"https:\/\/www.amazon.es\/gp\/product\/B0776QZKPP\/ref=ppx_yo_dt_b_asin_title_o04_s00?ie=UTF8&#038;psc=1\">USB 2.0 dongle<\/a> and connected it to a VHS VCR through a SCART to RCA cable.<\/p>\n<p>The dongle creates a <i>V4L2<\/i> device for video and is detected by <i>Pulseaudio<\/i> for audio. As I want to see what I am converting live I need to <i>tee<\/i> both audio and video to the corresponding sinks and the other part would go to to the encoders, muxer and filesink. The command line for that would be:<\/p>\n<p><code>gst-launch-1.0 matroskamux name=mux ! filesink location=\/tmp\/test.webm \\<br \/>\nv4l2src device=\/dev\/video2 norm=255 io-mode=mmap ! queue ! vaapipostproc ! tee name=video_t ! \\<br \/>\n        queue ! vaapivp9enc rate-control=4 bitrate=1536 ! mux.video_0 \\<br \/>\n        video_t. ! queue ! xvimagesink \\<br \/>\npulsesrc device=alsa_input.usb-MACROSIL_AV_TO_USB2.0-02.analog-stereo ! 'audio\/x-raw,rate=48000,channels=2' ! tee name=audio_t ! \\<br \/>\n    queue ! pulsesink \\<br \/>\n        audio_t. ! queue ! vorbisenc ! mux.audio_0<\/code><\/p>\n<p>As you can see I convert to <i>WebM<\/i> with <i>VP9<\/i> and <i>Vorbis<\/i>.  Something interesting can be passing <code>norm=255<\/code> to the <i>v4l2src<\/i> element so it&#8217;s capturing PAL and the <code>rate-control=4<\/code> for <i>VBR<\/i> to the <i>vaapivp9enc<\/i> element, otherwise it will use <i>cqp<\/i> as default and file size would end up being huge.<\/p>\n<p>You can see the pipeline, which is beatiful, here:<\/p>\n<p><a href=\"\/xrcalvar\/files\/2019\/10\/pipeline.png\"><img decoding=\"async\" src=\"\/xrcalvar\/files\/2019\/10\/pipeline.png\"><\/a><\/p>\n<p>As you can see, we&#8217;re using  <i>vaapivp9enc<\/i> here which is hardware enabled and having this pipeline running in my computer was consuming more or less 20% of CPU with the CPU absolutely relaxed, leaving me the necessary computing power for my <a href=\"https:\/\/webkitgtk.org\/\">daily work<\/a>. This would not be possible without GStreamer and GStreamer VAAPI plugins, which is what happens with other solutions whose instructions you can find online.<\/p>\n<p>If for some reason you can&#8217;t find <i>vaapivp9enc<\/i> in Debian, you should know there are a couple of packages for the intel drivers and that the one you should install is <i>intel-media-va-driver<\/i>. Thanks go to my colleague at <a href=\"https:\/\/www.igalia.com\">Igalia<\/a> <a href=\"https:\/\/www.igalia.com\/igalian\/vjaquez\">V\u00edctor J\u00e1quez<\/a>, who maintains <a href=\"https:\/\/gitlab.freedesktop.org\/gstreamer\/gstreamer-vaapi\/\">gstreamer-vaapi<\/a> and helped me solving this problem.<\/p>\n<p>My workflow for this was converting all tapes into <i>WebM<\/i> and then cutting them in the different relevant pieces with <a href=\"http:\/\/www.pitivi.org\/\">PiTiVi<\/a> running <a href=\"https:\/\/gitlab.freedesktop.org\/gstreamer\/gst-editing-services\">GStreamer Editing Services<\/a> both co-maintained by my colleague at <a href=\"https:\/\/www.igalia.com\">Igalia<\/a>, <a href=\"https:\/\/www.igalia.com\/igalian\/tsaunier\">Thibault Saunier<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My family had bought many years ago a Panasonic VHS video camera and we had recorded quite a lot of things, holidays, some local shows, etc. I even got paid 5000 pesetas (30\u20ac more than 20 years ago) a couple &hellip; <a href=\"https:\/\/blogs.igalia.com\/xrcalvar\/2019\/10\/24\/vcr-to-webm-with-gstreamer-and-hardware-encoding\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":31,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,7,8,73,9,11],"tags":[77,15,76],"class_list":["post-689","post","type-post","status-publish","format-standard","hentry","category-igaliacom","category-planet-gnome","category-planet-gpul","category-planet-gstreamer","category-planet-igalia","category-planeta-gnome-hispano","tag-encoding-by-hardware","tag-gstreamer","tag-vcr"],"_links":{"self":[{"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/posts\/689","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/comments?post=689"}],"version-history":[{"count":28,"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/posts\/689\/revisions"}],"predecessor-version":[{"id":723,"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/posts\/689\/revisions\/723"}],"wp:attachment":[{"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/media?parent=689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/categories?post=689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.igalia.com\/xrcalvar\/wp-json\/wp\/v2\/tags?post=689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}