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.
1
For those who don't know what the
– Programster – 2014-08-13T12:00:54.797crf=25
represents in the example commands, here is a CRF guide: http://slhck.info/articles/crfTo clarify @Programster's comment, the link goes to an x264 guide, but x265 and x264 are very similar in the CRF selection. – Timothy Gu – 2014-08-13T21:26:35.327
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. – Programster – 2014-08-13T21:44:14.233
@Programster: Yes x265's range is 0-51. However default value is 28 instead of 23.
– Timothy Gu – 2014-08-13T23:45:33.650Not impressed with the quality with preset medium crf=28. File size is smaller, but I can definitely tell the video quality suffers immensely. – Sun – 2015-08-11T17:12:31.127
@sunk818, x265 CRF of course has different meaning from x264's CRF. This graph might be of interest in assessing the quality of x265.
– Timothy Gu – 2015-11-13T04:09:22.597What would help me is ffmpeg default crf value for x265 matching x264 in terms of quality. An equivalency map of quality between x265 and x264 would also help. If x264 crf is 23 for ffmpeg, then what crf value would match that for x265? – Sun – 2015-11-14T09:11:28.760
2Great 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, butffmpeg -i INPUT -c:v libx265 -c:a copy -x265-params crf=2 OUTPUT_h265.mp4
encoded with x265. – rainabba – 2016-05-03T20:49:49.950@rainabba, thanks for the correction. Fixed. – Timothy Gu – 2016-05-07T02:25:58.230