Utilities API¶
This page documents helper scripts and repair utilities under vbc/utils/.
Fix VBC Tags¶
Dry-run capable helper for adding missing VBC metadata tags to existing MP4 files.
fix_vbc_tags ¶
Move Error Files¶
Move source MP4 files and matching .err markers into a quarantine directory.
move_err_files ¶
Move source MP4 files that have corresponding .err files in the output directory to /tmp/err.
Input directory is provided by the user; output directory is derived by appending _out to the
input directory name. Relative structure is preserved under /tmp/err. If more than 20 .err files
are found, the script asks for confirmation before moving anything.
safe_move ¶
Move src to dest, creating parents; avoid overwriting existing dest.
Source code in vbc/utils/move_err_files.py
Copy Failed Videos¶
Copy source videos that correspond to .err markers while preserving relative paths.
copy_failed_videos ¶
Copy source videos for failed compressions based on .err files.
This script finds all .err files in the output directory and copies the corresponding source .mp4 files to a new directory, preserving the date subdirectory structure.
copy_failed_videos ¶
Find .err files and copy corresponding source videos.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_dir
|
str
|
Directory with original .mp4 files (e.g., SR) |
required |
error_dir
|
str
|
Directory with .err files (e.g., SR_out) |
required |
destination_dir
|
str
|
Destination directory (e.g., SR_new) |
required |
Source code in vbc/utils/copy_failed_videos.py
FLV Repair¶
High-level FLV repair wrapper for corrupted inputs.
flv_repair ¶
repair_flv_file ¶
Repairs a FLV/MP4 file by removing the text error prefix and saving as a clean .flv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_path
|
Path
|
Path to the corrupted file. |
required |
output_path
|
Path
|
Path where the repaired .flv file should be saved. |
required |
keep_intermediate
|
Ignored in this version as we produce only one file. |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
True if repair was successful, False otherwise. |
Source code in vbc/utils/flv_repair.py
FLV Repair Core¶
Byte-level helpers for finding FLV headers and copying repaired payloads.
flv_repair_core ¶
find_flv_header_offset ¶
Return byte offset of the first FLV header marker in file.
Prefers exact FLV header prefix b"FLV\x01" and falls back to b"FLV".
Returns None when no marker is found.
Source code in vbc/utils/flv_repair_core.py
copy_from_offset ¶
copy_from_offset(input_path: Path, output_path: Path, offset: int, chunk_size: int = 1024 * 1024) -> int
Copy file data starting from offset into output_path.
Returns number of bytes written.
Source code in vbc/utils/flv_repair_core.py
Re-encode Repair¶
Fallback repair helper that re-encodes damaged files through ffmpeg.
reencode_repair ¶
repair_via_reencode ¶
repair_via_reencode(input_path: Path, output_path: Path, progress_callback: Optional[Callable[[int], None]] = None) -> bool
Repairs a corrupted video file by performing a fast re-encode to MKV with fixed framerate. Useful for files with broken indices, variable framerate issues, or 'ffmpeg code 234' errors.
Command: ffmpeg -i input -c:v libx264 -preset ultrafast -crf 20 -r 30 -c:a copy output.mkv
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_path
|
Path
|
Path to the corrupted file. |
required |
output_path
|
Path
|
Path where the repaired .mkv file should be saved. |
required |
progress_callback
|
Optional[Callable[[int], None]]
|
Optional callback receiving the current output size in bytes. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if repair was successful and validated, False otherwise. |
Source code in vbc/utils/reencode_repair.py
Audio Consistency Check¶
Command-line verifier for input/output audio codec handling.
check_audio_consistency ¶
Check audio handling between input and output directories.
Compares input audio codecs to expected output behavior based on VBC rules: - Lossless (pcm_*, flac, alac, truehd, mlp, wavpack, ape, tta) -> AAC 256k - AAC/MP3 -> stream copy - Other/unknown -> AAC 192k - No audio -> no audio