-
Notifications
You must be signed in to change notification settings - Fork 114
Description
SYMPTOM: Your stand-alone VLC plays .mp4 files with H.264 encoding fine, but when you try to do the same with python-vlc, it doesn't. You get an error "Codec `h264' (H264 - MPEG-4 AVC (part 10)) is not supported." or something similar.
This has been subject of many reports and questions over the years. There has been heuristic suggestions that might work such as "update ffmpeg", "install additional codecs" – for example in the case of Ubuntu with "sudo apt install ubuntu-restricted-extras" – or by setting enviroment variables such as VLC_PLUGIN_PATH to some good directory, and so on. For some people these might work, but for many those have not.
I spent enough time trying to solve this, and I record my findings so that others need not to endure the same in the future – supposing search engines will find this note. While there may be other ways to encounter problems with H.264 or other codecs and python-vlc, I suspect this is a major one.
There was actually nothing wrong with the H.264 codec itself, its location, or python-vlc finding it. The problem was that the codec needed another standard library - in the case of Ubuntu it was libstdc++.so - and the version I had was too old for the codec.
It shouldn't have been like that, since I had installed the whole operating system less than a month ago. Thus everything should have been really well up to date. And it was, as well as no amount of additional updating or installing helped at all. The reason behind this was that I use Ananconda for python environments, and it masks system wide libraries with the ones that it has installed by itself. The newest libstdc++.so available from Anaconda default channel was over three years old.
To make python-vlc work, I removed my python environment for VLC, and created a new environment using conda-forge channel that has often more up to date components.
conda create --name vlc -c conda-forge python
conda activate vlc
pip install python-vlc
and the H.264 files played without problems. The Ananconda default channel had library version 29, whereas conda-forge had version 34.
If your problem is different, and you wish to inspect your system,
# python
import vlc
instance = vlc.Instance('--verbose=3')
media = instance.media_new("myfile.mp4")
player = instance.media_player_new()
player.set_media(media)
player.play()
could be useful. There will be tons of output. In my case it included
main decoder warning: cannot load module '/usr/lib/x86_64-linux-gnu/vlc/plugins/codec/libavcodec_plugin.so' (/home/myname/anaconda3/envs/vlc/bin/../lib/libstdc++.so.6: version 'GLIBCXX_3.4.30' not found (required by /lib/x86_64-linux-gnu/libjxl_threads.so.0.7))
Inspecting that library with strings libstdc++.so.6 | grep GLIBCXX showed that it would have GLIBCXX versions only up to 3.4.29.
Additional note for Ubuntu users: snap sandboxing has become stricter, and while you could have used python-vlc with snap installed VLC with 20.04, you apparently cannot with Ubuntu 24.04. Thus use apt to install VLC.
I would also suggest making small note on the Install instructions. For example, "If you use Anaconda and you have codec problems, please make a conda environment by using conda-forge channel. The default channel may install standard libraries that are several years old, and those could manifest in errors with the codecs or otherwise. For example, an environment named vlc can be created by conda create -n vlc -c conda-forge python. Ubuntu users should use apt to install VLC. Sandboxed environments for VLC such as snap or flatpak might not work with python-vlc at least on some Linuxes.".