- How to generate an MP4 with H.265 codec using FFmpeg?
- H.265 HEVC support in High Sierra
- Converting WebM to MP4 Using FFmpeg
ffmpeg -i <input.???> -c:v libx265 -c:a aac -crf 25 -tag:v hvc1 <output.h265.mp4>
Note the need for the -tag:v hvc1
(see H.265 HEVC support in High Sierra for details). Without the tag, VLC opens the video with out issue, but QuickTime Player does not. The tag fixes the issue with QuickTime.
ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=nokey=1:noprint_wrappers=1 input.mp4
ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=nokey=1:noprint_wrappers=1 input.mp4
ffmpeg -i <infile> -c:v libx265 -crf 28 -c:a copy -tag:v hvc1 -preset slow <outfile>
ffmpeg -i <infile> -c:v libx265 -crf 28 -c:a aac -b:a 128k -tag:v hvc1 -preset slow <outfile>
Transcode a folder of AVI files:
for filename in *.avi; do
ffmpeg -i $filename -c:v libx265 -crf 28 -c:a aac -b:a 128k -tag:v hvc1 -preset slow "${filename%.*}.hvc1.mp4"
done
Avoid converting videos already encoded as HVC1.
for filename in *.{avi,mpeg,mp4,webm}; do
# Get codecs
video_codec=$(ffprobe -v error -select_streams 'v:0' -show_entries stream=codec_name -of default=nokey=1:noprint_wrappers=1 "${filename}")
audio_codec=$(ffprobe -v error -select_streams 'a:0' -show_entries stream=codec_name -of default=nokey=1:noprint_wrappers=1 "${filename}")
if [ "$video_codec" = "hevc" ]; then
echo "Skipping (already HVC1): ${filename}"
else
#video_opts="-c:v libx265 -crf 28 -tag:v hvc1 -preset slow"
if [ "$audio_codec" = "aac" ]; then
#audio_opts="-c:a copy"
ffmpeg -i "${filename}" -c:v libx265 -crf 28 -tag:v hvc1 -preset slow -c:a copy "${filename%.*}.hvc1.mp4"
else
#audio_opts="-c:a aac -b:a 128k"
ffmpeg -i "${filename}" -c:v libx265 -crf 28 -tag:v hvc1 -preset slow -c:a aac -b:a 128k "${filename%.*}.hvc1.mp4"
fi
fi
done
nice. I would just add
-tune fastdecode
and-movflags "+faststart"
(and
.mkv
instead of.mp4
).