VariaReEncoder / README.md
Newer Older
152 lines | 6.841kb
Bogdan Timofte authored a month ago
1
# VariaReEncoder
2

            
3
Batch transcoder for Garmin Varia dashcam footage. Converts H.264 source clips to HEVC MP4,
Bogdan Timofte authored a month ago
4
optimized for Apple Photos / QuickTime compatibility.
Bogdan Timofte authored a month ago
5

            
6
## Requirements
7

            
8
- macOS or Linux
9
- `ffmpeg` and `ffprobe` in `PATH` (any recent version with libx265/libx264; videotoolbox on macOS)
10
- Bash 3.2+
11

            
12
## Quick Start
13

            
14
```bash
15
# Transcode everything in SampleFootage → Output (hardware encoder on macOS)
16
./garmin_varia_transcode.sh -s SampleFootage -d Output
17

            
18
# Preview what would happen without writing any files
19
./garmin_varia_transcode.sh -s SampleFootage -d Output --dry-run
20

            
21
# Single file, verbose output
22
./garmin_varia_transcode.sh -s SampleFootage/Day/clip.mp4 -d Output --verbose
23

            
24
# Transcode + delete originals after validation
Bogdan Timofte authored a month ago
25
./garmin_varia_transcode.sh -s SampleFootage -d Output --delete-source
26

            
27
# Long unattended run preset (delete-source + keep-going)
28
./garmin_varia_transcode.sh -s SampleFootage -d Output --unattended
29

            
Bogdan Timofte authored a month ago
30
# NFS destination with local staging for temp outputs
31
./garmin_varia_transcode.sh -s SampleFootage -d ~/Autofs/xdev/is-baobab/nvme0n1/@backup/Garmin --staging-dir /tmp/varia_staging
32

            
Bogdan Timofte authored a month ago
33
# Timing debug: process first 20 files then stop and print final statistics
34
./garmin_varia_transcode.sh -s SampleFootage -d Output --debug-timing 20
35

            
Bogdan Timofte authored a month ago
36
# Media cleanup helper (Apple artifacts, zero-byte MP4, duplicate suffix normalization)
37
./cleanup_garmin_varia_media_folder.sh --dry-run ~/Autofs/xdev/autonas/ext01/@Camera/import
Bogdan Timofte authored a month ago
38
```
39

            
40
## Encoding Modes
41

            
42
| Mode       | Encoder            | Speed (30s clip) | Power\*   | Use when |
43
|------------|--------------------|-----------------|-----------|----------|
44
| `hardware` | hevc_videotoolbox  | ~4-5s           | ~35W      | Default — battery, large libraries, dashcam footage |
45
| `auto`     | videotoolbox → x265 → x264 | varies | varies   | Cross-platform or unknown machine |
46
| `quality`  | libx265 (CRF 20)   | ~50s            | ~80W      | Archival, cinema, complex sources |
47
| `compat`   | libx264 (CRF 19)   | ~30s            | ~70W      | Older TVs, players without HEVC support |
48

            
49
\* Measured on Apple Silicon MacBook Pro.
50

            
51
## CLI Reference
52

            
53
```
54
Options:
55
  -s, --source, --input DIR       Source directory or single file (default: current directory)
56
  -d, --destination, --output DIR Destination directory (default: current directory)
Bogdan Timofte authored a month ago
57
  --staging-dir DIR               Temporary staging directory for intermediate output files
Bogdan Timofte authored a month ago
58
                                  Falls back to destination temp files if staging is unavailable
59
                                  or does not have enough free space for current file
60
  --staging-ramdisk-mb N          RAM disk size in MB when auto-creating missing /Volumes staging
61
                                  directory on macOS (default: 8192)
62
  --debug-timing N                Process at most N video files, then stop and print timing stats
Bogdan Timofte authored a month ago
63
  --mode MODE                     hardware|auto|quality|compat (default: hardware)
64
  --crf N                         CRF for quality/compat modes (lower = better; default: 20/19)
65
  --no-overwrite                  Skip files that already exist at destination
66
  --dry-run                       Print actions without writing files
67
  --no-recursive                  Process only the top-level source directory
68
  --extensions LIST               Comma-separated extensions (default: mp4,mov,avi,m4v)
69
  --verbose                       Full per-operation logs + ffmpeg/ffprobe output
Bogdan Timofte authored a month ago
70
  --delete-source                 Delete source after strict post-encode validation
71
  --keep-going                    Continue after source-file failures (default: stop)
72
  --unattended                    Preset for long runs: --delete-source + --keep-going
73
  --no-apple-repack-fallback      Disable macOS avconvert fallback for unreadable MP4/MOV sources
74
  --apple-repack-fallback         Enable macOS avconvert fallback (default)
Bogdan Timofte authored a month ago
75
  -h, --help                      Show full help with encoding mode details
76
```
77

            
78
## Output Conventions
79

            
80
- Output is always `.mp4`
81
- HEVC outputs tagged `hvc1` (required for Apple Photos / QuickTime)
82
- Directory structure under source is preserved at destination
83
- File timestamps copied from source (`touch -r`)
84

            
85
## Output Format (quiet mode, default)
86

            
87
```
88
2026-05-04 12:08:00 : Transcoding SampleFootage/Day/2026-04-04_18-10-36.mp4 ... done in 5s
89
2026-05-04 12:08:04 : Transcoding SampleFootage/Day/2026-04-04_18-10-05.mp4 ... done in 4s
90
[2026-05-04 12:08:35] [INFO] Summary: videos_processed=10 videos_skipped=0 errors=0
91
[2026-05-04 12:08:35] [INFO] Timing: total_elapsed=44s, video_encode_avg=4s
92
```
93

            
94
## Safety
95

            
96
- Destination inside source is rejected with an error
Bogdan Timofte authored a month ago
97
- `--delete-source` only deletes source after codec + duration validation passes
Bogdan Timofte authored a month ago
98
- `--dry-run` never writes files
Bogdan Timofte authored a month ago
99
- `Ctrl+C` behavior during long runs:
100
  first press requests stop after current file; second press force-stops current encode
