VariaReEncoder / README.md
Newer Older
158 lines | 7.462kb
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

            
Bogdan Timofte authored 2 weeks ago
27
# Long unattended run preset (delete-source + keep-going; also stages input when --staging-dir is set)
Bogdan Timofte authored a month ago
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 2 weeks ago
33
# Flaky NAS/autofs source: copy each source clip to local staging before encode
34
./garmin_varia_transcode.sh -s ~/Autofs/xdev/autonas/ext01/@Camera/import -d ~/Autofs/xdev/autonas/ext00/@Garmin --unattended --staging-dir /Volumes/VARIA_RAM --staging-ramdisk-mb 512 --stage-input
35

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

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

            
43
## Encoding Modes
44

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

            
52
\* Measured on Apple Silicon MacBook Pro.
53

            
54
## CLI Reference
55

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

            
83
## Output Conventions
84

            
85
- Output is always `.mp4`
86
- HEVC outputs tagged `hvc1` (required for Apple Photos / QuickTime)
87
- Directory structure under source is preserved at destination
88
- File timestamps copied from source (`touch -r`)
89

            
90
## Output Format (quiet mode, default)
91

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

            
99
## Safety
100

            
101
- Destination inside source is rejected with an error
Bogdan Timofte authored 2 weeks ago
102
- Source readability and destination writability are checked before staging or
103
  scanning, so stale/inaccessible NFS/autofs mounts fail with an explicit error
Bogdan Timofte authored a month ago
104
- `--delete-source` only deletes source after codec + duration validation passes
Bogdan Timofte authored a month ago
105
- `--dry-run` never writes files
Bogdan Timofte authored a month ago
106
- `Ctrl+C` behavior during long runs:
107
  first press requests stop after current file; second press force-stops current encode
Bogdan Timofte authored 2 weeks ago
108
- Graceful quit between files:
109
  press `q` (or `Q`) during interactive runs to request a graceful stop before
110
  the next file begins. `--unattended` disables `q`/`Q` terminal polling so
111
  buffered terminal input cannot stop long runs accidentally; use `Ctrl+C`.
Bogdan Timofte authored a month ago
112
- On macOS, unreadable MP4/MOV sources automatically try `avconvert --preset PresetPassthrough`
113
  as fallback before being marked as unreadable
114

            
115
Backward-compatible aliases:
116
- `--move-source` maps to `--delete-source`
117
- `--continue-on-error` maps to `--keep-going`
118

            
119
## Media Cleanup Utility
120

            
121
`cleanup_garmin_varia_media_folder.sh` is a companion utility for import and transcoded media folders.
122

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

            
131
Usage:
132

            
133
```bash
134
# Preview only
135
./cleanup_garmin_varia_media_folder.sh --dry-run ~/Autofs/xdev/autonas/ext01/@Camera/import
136

            
137
# Apply changes
138
./cleanup_garmin_varia_media_folder.sh ~/Autofs/xdev/autonas/ext01/@Camera/import
139

            
140
# Example on transcoded output folder
141
./cleanup_garmin_varia_media_folder.sh --dry-run ~/Autofs/xdev/is-baobab/nvme0n1/@backup/Garmin
142
```
143

            
144
Exit codes:
145
- `0`: cleanup completed with no blocked duplicate groups
146
- `1`: cleanup completed but blocked duplicate groups require manual review
147
- `2`: invalid invocation or runtime error
Bogdan Timofte authored a month ago
148

            
149
## Source Files
150

            
151
```
152
SampleFootage/          Original clips (gitignored)
153
Output/                 Transcoded output (gitignored)
154
garmin_varia_transcode.sh   Main script
Bogdan Timofte authored a month ago
155
cleanup_garmin_varia_media_folder.sh   Media cleanup utility (import + transcoded folders)
Bogdan Timofte authored a month ago
156
CHANGELOG.md            Version history
157
DEVLOG.md               Development decisions and rationale
158
```