How to enable libx264 in ffmpeg

I am trying to encode with libx264 in ffmpeg

ffmpeg -f image2 -r 25 -i frames/%03d.bmp -vcodec libx264 out.mp4

However, i get the following error message:

Unknown encoder 'libx264'

If us type ffmpeg in the console, it shows under configuration --disable-libx264, so I guess that is the reason.

How can I enable this? I found in some other questions that it can be done by reinstalling with this option, but there where two things I could not find:

  1. Is it possible to change the configuration without reinstalling?
  2. If not, how do I pass options while reinstalling?
3

2 Answers

Is it possible to change the configuration without reinstalling?

The --disable-libx264 flag is a bit misleading. This is not an option that disables the h264 codec during installation, but is a compile flag during creation of your binary/executable. To change that flag, you either need to recompile it yourself, or install a version which had it enabled during compilation. This comes down to the repository you are downloading it from. I can confirm h264 is available on the native x64 Ubuntu version in 18.04.

If not, how do I pass options while reinstalling?

You need to get ffmpeg from a different source which did not disable it. The native windows version installed by chocolatey has the flag enabled on my system. It might be that WSL uses a separate repository which disabled it.

As for how to proceed:

  • Use the native windows version of ffmpeg
  • Try a different Ubuntu version, e.g. 18.04 LTS
  • Download ffmpeg from a different source, example
  • Compile ffmpeg from source

It would seem the ffmpeg binary that you have does not have the codec enabled. If you check the codecs as advised by @MMM above

ffmpeg -codecs | grep 264

you should see a line

DEV.LS h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (decoders: h264 h264_v4l2m2m ) (encoders: libx264 libx264rgb h264_v4l2m2m h264_vaapi )

The important part is the first 2 letters, tells you both decode and encode is supported. Either you'll need to download a binary with the library enabled or compile from scratch. The step by step instructions on the ffmepg website are easy enough to follow.

I usually compile from scratch but only because I personally want the libfdk_aac which is licenced differently and cannot be distributed. The same restriction does not apply to x264.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like