Unable to play MP4 file in Ubuntu 20.04

Unable to play MP4 file in Ubuntu 20.04

“Unable to play MP4 file in Ubuntu 20.04 : H.264 (Main Profile) decoder is required to play the file, but is not installed”, If you get this message when you try to play video file. Don’t get panics, Its just your installation is new and it might not contain the required codecs.

Why i am Unable to play MP4 file in Ubuntu 20.04 files?

Lets start with comparing this situation with Windows, If you install Windows and try to play MP4 videos you will notice video might not play as new installation misses codecs that are required to play the video. You need to install codec pack to be able to play those videos. Similarly on Ubuntu when you try to play MP4 videos after installation you might not be able to play it as codecs are missing as they might be 3rd party codes that Ubuntu might not own. This is mostly due to legal reasons, But in some cases it can be technical as well.

Unable to play MP4 file in Ubuntu 20.04 - Ubuntu logo
Unable to play MP4 file in Ubuntu 20.04 – Ubuntu logo

The error on playback

Whenever you try to play a video in above situation you will see a popup appearing and it displays this message

H.264 (Main Profile) decoder are required to play the file, but are not installed.

After this you will see a prompt to install the missing codec H.264, when you try to install it, you will be taken to software center and there you will see gstreamer plugin installation option for bad and ugly. The good one is already installed. You will also notice that H.264 will also be there.

For me this option didn’t work. Even i would avoid doing thing from there (software center) rather just run few commands in terminal to get the things done.

Fix : Unable to play MP4 file in Ubuntu 20.04

Just launch the terminal from application menu or just hold Ctrl + Alt + T . Now First thing which we will do here is update the repositories using the below command

Code #1 : apt-get update

sudo apt-get update

Now its the time to install most common codecs to support video playback of various format including MP4 for the video player, For this run the below command in terminal

Code #2 : install libdvd and gstreamer bad & Ugly

sudo apt-get install libdvdnav4 libdvdread7 gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly libdvd-pkg

What the above code will do is install libdvdnav4 libdvdread7 gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly libdvd-pkg packages.

Code #3 : install ubuntu-restricted-extras

After installing the previous packages, proceed with the installation of the Ubuntu restricted extras with the following command:

sudo apt-get install ubuntu-restricted-extras

What we installed

Lets get to know about each package we installed to fix Unable to play MP4 file in Ubuntu 20.04 issue :

libdvdnav4 and libdvdread7

Libdvdnav is a library for developers of multimedia applications which is used as a DVD navigation library and facilitates an interface to the advanced features of DVDs, like menus, chapters and navigation. It also helps in multi-angle playback and even interactive DVD games. It contains the VM and other parts useful for writing DVD players. The main usage of libdvdnav is a loop regularly calling a function to get the next block, surrounded by additional calls to tell the library of user interaction. The whole DVD virtual machine and internal playback states are completely encapsulated. Libdvd is based on Ogle DVD player, but was altered so that it can be used by xine and mplayer.

Source: Videolan

gstreamer1.0-plugins-bad and gstreamer1.0-plugins-ugly

GStreamer plugins from the “bad” set – GStreamer is a streaming media framework, based on graphs of filters which operate on media data. Applications using this library can do anything from real-time sound processing to playing videos, and just about anything else media-related. Its plugin-based architecture means that new data types or processing capabilities can be added simply by installing new plug-ins.

GStreamer Bad Plug-ins is a set of plug-ins that aren’t up to par compared to the rest. They might be close to being good quality, but they’re missing something – be it a good code review, some documentation, a set of tests, a real live maintainer, or some actual wide use.

GStreamer Ugly Plug-ins package contains plugins from the “ugly” set, a set of good-quality plug-ins that might pose distribution problems.

libdvd-pkg

This package provides libraries that are needed for playing video DVDs with a media player (such as VLC, SMplayer, Totem, etc.). It automates the process of downloading source files, compiling them, and installing the binary packages.

Ubuntu tries to make all of the most important software available to its users automatically. But due to patent and copyright restrictions, the distribution of software to support non-free formats gets complicated. To overcome this we have ubuntu-restricted-extras packages installation which allows us the ability to play popular non-free media formats, including DVD, MP3, Quicktime, and Windows Media formats.

After running the commands, you should be able be able to play different format videos immediately which were failing initially. If you are still face issue try restarting you computer. Now it should work.

If you are still Unable to play MP4 file in Ubuntu 20.04 please comment, we will try to help.