Bogdan Timofte authored a month ago
101
 - Graceful quit between files:
102
   Press `q` (or `Q`) between files to request a graceful stop before the next
103
   file begins. The program consumes the keypress (it is not echoed) so you can
104
   press `q` while an encode is running and it will be honored once that encode
105
   finishes.
Bogdan Timofte authored a month ago
106
- On macOS, unreadable MP4/MOV sources automatically try `avconvert --preset PresetPassthrough`
107
  as fallback before being marked as unreadable
108

            
109
Backward-compatible aliases:
110
- `--move-source` maps to `--delete-source`
111
- `--continue-on-error` maps to `--keep-going`
112

            
113
## Media Cleanup Utility
114

            
115
`cleanup_garmin_varia_media_folder.sh` is a companion utility for import and transcoded media folders.
116

            
117
What it does:
118
- Removes AppleDouble artifacts (`._*`) up to 4096 bytes
119
- Removes zero-size `.mp4` files
120
- Normalizes duplicate timestamp files:
121
  if `YYYY-MM-DD_HH-MM-SS.mp4` is missing and exactly one
122
  `YYYY-MM-DD_HH-MM-SS_<n>.mp4` exists, it renames it to base name
123
- Reports blocked duplicate groups when base exists or multiple suffixed duplicates exist
124

            
125
Usage:
126

            
127
```bash
128
# Preview only
129
./cleanup_garmin_varia_media_folder.sh --dry-run ~/Autofs/xdev/autonas/ext01/@Camera/import
130

            
131
# Apply changes
132
./cleanup_garmin_varia_media_folder.sh ~/Autofs/xdev/autonas/ext01/@Camera/import
133

            
134
# Example on transcoded output folder
135
./cleanup_garmin_varia_media_folder.sh --dry-run ~/Autofs/xdev/is-baobab/nvme0n1/@backup/Garmin
136
```
137

            
138
Exit codes:
139
- `0`: cleanup completed with no blocked duplicate groups
140
- `1`: cleanup completed but blocked duplicate groups require manual review
141
- `2`: invalid invocation or runtime error
Bogdan Timofte authored a month ago
142

            
143
## Source Files
144

            
145
```
146
SampleFootage/          Original clips (gitignored)
147
Output/                 Transcoded output (gitignored)
148
garmin_varia_transcode.sh   Main script
Bogdan Timofte authored a month ago
149
cleanup_garmin_varia_media_folder.sh   Media cleanup utility (import + transcoded folders)
Bogdan Timofte authored a month ago
150
CHANGELOG.md            Version history
151
DEVLOG.md               Development decisions and rationale
152
```