How to Set Environmental Variables

I’m going through the instructions on how to set up hardware acceleration in Firefox with an NVIDIA GPU, and I’ve been told to “Run Firefox with NVD_BACKEND=direct MOZ_DISABLE_RDD_SANDBOX=1 env variables.”

Unfortunately, the guide doesn’t explain how to do this, and honestly, although I’ve tried using Google, I have a hard time finding a guide explaining exactly how to set an environmental variable in a permanent way. Most of what I find is either for another distro (and may or may not work here) or else I’m not entirely clear whether the variable will be set persistently, or how to make it apply to Firefox.

How can I get this environmental variable set, and is there a good general guide to working with environmental variables that I can use to expand my general knowledge?

You can define these in your .bash_profile file. They then are always set when you log in.

Since these are only needed for Firefox, a better approach is to set them only (automatically) when Firefox is executed. You could create a wrapper script so the variables are always set when you run the command “firefox”, or modify the .desktop launcher (by placing an edited copy in ~/.local/share/applications or /usr/local/share/applications, where you launch firefox like so:

Exec=env NVD_BACKEND=direct MOZ_DISABLE_RDD_SANDBOX=1 firefox --new-window %u
2 Likes

Your desktop environment may also provide a GUI way of doing this.

For example, in KDE Plasma, search for Firefox in the application launcher (‘start menu’), right-click on it and select “Edit Application”. This brings up an editor window where you can enter the environment variables, like so:

Thanks! This has gotten at least one of the variables set… the other one doesn’t seem to be listed in Firefox but between this and tweaking some about:config seetings as listed on the vaapi page, I was able to get hardware acceleration to admit to being working.

I just got hardware acceleration working as well (I believe for the most part!) from this Fedora Project Guide:

I’ve done all the steps required for my hybrid Intel GPU+Nvidia MX150 GPU laptop setup to function and under about:hardware there is a Media>Codec Support Information where I do see I have Software and Hardware encoding “Supported” (and in green colors!) for H264, VP8/9, and HEVC support enabled.

But like this question I’m still a bit stuck on adding a variable as I’m seeing different commands I’m just just wondering what exactly I should be inputting and where exactly in my org.mozilla.firefox.desktop file should I be adding this?

The Fedora project guide says to add this:

NVD_BACKEND=direct MOZ_DISABLE_RDD_SANDBOX=1

But in this post the answer given is this:

Exec=env NVD_BACKEND=direct env MOZ_DISABLE_RDD_SANDBOX=1 firefox --new-window %u

If I could get some clarification on which exactly to put where exactly I’d really appreciate it, thanks.

Edit: As of Firefox 137, I’ve also enabled media.hardware-video-decoding.force-enabled in about:config as the older media.ffmpeg.vaapi.enabled is deprecated.

Also, when I play a YouTube video on 1080p and I use the command nvtop it shows Firefox in the bottom category under “Graphic” but I’m reading that for it all to be working it should be reading “Compute” when running a YT video on Firefox with nvtop running. Here’s what mine currently looks like, appreciate any help.

I feel like I’m just one command away from finally getting it all working correctly.

The guide means that you should add those variables into the Exec: line so that the result is the line you mentioned:

So these aren’t two contradicting instructions - the guide is saying the same thing as the earlier answer, just in less explicit terms.

Is it possible that Firefox is playing this video using AV1 (which your GPU model doesn’t support, so would fall back to software decoding)? Is the result any different if you set media.av1.enabled to false in about:config, to force the use of a different codec?

Ok I just added the line Exec=env NVD_BACKEND=direct MOZ_DISABLE_RDD_SANDBOX=1 firefox %u to my Firefox desktop file in /home/scott/.local/share/applications, restarted Firefox, and nvtop still shows just Graphics and none Compute, so I guess I’m still using my Intel integrated card when watching any YouTube video? I also tried your suggestion media.av1.enabled to false and restarted, but still the same result. Not sure if I’ve done anything wrong, just trying to figure out if I can get this thing working or if I even do if I will even see any benefit to it or does it not even really matter that much ya know?

From the graphs in nvtop, it looks like GPU 1 (i.e. the Intel iGPU) is doing the decoding.

I’m not an Intel user but my impression is that they do a pretty decent job of video decoding, so maybe there is indeed not much benefit to making the dGPU do the decoding.

How is your experience of YouTube? Do videos seem jerky or low-quality with your current setup? If not, then not worrying about it is definitely an option :slightly_smiling_face:

1 Like

Yeah videos play just fine, no issues, I just assumed there was some “greater benefit” because I see this topic brought up sometimes and I didn’t want to miss out on any performance improvements if I could get them. But yeah, I guess I’ll just revert somethings and go back to what it was before, but appreciate the help all the same hehe

I recorded a quick 4K@60 video a while back and use it to test GPU video decode: https://www.youtube.com/watch?v=Hg0Sjh9VMTk

For Intel, I use intel_gpu_top and it shows about 20% on video while that video plays in Firefox. I’m thinking NVIDIA has a monitoring tool to show something similar.

(I’d check CPU too; just found out Firefox was 100% CPU’ing that video even with 20% video processing on Windows)

Thanks! I was wondering where that old setting went :stuck_out_tongue: (I still set media.ffmpeg.vaapi.enabled on Linux a few days ago; didn’t test video decode prior to setting it but Firefox still HW decoded with the old flag created at true)


Options from others above are likely better to isolate the envs only to Firefox, but I’d do:

sudo -e '/etc/profile.d/firefox-tweaks.sh'
# NVIDIA
export NVD_BACKEND='direct'
export MOZ_DISABLE_RDD_SANDBOX='1'

# End

I assume only Firefox would use MOZ_DISABLE_RDD_SANDBOX, but I’m not sure what NVD_BACKEND might affect outside of Firefox (I’m thinking video players, but mpv can have different settings forced in mpv.conf).

1 Like