MediaCli is a comprehensive multimedia file processing CLI tool. Specifically designed for photographers and media collectors, it leverages powerful tools like ffmpeg and exiftool to efficiently compress, convert, organize, rename, and manage image, video, and audio files.
- Smart Organization: Organize photos and videos by date (EXIF metadata or file attributes).
- Batch Processing: Compress images, convert videos/audio, and rename files in bulk.
- File Management: Intelligent file moving, deletion, and directory flattening.
- Encoding Fixes: Detect and fix filename encoding issues (e.g., GBK, Shift-JIS) and smart unzip.
- Raw Workflow: Utilities to manage RAW + JPEG workflows.
Install globally via npm:
npm install mediac -gOr run locally:
git clone https://github.com/mcxiaoke/media-cli.js.git
cd media-cli.js
npm install
npm start -- --helpBasic usage syntax:
mediac <command> <input> [options]To see help for a specific command:
mediac <command> --helpThis table is generated from the registered yargs commands (
node mediac --help). The previously listedorganize/ozcommand does not exist.
| Command | Aliases | Description |
|---|---|---|
compress |
cs, cps |
Compress images to target size/quality while preserving metadata. |
dcimr |
dm, dcim |
Rename media files based on EXIF Date/Time or file attributes. |
decode |
dc |
Decode text containing messy or invalid characters. |
execute [input] |
run |
Run standalone tasks — registered as a placeholder, not implemented yet. |
ffmpeg |
transcode, aconv, vconv, avconv |
Convert video/audio using FFmpeg presets. |
lrmove |
lv |
Move JPEG files that have matching RAW files to a separate folder. |
move |
md |
Move files to folders based on date patterns in filenames. |
moveup |
mp |
Flatten directories by moving files to parent/top folders. |
pick |
pk |
Smart photo selection for photo journals (filters by time/date distribution). |
prefix |
pf, px |
Batch rename by prepending directory names or custom strings. |
remove |
rm, rmf |
Delete files matching specific size, resolution, or name patterns. |
rename |
fn, fxn |
Advanced rename (fix encoding, regex replace, char cleanup, TC to SC). |
test (default) |
tt |
No-op command used to smoke-test the CLI. |
zipu |
zipunicode |
Smart Unzip detecting filename encoding automatically. |
mediac ffmpeg <input> (aliases transcode / aconv / vconv / avconv) transcodes video and
audio using presets, driven by a hardware-acceleration-aware engine. See
docs/FFMPEG-USAGE.md for the full parameter reference and caveats.
Key points that reflect the current implementation:
- Dry-run by default. Without
--doitthe command only scans files, picks the hardware tier, builds the command and logs it — it writes nothing. Add--doitto actually transcode. --presetis required (no default). List available presets with--show-presets.- Automatic hardware tiering. Per file it probes CUDA / QSV / AMF / D3D11VA / software-decode+
hardware-encode / pure CPU and gracefully degrades; the encoder is chosen by the resolved tier
plus the preset's output codec family (never by input bit depth). Use
--hwaccel/--decode-modeto steer it, and--strictto disable every fallback (unsupported files are skipped, not retried). - Presets are YAML, layered & inheritable. Built-in single source is
presets/default.yaml(h264 / hevc / av1 / vp9 / audio families); user layers live in~/.mediac/presets.yamland./presets.yaml. Overriding a built-in name requires an explicit_override: true. - Append-style overrides.
--video-args/--audio-args/--filtersare appended to the preset's blocks (later ffmpeg option wins) instead of replacing them;--video-argsmust not contain-c:v(change the encoder with--video-codecor--ffargs "vc=..."). - Dedicated
--metadatachannel whose values may contain spaces;--ffargsuses;:#as key/value separators (not commas). - Built-in safety rails. Smart bitrate (never exceeds source, never upscales), temp-file writes
with interrupt cleanup, and
--delete-source-filesonly removes the source when a non-empty output exists (moved to the Recycle Bin after confirmation; never in dry-run).
# preview the exact command, then run it
mediac ffmpeg ./video.mp4 --preset hevc_2k
mediac ffmpeg ./video.mp4 --preset hevc_2k --doitThe decode command is used to identify and fix encoding issues in text, particularly for filenames or text content that appears garbled due to encoding mismatches.
mediac decode [strings...] [options]| Option | Alias | Type | Description |
|---|---|---|---|
--from-enc |
-f |
string | Source encoding to try first |
--to-enc |
-t |
string | Target encoding to convert to |
--files |
-i |
array | Files to process (supports wildcards) |
--recursive |
-r |
boolean | Recursively process files in subdirectories |
-
Decode a single garbled string:
mediac decode "乱码字符串" -
Decode multiple strings:
mediac decode "乱码1" "乱码2" "乱码3"
-
Decode with specific encoding settings:
mediac decode --from-enc gbk --to-enc utf8 "乱码字符串" -
Decode files:
mediac decode --files *.txt -
Recursively decode files in subdirectories:
mediac decode --files **/*.txt --recursive
The decode command supports a wide range of encodings, including:
- UTF-8, UTF-16, UTF-32
- GBK, BIG5
- SHIFT_JIS, EUC-JP
- EUC-KR, CP949
- ISO-8859-1, ISO-8859-2
The decode command uses an intelligent approach to detect and fix encoding issues:
- It first analyzes the input text to identify potential encoding problems
- It then tries different encoding combinations to find the best match
- It evaluates the quality of each decoding attempt
- It returns the best decoding result with confidence scores
This makes it particularly effective for fixing filenames that were encoded in one encoding and displayed in another, a common issue when transferring files between different systems.
- Node.js (v22+,见
package.json的engines) - Tools:
ffmpeg,ffprobe,exiftoolmust be installed and available in PATH for full functionality.
npm run check: Verify syntax.npm run lint: Lint code with ESLint.npm run test:package: Pack, install, and smoke-test the published CLI artifact.npm run lint:fix: Fix linting errors.npm run prettier:fix: Format code with Prettier.npm start: Run the CLI locally.
Copyright 2021-2026 @ Zhang Xiaoke.
Licensed under the Apache License 2.0.