====== ffmpeg - Conversions - Convert H264 to H265 ======
===== Convert h.264 to h.265 (no change in resolution) =====
ffmpeg -i input.mp4 -c:v libx265 -vtag hvc1 -c:a copy output.mp4
----
===== Software Encoding =====
ffmpeg -i a.mp4 -c:v libx265 a.mkv
ffmpeg -i a.mp4 -c:v libx265 -map 0:v -c:a copy -map 0:a -c:s copy b.mkv
ffmpeg -i a.mp4 -c:v libx265 -map 0:v -c:a copy -map 0:a? -c:s copy -map 0:s? b.mkv
**NOTE:** **libx265** is a software encoder.
* It does not support hardware encoding.
----
===== Using GPU Hardware Encoding =====
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i a.mp4 -c:v hevc_vaapi a.mkv
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i a.mp4 -c:v hevc_vaapi -map 0:v -c:a copy -map 0:a -c:s copy a.mkv
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i a.mp4 -c:v hevc_vaapi -map 0:v -c:a copy -map 0:a? -c:s copy -map 0:s? a.mkv
**NOTE:** This allows the GPU to be used:
-hwaccel vaapi -hwaccel_output_format vaapi -vaapi_device /dev/dri/renderD128
----
==== Encoding formats ====
Try replacing scale with scale_vaapi and replace -c:v h264 with -c:v: h264_vaapi
The supported encoders are:
|H.262 / MPEG-2 part 2|mpeg2_vaapi|
|H.264 / MPEG-4 part 10 (AVC)|h264_vaapi|
|H.265 / MPEG-H part 2 (HEVC)|hevc_vaapi|
|MJPEG / JPEG|mjpeg_vaapi|
|VP8|vp8_vaapi|
|VP9|vp9_vaapi|
----
===== Keeping the output size low, similar to Software encoding =====
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i input.mp4 -c:v hevc_vaapi -b:v 0.589M output.mp4
**NOTE:** I had to set the bitrate smaller because the transcoded one was even bigger than the original file.
* You can change bitrate at 0.589M
* 0.589M is 0.589 Megabytes.
* Change it accordingly to your desired bitrate. I will use 2x - 3x smaller than the orginal. In this example h.264 to hevc.
----
==== Other examples ====
ffmpeg -i a.mp4 -vaapi_device /dev/dri/renderD128 -vf format=nv12,hwupload -c:v hevc_vaapi -map 0:v:0 -map 0:a? -c:a copy -map 0:s? -c:s copy -rc_mode 1 -qp 25 -map_chapters 0 b.mkv
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i a.mp4 -c:v hevc_vaapi -map 0:v:0 -map 0:a? -c:a copy -map 0:s? -c:s copy -b:a 320k -global_quality 25 k.mkv
ffmpeg -init_hw_device vaapi=amd:/dev/dri/renderD128 -hwaccel vaapi -hwaccel_output_format vaapi -hwaccel_device amd -filter_hw_device amd -i a.mp4 -vf 'format=nv12|vaapi,hwupload' -y -c:v hevc_vaapi -map 0:v:0 -map 0:a? -c:a copy -map 0:s? -c:s copy -qp:v 28 b.mkv
ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i a.mp4 -c:v hevc_vaapi b.mkv
ffmpeg -threads 16 -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format vaapi -i a.mp4 -c:v hevc_vaapi c.mkv
----
=== References ===
https://trac.ffmpeg.org/wiki/Encode/H.265