Videos in H.265 (HEVC) need noticeably less space than in H.264 at a similar quality. ffmpeg converts them on your server, so your computer does not have to. This page converts one file and then a whole folder, with a low priority so that your other programs stay fast. The commands were tested on Ubuntu 26.04 LTS with ffmpeg 8.0; run them as root or as the user who owns the videos.
Older TVs, players and browsers cannot play H.265. Jellyfin and Plex then convert it again while you watch, which costs processor power every time. Convert only if your players handle H.265, and keep the originals until you have checked the result.
1. Install ffmpeg
apt install ffmpeg
2. Convert One File
nice -n 19 ffmpeg -i "Holiday 2025.mp4" -map 0 -c:v libx265 -crf 26 -preset medium -c:a copy -c:s copy "Holiday 2025.mkv"
nice -n 19: the lowest priority, so that the conversion uses only the processor time that nothing else needs.-map 0: keep all tracks of the file, for example several audio languages and subtitles.-c:v libx265: convert the picture to H.265.-crf 26sets the quality: lower numbers give better quality and bigger files; 22 to 28 is a usual range.-preset medium: the balance between speed and size.slowgives smaller files and takes longer,fastthe opposite.-c:a copy -c:s copy: take sound and subtitles over unchanged.
While it runs, ffmpeg shows the progress: the time already done and the speed. For example, a 20-second Full HD clip of a test picture takes 26 seconds on a 4-core Xeon and shrinks from 20.5 MB to 12.9 MB. Real films shrink by different amounts, so try one first.
Check the result: ffprobe -v error -show_entries stream=codec_name -of csv=p=0 "Holiday 2025.mkv" lists hevc for the picture, and the duration should be the same as before.
3. A Whole Folder
Save this script, for example as /usr/local/bin/convert-h265, and change the two folders:
#!/bin/bash
# Converts every video in IN to H.265 into OUT; skips files that are already done.
IN=/srv/media/to-convert
OUT=/srv/media/converted
for f in "$IN"/*.mp4 "$IN"/*.mkv; do
[ -e "$f" ] || continue
name=$(basename "${f%.*}")
[ -e "$OUT/$name.mkv" ] && continue
nice -n 19 ffmpeg -nostdin -v error -i "$f" -map 0 -c:v libx265 -crf 26 -preset medium -c:a copy -c:s copy "$OUT/$name.mkv" && echo "done: $name"
done
chmod 755 /usr/local/bin/convert-h265 convert-h265
The script converts each file once; when you run it again, it skips the files that are already in the output folder. The encoder still prints a few lines starting with x265 [info]; that is normal.
A large folder takes hours. Start it inside tmux, so that it continues when you close SSH: Keep a Program Running on Linux.
Prefer a web page that does this for your whole library? On App Hosting, Tdarr does it: Tdarr: Convert Your Videos Automatically to Save Space.