setup:

cat /etc/os-release; # tested on
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"

apt install ffmpeg

ffmpeg --version
ffmpeg version 4.3.5-0+deb11u1 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 10 (Debian 10.2.1-6)

howto:

# keep the resolution, simply reencode with x265 (2x smaller)
ffmpeg -i "input.mp4" -vcodec libx265 -crf 28 output.mp4

# reencode with x265 and reduce the resolution by 50% (file size 4.4x smaller)
ffmpeg -i "input.mp4" -vcodec libx265 -crf 28 -vf "scale=trunc(iw/4)*2:trunc(ih/4)*2" output.mp4

script it:

  • this will re-encode all *.mp4 in the current directory
  • video encoding/decoding it a very CPU & energy intense process (if not hardware accelerated)
    • example: depending on resolution of video:
      • AMD-Ryzen-5600G re-encodes x264 to x265 at 1.5x the speed of playback (or ~40fps) while using 125W!
vim /scripts/reencode_x265.sh

#!/bin/bash
echo "=== re encoding all video.mp4 files in the current directory via ffmpeg and x265 ==="
for f in *.mp4 ; do 
   time ffmpeg -i "$f" -vcodec libx265 -crf 20 "$f".x265.recompressed.mp4
done

To scale to half size:

vim /scripts/reencode_x265_half_size.sh

#!/bin/bash
echo "=== re encoding all video.mp4 in the current directory via ffmpeg and x265 plus reducing resolution by HALF! ==="
# for $FILENAME in ./*.mp4; do
for f in *.mp4 ; do
time ffmpeg -i "$f" -vcodec libx265 -crf 20 "$f".x265.recompressed.mp4
   time ffmpeg -i "$f" -vf "scale=trunc(iw/4)*2:trunc(ih/4)*2" -c:v libx265 -crf 28 "$f".half-size.x265.mp4
done

more examples:

ffmpeg -i input.mkv -vf "scale=trunc(iw/4)*2:trunc(ih/4)*2" -c:v libx265 -crf 28 half_the_frame_size.mkv

One third size:

ffmpeg -i input.mkv -vf "scale=trunc(iw/6)*2:trunc(ih/6)*2" -c:v libx265 -crf 28 a_third_the_frame_size.mkv

One quarter size:

ffmpeg -i input.mkv -vf "scale=trunc(iw/8)*2:trunc(ih/8)*2" -c:v libx265 -crf 28 a_fourth_the_frame_size.mkv

One fifth size:

ffmpeg -i input.mkv -vf "scale=trunc(iw/10)*2:trunc(ih/10)*2" -c:v libx265 -crf 28 a_fifth_the_frame_size.mkv

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin