{"id":435,"date":"2018-05-04T17:44:10","date_gmt":"2018-05-04T16:44:10","guid":{"rendered":"https:\/\/tollana.d-tor.org\/notes-to-self\/?p=435"},"modified":"2018-05-04T17:44:10","modified_gmt":"2018-05-04T16:44:10","slug":"hardware-accelerated-transcode","status":"publish","type":"post","link":"https:\/\/tollana.d-tor.org\/notes-to-self\/?p=435","title":{"rendered":"Hardware accelerated transcode"},"content":{"rendered":"<p>While reading the Linux Magazine on the bowl this morning, I discovered that <em>ffmpeg<\/em> has hardware support for decoding and encoding. Since I do that quite often, I figured it&#8217;s time to try it out. Lo and behold, it works better than I expected! Not on hadante, though. <em>ffmpeg<\/em> just segfaulted, because the card is way too old and the kernel module doesn&#8217;t seem to support it.<\/p>\n<p>On othalla (my almost 4 year old laptop), it works like a charm. <em>ffmpeg<\/em> said encoding\u00a0 at 5.5 times the original speed, even over NFS!<\/p>\n<p>The command line I used:<\/p>\n<pre>$\u00a0ffmpeg -hwaccel cuvid -c:v h264_cuvid -resize 1280x720\\\r\n-i in.mkv -acodec copy -scodec copy\\\r\n-c:v h264_nvenc -preset slow -b:v 4000K -minrate 4000K out.mkv<\/pre>\n<p>It has a NVIDIA GPU, as well as an Intel pixel manager, but <em>cuvid<\/em> and <em>nvenc<\/em> only works the (proprietary) NVIDIA driver. Anyhow, as always it&#8217;s important where you place the options. Any options before -i is for decoding, anything after is for encoding. This makes:<\/p>\n<pre>-hwaccel cuvid -c:v h264_cuvid -resize 1280x720<\/pre>\n<p>ffmpeg decode everything via cuvid on the GPU and resize it to 720p. Source was 1080p.<\/p>\n<pre>-acodec copy -scodec copy<\/pre>\n<p>says: Just copy the audio stream and the subtitle stream to output. Now comes the important:<\/p>\n<pre>-c:v h264_nvenc -preset slow -b:v 4000K -minrate 4000K<\/pre>\n<p>tells it to let the GPU encode it to x264, preset slow and a minimum bitrate of 4000K. If I do the same via software decoder and encoder, I get barely more than real time speed, perhaps 1.1 or 1.2, depending on the source. With cuvid I get 5.5. Even Hadante with its 12 processors and 32GB only gets a speed of 2.0 to 2.2 max, and it&#8217;s hardware is much more current! Like it!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While reading the Linux Magazine on the bowl this morning, I discovered that ffmpeg has hardware support for decoding and encoding. Since I do that quite often, I figured it&#8217;s time to try it out. Lo and behold, it works better than I expected! Not on hadante, though. ffmpeg just segfaulted, because the card is &hellip; <a href=\"https:\/\/tollana.d-tor.org\/notes-to-self\/?p=435\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Hardware accelerated transcode<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79,77,78],"tags":[48,110],"class_list":["post-435","post","type-post","status-publish","format-standard","hentry","category-hardware","category-linux","category-transcoding","tag-ffmpeg","tag-nvidia"],"_links":{"self":[{"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/posts\/435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=435"}],"version-history":[{"count":3,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/posts\/435\/revisions"}],"predecessor-version":[{"id":438,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=\/wp\/v2\/posts\/435\/revisions\/438"}],"wp:attachment":[{"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tollana.d-tor.org\/notes-to-self\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}