When you start using a fresh installed Ubuntu system and try to open an MP4 file to play videos, it may show you an error that reads:
H.264 (High Profile) decoder is required to play the file, but is not installed.
You can perhaps guess what’s going on here. Your system doesn’t have the required media codecs installed and hence the video player cannot play that video file.
So, what’s the solution here? You install the required codec. But how?
I’ll discuss three ways about fixing this issue:
- Install just the required codec: It could work for the given file but some other video files will still complain about missing codecs.
- Install a wide variety of multimedia codecs at once: It installs codecs as well as some other packages that you might not need like Microsoft Fonts.
- Install a different video player: Applications like VLC and MPV have better support for codecs by default. You don’t need to install them separately for most common video files.
If you take my advice, I suggest going for the second as well as the third method. Why? You’ll see in a moment.
Getting h264 decoder in Ubuntu Linux
I am using Ubuntu Linux here. The first and the third methods should work for other distributions but not the second one as the package mentioned is (usually) exclusive to Ubuntu.
Method 1: Install only the required codec (not recommended)
When you see the error, it gives you the option to “Find in Ubuntu Software”. Clicking on that option opens the Software Center and it may (or may not) show some packages that will install the h264 decoder on your system.
The package names may sound similar but you need the GStreamer Multimedia Codecs from the “bad” set. Check the description of the packages.
Alternatively, you can install the package in the terminal using this command:
sudo apt install gstreamer1.0-plugins-bad
If you are new to the terminal, please note that it will ask for your account password. Nothing is displayed on the screen while you type the password. That’s the Linux way. You type the password blindly and press enter.
Once this package is installed, open the file again and see if it works now.
It may work for you but the story doesn’t end here. You may have other video files that require some other h264 decoder or some other decoder.
You can try and install more decoders like this:
sudo apt install libavcodec-extra gstreamer1.0-plugins-ugly gstreamer1.0-libav
However, there is a much more convenient way of installing media codecs in Ubuntu and I’ll show it to you in the next section.
Method 2: Install all multimedia codecs (recommended)
Ubuntu provides a meta-package named ubuntu-restricted-extras that consists of most of the common audio and video codecs along with some other packages like the Microsoft fonts.
Install this package and you won’t have to worry about the media codecs anymore.
Open the terminal in Ubuntu and type the following command:
sudo apt install ubuntu-restricted-extras
Since this meta-package contains software from Microsoft, you’ll have to accept the End User License Agreement (EULA).
The next screen may look like the one below. Just press tab and it will highlight the options. When the correct options are highlighted, press enter to confirm your selection.
With the multimedia codecs installed, you should be able to play (almost) all kinds of media files. Your music player can play MP3 files and your video player should be able to play MP4, MKV, and whatnot.
However, this too is not the end of the story, at least for some people.
Why do I say that? Because I have noticed that the default video player in Ubuntu, Totem, often struggles while playing certain kinds of video files. You’ll notice that suddenly your system heats up, the fans start blowing and your mouse cursor stop functioning smoothly.
Why? Because Totem is struggling in decoding the video and taking too much processing power.
You can test it by running the top command while playing the video. Look for the process named totem (that’s the name of the default video player).
What can you do now? Your trouble seems to be never ending. Fret not. There are better video players in Linux and they will help you solve the issue.
Method 3: Install a better video player (recommended)
There are many good video players in Linux. I find them better than the default Totem video player.
Personally, I prefer two of the lot: VLC and MPV.
VLC is a versatile and hugely popular video player. Chances are that you have already used VLC.
MPV Media Player is not that popular but this lightweight application is quite good for playing video files.
Both VLC and MPV players are good at handling media codecs. You don’t even need to install media codecs separately with them. Just install VLC or MPV and you should be able to play various kinds of video files.
Either look for it in the software center:
Or install MPV on Ubuntu using the command line:
sudo apt install mpv
Now that you have another video player, you should right click on the video files and choose to open with the new video player.
Alternatively, you can make it the default application for playing video files and use double clicks.
Did it work for you?
I hope I didn’t go into too much detail here. I wanted to explain the various methods and the pros and cons associated with each of them.
Did you manage to get rid of the h264 decoder problem in Ubuntu? Which method did you go for?