{"id":34388,"date":"2021-08-16T14:35:40","date_gmt":"2021-08-16T14:35:40","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=34388"},"modified":"2024-02-13T12:45:15","modified_gmt":"2024-02-13T12:45:15","slug":"enable-hardware-video-acceleration-va-api-for-firefox-in-ubuntu-20-04-18-04-higher","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2021\/08\/enable-hardware-video-acceleration-va-api-for-firefox-in-ubuntu-20-04-18-04-higher\/","title":{"rendered":"Enable Hardware Video Acceleration (VA-API) For Firefox in Ubuntu 20.04 \/ 18.04 &#038; Higher"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-34159\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/07\/firefox-icon250.png\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/07\/firefox-icon250.png 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/07\/firefox-icon250-150x150.png 150w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/p>\n<p><b>This tutorial shows how to enable hardware video acceleration (VA-API) for Firefox, so it uses the video card to decode\/encode video to save power.<\/b><\/p>\n<p>Hardware video acceleration is a computer technology to make the graphics card to encode and decode video, thus offloading the CPU to save power. And compared to CPU, GPU are normally more efficient at the job.<\/p>\n<p><u><b>UPDATE 2024: VA-API SHOULD BE ENABLED BY DEFAULT (if available) IN RECENT FIREFOX RELESES! SO, JUST GO TO BOTTOM TO VERIFY.<\/b><\/u><\/p>\n<p>There are a few ways to achieve this on Ubuntu Linux, including:<\/p>\n<ul>\n<li><b>Video Acceleration API (VA-API)<\/b> &#8211; an open source API developed by Intel.<\/li>\n<li><b>Video Decode and Presentation API for Unix (VDPAU)<\/b> &#8211; open source API developed by NVIDIA.<\/li>\n<li><b>NVENC\/NVDEC<\/b> &#8211; NVIDIA&#8217;s proprietary API.<\/li>\n<\/ul>\n<p>The VA-API supports Intel, AMD, and NVIDIA (via open-source Nouveau drivers) GPUs. And it is widely supported by software, such as MPV uses va-api hardware acceleration for video playback by default if available.<\/p>\n<p>The VDPAU API supports both AMD and NVIDIA, but has no support in Firefox or Chromium. And while NVENC\/NVDEC is used for NVIDIA GPU only, we usually use VA-API for hardware video acceleration.<\/p>\n<div id=\"attachment_34392\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/firefox-vaapi.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-34392\" class=\"size-large wp-image-34392\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/firefox-vaapi-600x341.jpg\" alt=\"\" width=\"600\" height=\"341\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/firefox-vaapi-600x341.jpg 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/firefox-vaapi-300x170.jpg 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/firefox-vaapi-768x436.jpg 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/firefox-vaapi.jpg 1271w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><p id=\"caption-attachment-34392\" class=\"wp-caption-text\">Firefox pop-up video encoding\/decoding via Intel GPU<\/p><\/div>\n<h3>Verify VA-API:<\/h3>\n<p><i><b>NOTE<\/b>: VA-API does not work on NVIDIA via proprietary drivers as mentioned above. If you installed NVIDIA proprietary driver via &#8216;Additional Drivers&#8217; utility, this will only work when you choose &#8216;Intel (Power Saving)&#8217; mode in NVIDIA Prime settings.<\/i><\/p>\n<p>The VA-API may work out-of-the-box in Ubuntu. You can firstly open terminal from start menu (click &#8216;Activities&#8217; and search terminal).<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/open-gnometerminal.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-34389\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/open-gnometerminal.jpg\" alt=\"\" width=\"600\" height=\"270\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/open-gnometerminal.jpg 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/open-gnometerminal-300x135.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>Next install <code>vainfo<\/code> package via command:<\/p>\n<pre>sudo apt install vainfo<\/pre>\n<p>And run it to check VA-API info:<\/p>\n<pre>vainfo<\/pre>\n<p>It outputs the driver as well as supported profile. <code>VAEntrypointVLD<\/code> means decoding support for this format, <code>VAEntrypointEncSlice<\/code> means encoding support.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/vainfo-ihd.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-34390\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/vainfo-ihd.png\" alt=\"\" width=\"600\" height=\"372\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/vainfo-ihd.png 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/vainfo-ihd-300x186.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>If the command outputs an error, you can try to install drivers via command:<\/p>\n<ul>\n<li>For NVIDIA nouveau and AMD, run command:\n<pre>sudo apt install mesa-va-drivers<\/pre>\n<\/li>\n<li>For Gen 8+ Intel hardware, install via command:\n<pre>sudo apt install intel-media-va-driver<\/pre>\n<p>And for old Intel hardware, install <code>i965-va-driver<\/code> instead via apt install command.<\/li>\n<\/ul>\n<p>By setting the environment variable, you can choose which driver to use. For example, set &#8220;export LIBVA_DRIVER_NAME=i965&#8221; to use i965 driver. The value can also set to &#8220;nouveau&#8221; for NVIDIA, or &#8220;radeonsi&#8221; for AMDGPU.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/vainfo-i965.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-34391\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/vainfo-i965.png\" alt=\"\" width=\"600\" height=\"444\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/vainfo-i965.png 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/vainfo-i965-300x222.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<h3>Enable VA-API in Firefox:<\/h3>\n<p>Firefox added VA-API support since version 80, though it&#8217;s not enabled by default. You can enabled it manually by doing following steps one by one.<\/p>\n<p>Firstly, open Firefox and go to <b>about:config<\/b> in url bar. Click on &#8220;Accept the Risk and Continue&#8221;. Then search for following keys, enable or disable them one by one:<\/p>\n<ul>\n<li><code>media.ffmpeg.vaapi.enabled<\/code> set to <code>true<\/code><\/li>\n<li><code>media.ffvpx.enabled<\/code> set to <code>false<\/code>.<\/li>\n<li><code>media.rdd-vpx.enabled<\/code> set to <code>false<\/code>.<\/li>\n<li><code>media.navigator.mediadatadecoder_vpx_enabled<\/code> set to <code>true<\/code>.<\/li>\n<li>If you experience page crashes, try setting <code>security.sandbox.content.level<\/code> to <code>0<\/code>.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/toggle-firefox-vaapi.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-34393\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/toggle-firefox-vaapi-600x392.jpg\" alt=\"\" width=\"600\" height=\"392\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/toggle-firefox-vaapi-600x392.jpg 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/toggle-firefox-vaapi-300x196.jpg 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/toggle-firefox-vaapi-768x502.jpg 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/toggle-firefox-vaapi.jpg 847w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>Secondly, set environment variable (for current user only). Open terminal and run command to edit profile file:<\/p>\n<pre>gedit ~\/.profile<\/pre>\n<p>When file opens, add following lines to the end:<\/p>\n<ul>\n<li>(Optional) Specify va-api driver as mentioned above (replace iHD accordingly):\n<pre>export LIBVA_DRIVER_NAME=iHD<\/pre>\n<p>You can <b>SKIP<\/b> this if <code>vainfo<\/code> outputs without error!<\/li>\n<li>Diable RDD sandbox:\n<pre>export MOZ_DISABLE_RDD_SANDBOX=1<\/pre>\n<\/li>\n<li>For Xorg session, default in Ubuntu 18.04\/Ubuntu 20.04:\n<pre>export MOZ_X11_EGL=1<\/pre>\n<\/li>\n<li>For Wayland session, default in Ubuntu 21.04 &amp; higher:\n<pre>export MOZ_ENABLE_WAYLAND=1<\/pre>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/vaapi-variable.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-34394\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/vaapi-variable-600x331.jpg\" alt=\"\" width=\"600\" height=\"331\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/vaapi-variable-600x331.jpg 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/vaapi-variable-300x166.jpg 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/vaapi-variable-768x424.jpg 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/vaapi-variable.jpg 900w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>Finally, log out and back in. Open Firefox and play a video and see result!<\/p>\n<h3>Check if Hardware Video Acceleration working:<\/h3>\n<p>During video playback, you can use top command to see CPU usage before and after enable VA-API. For Intel GPU, there&#8217;s <code>intel_gpu_top<\/code> command that monitor it continuously.<\/p>\n<p>Open terminal and run command to install the tool first:<\/p>\n<pre>sudo apt install intel-gpu-tools<\/pre>\n<p>Next, run command:<\/p>\n<pre>sudo intel_gpu_top<\/pre>\n<p>Start playing video in Firefox and you&#8217;ll see the video bar is busy (above 0%) if VA-API starts working.<\/p>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/intel-gpu-top.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-34395\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/intel-gpu-top.png\" alt=\"\" width=\"600\" height=\"268\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/intel-gpu-top.png 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2021\/08\/intel-gpu-top-300x134.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>For AMD GPU, there&#8217;s another command line tool &#8220;radeontop&#8221; available to monitor GPU activity.<\/p>\n<p><b>NOTE<\/b> for YouTube videos, the video codec may sometimes not supported by your hardware. To workaround, try <a href=\"https:\/\/addons.mozilla.org\/en-US\/firefox\/addon\/h264ify\/\" target=\"_blank\" rel=\"noopener\">h264ify<\/a> or <a href=\"https:\/\/addons.mozilla.org\/en-US\/firefox\/addon\/enhanced-h264ify\/\" target=\"_blank\" rel=\"noopener\">enhanced-h264ify<\/a> extension to make YouTube stream H.264 videos instead of VP8\/VP9.<\/p>\n<p>That&#8217;s all. Enjoy!<\/p>","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to enable hardware video acceleration (VA-API) for Firefox, so it uses the video card to decode\/encode video to save power. Hardware video acceleration is a computer technology to make the graphics card to encode and decode video, thus offloading the CPU to save power. And compared to CPU, GPU are normally [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":34356,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[1194],"class_list":["post-34388","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-firefox"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/34388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=34388"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/34388\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/34356"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=34388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=34388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=34388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}