MATLAB: Does VideoReader return an empty video object on Linux

codecemptyformatgstreamerlinuxMATLABvideovideoreader

I have an AVI file encoded in H.264 format. I am successfully able to read it in MATLAB on Windows 10. However, when opening the file with 'VideoReader' on Linux, I get the following output:
>> VideoReader('MyVideo.avi');
ans =
VideoReader with properties:
General Properties:
Name: 'MyVideo.avi'
Path: '/home/user/Documents/MyVideo.avi'
Duration: 300.0240
CurrentTime: 300.0240
NumFrames: <Calculating...> learn more
Video Properties:
Width: 0
Height: 0
FrameRate: 0
BitsPerPixel: 0
VideoFormat: ''
Notice that the 'Width', 'Height', 'FrameRate', and 'BitsPerPixel' properties are all 0 and the 'VideoFormat' string is empty. The 'mmfileinfo' command gives similar output:
>> mmfileinfo('MyVideo.avi').Video
ans =
struct with fields:
Format: ''
Height: []
Width: []
Finally, if I call 'readFrame' on this 'VideoReader' object, it errors with the following message:
No more frames available to read from file.

Best Answer

There are two common reasons as to why MATLAB may fail to read a video file in this way.
1) The necessary gstreamer packages are not installed:
In order to properly read video files, MATLAB requires gstreamer1.0 and several associated packages to be present on the system. In particular, the gstreamer libav package provides most of the necessary gstreamer functionality. On Debian/Ubuntu based systems, this package can be installed using the command
$ sudo apt-get install gstreamer1.0-libav
On RHEL/Fedora based systems, the package can be installed with either
$ sudo yum install gstreamer1-libav 
or
$ sudo dnf install gstreamer1-libav
For RHEL/Fedora based systems, it may be necessary to install additional repositories in order to gain access to this package. See the RPM Fusion website for more information about how to install these additional repositories:
The following gstreamer plugins provide support for additional video codecs. It may be necessary to install them depending on the type of video you are reading: 
2) There is an ABI incompatibility with the MATLAB libstdc++ library
By default, MATLAB uses its own shipped libstdc++. This version of libstdc++ may be newer or older than the version used by the installed gstreamer library. Occasionally, this can cause an ABI incompatibility which prevents MATLAB from loading the gstreamer library at runtime. To test if this is the case, open MATLAB from the Linux terminal using the command:\n\n
$ matlab
Next, attempt to read the video file using 'VideoReader'. If the Linux terminal outputs a warning message then there is an ABI incompatibility:
(MATLAB:30631): GStreamer-WARNING **: 14:16:03.858: Failed to load plugin '/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstlibav.so': /opt/MATLAB/R2019b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.25' not found (required by /lib/x86_64-linux-gnu/libopenmpt.so.0)
The simplest workaround for this issue is to tell MATLAB to use the Linux system libstdc++ library instead of the version shipped with MATLAB. Please see the following link for instructions on how to do this:
Related Question