4

How can I use libx265 (H.265) in the ffmpeg-python package?

I tried using:

( ffmpeg .input('0.mp4') .filter('fps', fps=25, round='up') .output('out.mkv', format='h265') .run() ) 

But it is throwing an error:

format is not recognized

But this works:

( ffmpeg .input('0.mp4') .filter('fps', fps=25, round='up') .output('out.mkv', format='h264') .run() ) 
1

1 Answer 1

6

Replace format='h265' with vcodec='libx265'.


  • H.265 is a video codec, and vcodec='libx265' tells FFmpeg to use the libx265 video encoder.
  • The output format, in case of an MKV video container is format='matroska'. You don't have to set the format, because FFmpeg automatically selects the output format by the .mkv file extension.

Updated code:

import ffmpeg ( ffmpeg .input('0.mp4') .filter('fps', fps=25, round='up') .output('out.mkv', vcodec='libx265') .run() ) 
Sign up to request clarification or add additional context in comments.

3 Comments

Thankyou! Is it possible to add " -bitexact -map_metadata -1 " in the above code?
You can add them to the output arguments: output('out.mkv', vcodec='libx265', fflags='bitexact', map_metadata='-1')
It looks like fflags='bitexact' is not equivalent to -bitexact. A way around it is using **{'bitexact': None} (instead of fflags='bitexact').

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.