Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

av1-reencode

Re-encode video files to AV1 or HEVC to save disk space. Prefers hardware encoders when available and falls back to software.

Requirements

  • ffmpeg (with ffprobe)
  • Optionally python3, used to read Google Takeout .supplemental-metadata.json sidecars and embed the capture time and GPS location.

Hardware encoding needs a VAAPI render node (/dev/dri/renderD128) or a Vulkan device with the matching ffmpeg encoders built in.

Encoder selection

The script picks the first encoder available, in this order:

  1. av1_vaapi — VAAPI hardware AV1 (needs the VAAPI device)
  2. hevc_vaapi — VAAPI hardware HEVC
  3. hevc_vulkan — Vulkan hardware HEVC
  4. libx265 — software HEVC

Pass --hevc to skip AV1 and start from hevc_vaapi.

When a hardware encoder can't decode the source codec (some drivers reject older formats such as wmv3), the encode is retried with software decode while still encoding on the GPU.

Usage

./av1-reencode.sh [OPTIONS] [FILE_OR_DIR ...]

With no path arguments it processes the current directory. Directories are scanned one level deep for .mp4, .wmv, .avi, .mkv, .mov, .mpeg, and .mpg files, and you're asked to confirm before a batch runs.

Output is written next to each source as NAME<suffix>.mp4 (suffix .av1 or .hevc depending on the encoder), or into --outdir if given.

Options

Option Description
-q, --quality N Quality. Default 120 for AV1 (global_quality, 0=lossless, 255=worst), 28 for HEVC (0=lossless, 51=worst).
-p, --preset NAME libx265 preset for software encode (default: medium).
-s, --suffix SUF Output suffix before .mp4 (default: auto, .av1 or .hevc).
-o, --outdir DIR Write outputs to DIR instead of alongside the source.
-a, --audio-br BR Re-encode audio to AAC at this bitrate, e.g. 128k (default: copy source audio when possible).
-r, --replace Replace the source with the output if the output is smaller.
--newer Re-encode when the source is newer than an existing output.
--force Overwrite existing outputs regardless of age.
-n, --dry-run Print what would be done without encoding.
--hevc Force HEVC instead of AV1.
-h, --help Show help.

Audio

Source audio is copied when the codec fits in an MP4 container (aac, mp3, ac3, eac3, alac, opus). Anything else (for example wmav2 or vorbis) is re-encoded to AAC 192k, since copying it would make the muxer reject the stream. Use --audio-br to force AAC at a chosen bitrate for every file.

Skipping and overwriting

By default a source is skipped when its output already exists. --newer re-encodes sources that are newer than their output; --force always overwrites. Files carrying the output suffix are ignored during directory scans so encodes aren't fed back in.

Examples

Re-encode one file:

./av1-reencode.sh clip.mp4

Re-encode a directory into a separate output folder, HEVC, higher quality:

./av1-reencode.sh --hevc -q 24 -o encoded/ ~/Videos

Preview a run without encoding:

./av1-reencode.sh -n ~/Videos

Re-encode in place and replace originals when the result is smaller:

./av1-reencode.sh -r clip.mp4

Notes

  • Outputs are muxed with +faststart for streaming.
  • If an output ends up no smaller than the source, both files are kept.
  • A summary at the end reports how many files were encoded, skipped, and failed, along with the total space saved.

About

Simple script to quickly reencode videos to AV1 or HEVC using VAAPI if available

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages