49

I want to encode a video file to H.265. The last version of ffmpeg should be support H.265 (Source).

However, I could not find any information about the exact command.

I do not know, which library I should indicate after -vcodec.

I use the lastest Zeranoe FFmpeg Build (git-c78a416 (2013-10-26)).

3 Answers 3

78

Background

FFmpeg supports encoding HEVC/H.265 since 2014-2-12 with libx265. Now you can use ffmpeg directly to encode HEVC or use another encoder then manually mux that into .mp4, .mov, or .mkv using FFmpeg.

Available Encoders

Current H.265/HEVC encoders are:

Only the MulticoreWare and DivX are suggested because of their development time and reliability.

Two x265's

One confusion is that there are two independent projects both named "x265", one by a Chinese college student and is practically dead, and another by a commercial company called MulticoreWare. Although the former started out first, it is practically dead now, and the latter is under active development and is endorsed by VideoLAN (the developer of x264).

Timeline of FFmpeg HEVC Encoding Support

  • 2013-10-12 .mov muxing support added in 53f903b.
  • 2014-02-12 libx265 encoding support added in bb6b173.
  • 2014-03-09 More complete Matroska muxing support for HEVC added in 38aee64.
  • 2014-03-09 More complete .mov and new .mp4 muxing support added in 9563e67.

tl;dr

Anyways, these are a complete set of current possibilities of encoding HEVC in order of my recommendation:

  • Directly using MulticoreWare libx265 with FFmpeg. This means with the latest Zeranoe build you can now do this:

    ffmpeg -i INPUT -c:v libx265 -an -x265-params crf=25 OUT.mov
    # With audio
    ffmpeg -i INPUT -c:v libx265 -c:a copy -x265-params crf=25 OUT.mov
    

    Note: FFmpeg builds newer than 2014-03-09 allows you to mux HEVC into .mp4 files now (commit 9563e67):

    ffmpeg -i INPUT -c:v libx265 -an -x265-params crf=25 OUT.mp4
    

    You can also mux it in Matroska (.mkv):

    ffmpeg -i INPUT -c:v libx265 -an -x265-params crf=25 OUT.mkv
    
  • Using standalone MulticoreWare x265 and then mux the resulting file with FFmpeg or MP4Box. This will work with older FFmpeg builds that don't have libx265 support.

    # Decode input using FFmpeg and encode using x265 using pipe
    ffmpeg -i INPUT -f yuv4mpegpipe -pix_fmt yuv420p - | \
    x265 --y4m -o encoded.265 -
    
    # Mux the resulting encoded .265 file into an .mp4 or .mov
    
    # Using ffmpeg: only works with newer builds that support muxing HEVC
    # Muxing to .mp4 supported since 03-09-2014
    ffmpeg -i encoded.265 -c copy out.mp4
    # With audio
    ffmpeg -i encoded.265 -i INPUT -map 0 -map 1:a -c copy out.mp4
    
    # Using MP4Box
    MP4Box -add raw.265 out.mp4
    # With audio
    MP4Box -add {INPUT}#audio -add raw.265 out.mp4
    

    Thanks to @Duvrai.

  • Using DivX HEVC Encoder and then mux it.

    The way of using it is similar to using standalone x265 (see above).

Update: FFmpeg has HEVC encoding support using MulticoreWare libx265 now.

Update 2: FFmpeg now has support for muxing HEVC into mp4 AND mov now.

8
  • 3
    For those who don't know what the crf=25 represents in the example commands, here is a CRF guide: slhck.info/articles/crf Aug 13, 2014 at 12:00
  • To clarify @Programster's comment, the link goes to an x264 guide, but x265 and x264 are very similar in the CRF selection.
    – Timothy Gu
    Aug 13, 2014 at 21:26
  • I couldn't find any guide on CRF specifically aimed at h265 but the concept looks constant. I am currently experimenting with the values it recommends (18-28), but do not know if these need to be slightly different for h265. Aug 13, 2014 at 21:44
  • 1
    Not impressed with the quality with preset medium crf=28. File size is smaller, but I can definitely tell the video quality suffers immensely.
    – Sun
    Aug 11, 2015 at 17:12
  • 4
    Great answer overall, but missing a critical bit; -c:v libx265 as it is, the examples above output using x264. For clarity, ffmpeg -i INPUT -c:a copy -x265-params crf=2 OUTPUT_h265.mp4 was encoding with x264, but ffmpeg -i INPUT -c:v libx265 -c:a copy -x265-params crf=2 OUTPUT_h265.mp4 encoded with x265.
    – rainabba
    May 3, 2016 at 20:49
35

ffmpeg added x265 encoding on 12 February 2014, and mp4 container support on 9 March:

ffmpeg -i input -c:v libx265 -c:a copy output.mp4

Note:

  • The above command will copy the audio in it's original codec. If that doesn't work, convert the audio to AAC by omitting -c:a copy (or replace copy with aac, libfdk_aac or libfaac — ordered quality-wise)
  • when compiling ffmpeg use --enable-libx265 (and --enable-libfdk-aac or --enable-libfaac if needed)
2
  • 1
    FFmpeg supports muxing HEVC natively in mp4 since 3-9-2014.
    – Timothy Gu
    Mar 14, 2014 at 2:38
  • 3
    For some reason the result was green and pink, but when I added -pix_fmt yuv420p before the -c:v, the result was fine. Jul 28, 2016 at 3:00
-4

Try the current divx encoder. It has build in support for h265: http://www.divx.com/

(as reported http://jkdigital.de/h265-hevc-divx-praxisbericht/ )

1
  • 1
    The question is specifically about using ffmpeg to accomplish this. Sep 15, 2018 at 19:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .