Vid Cleaner
Tools to transcode, inspect, and convert videos. vid-cleaner is a command-line wrapper around ffmpeg and ffprobe that removes unwanted tracks, converts codecs, and finds or checks video files in a library. It is built for my own workflows, and I share it in case it is useful to others.
Features
- Remove unwanted audio and subtitle tracks, optionally keeping the original language audio track
- Remove commentary, SDH, and description tracks
- Determine a video's original language from its filename, its container metadata, or the TMDb, Radarr, and Sonarr APIs
- Convert to H.265 or VP9
- Convert 4k to 1080p
- Add a stereo track to a surround file (5.1, 7.1, or Atmos), with a mix that keeps dialogue clear
- Inspect the streams in a video file
- Create clips from a video file
- Search for video files under a directory that match specific criteria
- Check that video files are valid, and exit non-zero when any file is not
Install
vid-cleaner needs these programs:
Every command except cache needs ffmpeg and ffprobe. If either program is not on PATH, the command stops before it reads a file.
To install vid-cleaner, run one of these commands:
# With uv
uv tool install vid-cleaner
# With pip
python -m pip install --user vid-cleaner
Usage
Run vidcleaner --help to see the commands, and vidcleaner COMMAND --help to see the options of one command. Every command accepts --dryrun (-n), which shows what the command will do without a change to a file.
Every command that reads video files skips the ._ metadata files that macOS writes beside each file it copies to a network share or external disk. This includes ._ files that a shell pattern such as *.mkv adds to the command line.
Inspecting a video file
vidcleaner inspect FILES prints a table of the video, audio, and subtitle streams in each file, with the codec, language, and channel layout of each stream. inspect continues past a file it cannot read and exits 1 at the end. Use --json to print one JSON document for all files instead. The data for one file is at .files[N], with ffprobe's streams and format.
vidcleaner inspect movie.mkv
vidcleaner inspect --json movie.mkv
Cleaning a video file
vidcleaner clean FILES removes the audio and subtitle tracks you do not want, and can convert the video in the same pass. With no options, it keeps the audio tracks in the languages that langs_to_keep names in the configuration file, plus the original language of the video.
clean keeps attachments, such as the fonts that ASS subtitles use. WebM cannot hold attachments, so --vp9 removes them and shows a notice for each one.
# Keep only English audio and convert to H.265
vidcleaner clean --langs=en --h265 movie.mkv
# Add a stereo track and keep every subtitle track
vidcleaner clean --downmix --keep-subs movie.mkv
# Convert a 4k file to 1080p
vidcleaner clean --1080p movie.mkv
These are the options you use most:
| Option | Effect |
|---|---|
-l, --langs |
Languages to keep, as comma-separated ISO 639-1 codes (en,es) |
-H, --h265 |
Convert the video to H.265 |
-V, --vp9 |
Convert the video to VP9, in a WebM container |
-p, --1080p |
Convert a 4k video to 1080p. With --force, a smaller video is upscaled only after you approve it. |
-d, --downmix |
Add a stereo track if the file has none. With --force, replace the stereo track in the language of the surround track. |
-s, --keep-subs |
Keep every subtitle track |
-c, --keep-commentary |
Keep commentary audio tracks. Without this flag, all commentary tracks are removed, also tracks with no language tag. |
-f, --force |
Process the file even if it is already in the requested format |
Each on-or-off option in the Configuration group of vidcleaner clean --help also has a --no- form, such as --no-downmix or --no-keep-commentary. Use the --no- form to turn off for one run an option that your configuration file turns on.
Run vidcleaner clean --help for the full list. To act on every file that matches a query, see Cleaning what you searched for.
Making a clip
vidcleaner clip FILES cuts a section out of a video without a new encode. Set the start time with --start and the length with --duration, both in HH:MM:SS format. The defaults are 00:00:00 and one minute.
# A 90-second clip that starts ten minutes in
vidcleaner clip --start=00:10:00 --duration=00:01:30 movie.mkv
Searching for video files
vidcleaner search DIRECTORY finds video files under a directory and prints a table of matches. The directory defaults to the current directory. These options control the search:
--filterskeeps only files with the traits you name. Runvidcleaner search --helpfor the list of traits.--depthsets how many levels of subdirectories to search. The default, 0, searches only the directory itself.--sortorders the results byalpha,size, orbitrate, and--reverseflips the order.--limitkeeps only the first N results after the sort.--jobssets how many files ffprobe reads at the same time. The default is 8. On a network share, a higher value can make the search faster.
# The five largest 4k files, two directories deep
vidcleaner search /media --filters=4k --sort=size --depth=2 --limit=5
If you name several filters, a file must have every trait to match. More filters give fewer results.
vid-cleaner keeps the ffprobe result for each file in the cache. If the size and the modification time of a file do not change, the next search uses the result in the cache and does not read the file again. A second search of a large library is fast because of this. vid-cleaner removes the result for a file that no command used in 90 days.
# Only 4k files that also have a 5.1 track and no stereo track to go with it
vidcleaner search /media --filters=4k,surround5,needs_stereo
Cleaning what you searched for
clean accepts the same query options as search, so a search command is a preview of the clean command that acts on the same files. To change a search command into a clean command, replace the directory with --from DIRECTORY:
# Preview
vidcleaner search /media --filters=4k --sort=size --limit=5
# Act on exactly that selection
vidcleaner clean --from /media --filters=4k --sort=size --limit=5 --h265
clean shows the same table as search, then asks you to confirm before it changes a file. The prompt tells you if each original gets a backup or is replaced in place. In scripts and cron jobs, use --yes to skip the prompt. If there is no terminal and you do not give --yes, the command stops with an error.
These rules apply to --from:
--frommust name a directory that exists.- You cannot use
--fromtogether with file paths or with--out. --yesand the query options (--filters,--sort,--reverse,--depth,--limit,--jobs) work only with--from.--limitand--jobsmust be 1 or more.
Where the output goes
clean and clip replace the file you give them. The original file gets a new name with a timestamp and a .bak extension, in the same directory. To write the result to a different location and keep the input unchanged, use --out PATH. --out works only with one input file.
CAUTION: Do not use
--overwriteunless you have a copy of the original.--overwritereplaces the original with no backup.
overwrite = true in the configuration file has the same effect as --overwrite. To keep a backup for one run, use --no-overwrite.
--vp9 writes a new file, because VP9 must go in a WebM container. vidcleaner clean --vp9 movie.mkv writes movie.webm in the same directory and keeps movie.mkv. With --overwrite, the command deletes movie.mkv.
If one file fails when you clean or clip several files, the command continues with the other files. At the end, it lists the failures and exits with a non-zero status. clean and clip refuse a file that has no video stream.
Ctrl-C, kill, docker stop, and systemctl stop stop the run, delete its temporary files, and exit with status 1. The command also stops when you close its terminal, unless you started it with nohup.
Checking the output
Before clean or clip replaces the original, the command checks the new file. The --verify option sets the level, for example --verify=full. The default level is quick. To change the default, set verify in the configuration file.
off: no check.quick: reads the new file and makes sure that it has a video stream, the expected number of audio and subtitle streams, and the expected length.full: does thequickcheck, then decodes the whole file. This check takes minutes for each file.
If the check fails, the command keeps the original, reports the file as failed, and continues with the next file. A dry run does not check anything, because it writes no file.
Checking that files are valid
vidcleaner check reports if each video file is valid. If a file is not valid, the command exits 1. Use it to find damaged and mislabeled files in a library.
# Two files named directly
vidcleaner check movie.mkv other.mp4
# Every video file in a library, three levels deep
vidcleaner check --from /media --depth=3
The command prints one line for every file, so one invalid file does not hide the state of the others.
✓ movie.mkv
✗ broken.mkv Invalid data found when processing input
✗ audiobook.mkv no video stream
✗ notes.txt not a video file
Checked 4 file(s): 1 valid, 3 invalid
A file is valid when all of these conditions are true:
- The file exists.
- The file has a video container extension.
- ffprobe can read the file.
- The file has a minimum of one video stream.
Cover art does not count as a video stream. An audio-only file with an embedded poster is invalid.
The command prints valid files to stdout and invalid files to stderr. To hide the invalid files, run vidcleaner check FILES 2>/dev/null. With --json, all per-file lines go to stderr and stdout holds only the JSON document.
By default, the command reads only the metadata of each file, which takes milliseconds. To decode every frame instead, use --deep. A deep check finds damage in the body of a file that has a correct header. It takes minutes for each file.
# Fully decode every 4k file to find damage that ffprobe cannot see
vidcleaner check --from /media --filters=4k --deep
check accepts the same query options as search, except --limit. A limit can leave files unchecked while the command exits 0. A trait filter never hides an invalid file, because the filter applies only to files that ffprobe can read.
JSON output for scripts
inspect, search, check, and clean accept --json. Each run prints one JSON document to stdout. All other output, such as progress bars and tables, goes to stderr. The exit codes are the same as without --json.
Every document has the same top-level keys:
schema_version: the integer1. It increases when a field is removed or changes meaning.command: the command that ran.dry_run:truewhen the run used-n.interrupted:truewhen Ctrl-C or a signal stopped the run.filesholds the files that finished.error: why the run stopped before it processed a file or crashed, ornull. A file that fails is reported in its own entry.summary: counts for the run.files: one entry for each file.
Each command fills files in its own way:
inspectandsearch: each entry has the file'spath,name,size, and ffprobe'sstreamsandformat.searchentries also havetraits,matches, andbitrate. Files that cannot be read are in a separateskippedlist, each with apathand areason.searchalso returns thequerythat selected the files.check: each entry has the file'spath,ok, and thereasonit is invalid.clean: see below.
For clean, each entry has a status:
cleaned: the file was written.resultdescribes the new file.unchanged: the file needs no changes, so ffmpeg does not run. A dry run reports this status too.failed: the file was skipped.reasonsays why.planned: a dry run.planned_streamslists the streams the run would write.
A script cannot answer the confirmation prompt. With clean --from, add --yes.
# List the files that failed to clean
vidcleaner clean --json --from /media --yes | jq '.files[] | select(.status == "failed") | .path'
Configuration
The configuration file ~/.config/vid-cleaner/config.toml sets the defaults for clean and clip. If the file does not exist, vid-cleaner creates it with the defaults below the first time it runs. Only your user account can read the file, because it can hold API keys. If other users can read a file that holds API keys, vid-cleaner shows a warning with the chmod command that corrects it.
vid-cleaner gets each setting from the first of these sources that sets it:
- A command-line flag, such as
--downmixor--no-downmix. - An environment variable with the
VIDCLEANER_prefix and the key in uppercase. For example,VIDCLEANER_TMDB_API_KEYsetstmdb_api_key. - The configuration file.
An environment variable for an on-or-off setting takes true, false, 1, or 0. An environment variable for langs_to_keep takes a comma-separated list, such as VIDCLEANER_LANGS_TO_KEEP=en,fr, or a TOML array, such as VIDCLEANER_LANGS_TO_KEEP='["en", "fr"]'. vid-cleaner ignores an empty environment variable.
If a setting has a value that is not valid, clean, clip, and cache stop and list each setting that is not valid, with its source. The other commands read no setting except cache_dir, so they continue to work. If cache_dir is not valid, search and check read every file with ffprobe and do not use the cache. If the file has a key that vid-cleaner does not know, vid-cleaner shows a warning and ignores the key.
vid-cleaner uses the original language of a video to select the audio and subtitle tracks to keep. To find that language, it looks for an IMDb or TMDB ID in three places, and stops at the first one that it finds:
- The filename, matching either a bare
tt0245712or the{tmdb-55}naming convention. - The
IMDBandTMDBmetadata tags in the container, as tools such as mkvmerge write them. - A Radarr or Sonarr title search.
The first two places need only tmdb_api_key. To use the Radarr or Sonarr title search when the first two places have no ID, set the radarr_ or sonarr_ keys.
# Languages to keep (list of ISO 639-1 codes)
langs_to_keep = ["en"]
# Keep subtitles matching the local language(s) even when the audio is not in the local language(s)
keep_local_subtitles = false
# Keep commentary audio
keep_commentary = false
# Force dropping local subtitles even if audio is not default language
drop_local_subs = false
# Keep all subtitles
keep_all_subtitles = false
# Drop original language audio if not specified in langs_to_keep
drop_original_audio = false
# Always create a stereo track
downmix_stereo = false
# Replace the original file without keeping a timestamped .bak copy
overwrite = false
# Check the new file before it replaces the original: "off", "quick", or "full"
verify = "quick"
# External services used to determine the original language of a movie or TV show
radarr_api_key = ""
radarr_url = ""
sonarr_api_key = ""
sonarr_url = ""
tmdb_api_key = ""
File locations
vid-cleaner keeps its files in the locations that the XDG Base Directory specification defines:
- Configuration file:
~/.config/vid-cleaner/config.toml, or$XDG_CONFIG_HOME/vid-cleaner/config.tomlifXDG_CONFIG_HOMEis set - Cache:
~/.cache/vid-cleaner, or$XDG_CACHE_HOME/vid-cleanerifXDG_CACHE_HOMEis set. To use a different directory, setcache_dirin the configuration file orVIDCLEANER_CACHE_DIR.
The cache holds temporary files from clean and clip, and the ffprobe results that search, check --from, and clean --from use again. To print the contents of the cache, run vidcleaner cache. To empty the cache, run vidcleaner cache --clear.
Before clean encodes a file, it makes sure that the cache disk and the destination disk each have free space of at least 1.5 times the size of the original file. The extra space allows for a result that is larger than the original, for example after an upscale. If the cache and the destination are on the same disk, that disk needs 3 times the size of the original file. If there is not sufficient space, clean skips the file and continues with the next file.
If clean or clip cannot copy a finished file to its destination, for example because the disk is full, the command keeps the file in the cache. The error message shows the path. Move the file to where you want it, then run vidcleaner cache --clear.
Contributing
To set up a development environment and run the checks, read CONTRIBUTING.md.
Metadata
Release files for vid-cleaner 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vid_cleaner-1.0.0.tar.gz | 116.2 kB | Without provenance | Details for vid_cleaner-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vid_cleaner-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for vid_cleaner-1.0.0-py3-none-any.whl |
Total release size: 227.6 kB
Release files / vid_cleaner-1.0.0.tar.gz
| Download URL | vid_cleaner-1.0.0.tar.gz |
|---|---|
| Size | 116.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
383956227f8301f080228c0fb39ab162a9fc971165304565aaf55ddfc116dbbc
|
|
BLAKE2b-256 checksum How to use checksums |
c086df7c13bbe73627f7482410e2822f27e9fcde9e4455d6705c1ecd8e990d28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / vid_cleaner-1.0.0-py3-none-any.whl
| Download URL | vid_cleaner-1.0.0-py3-none-any.whl |
|---|---|
| Size | 111.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
81fb22de6c1d30b1a97d697a7801353ab056df061e8850e633aa3cf3e4af45e7
|
|
BLAKE2b-256 checksum How to use checksums |
914d565e2a1c167f5281a8c80986012548c47e9e1d1ea3101b91f7d235259bb2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for vid-cleaner 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.