VariaReEncoder / README.md
Newer Older
143 lines | 6.289kb
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,
4
optimized for Apple Photos / QuickTime compatibility, with sidecar JSON copy and a telemetry
5
manifest placeholder for a future FIT sync pipeline.
6

            
7
## Requirements
8

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

            
13
## Quick Start
14

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

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

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

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

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

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

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

            
38
## Encoding Modes
39

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

            
47
\* Measured on Apple Silicon MacBook Pro.
48

            
49
## CLI Reference
50

            
51
```
52
Options:
53
  -s, --source, --input DIR       Source directory or single file (default: current directory)
54
  -d, --destination, --output DIR Destination directory (default: current directory)
Bogdan Timofte authored a month ago
55
  --staging-dir DIR               Temporary staging directory for intermediate output files
56
                                  Falls back to destination temp files if staging cannot be used
Bogdan Timofte authored a month ago
57
  --mode MODE                     hardware|auto|quality|compat (default: hardware)
58
  --crf N                         CRF for quality/compat modes (lower = better; default: 20/19)
59
  --no-overwrite                  Skip files that already exist at destination
60
  --dry-run                       Print actions without writing files
61
  --no-recursive                  Process only the top-level source directory
62
  --extensions LIST               Comma-separated extensions (default: mp4,mov,avi,m4v)
63
  --verbose                       Full per-operation logs + ffmpeg/ffprobe output
Bogdan Timofte authored a month ago
64
  --delete-source                 Delete source after strict post-encode validation
65
  --keep-going                    Continue after source-file failures (default: stop)
66
  --unattended                    Preset for long runs: --delete-source + --keep-going
67
  --no-apple-repack-fallback      Disable macOS avconvert fallback for unreadable MP4/MOV sources
68
  --apple-repack-fallback         Enable macOS avconvert fallback (default)
Bogdan Timofte authored a month ago
69
  -h, --help                      Show full help with encoding mode details
70
```
71

            
72
## Output Conventions
73

            
74
- Output is always `.mp4`
75
- HEVC outputs tagged `hvc1` (required for Apple Photos / QuickTime)
76
- Directory structure under source is preserved at destination
77
- File timestamps copied from source (`touch -r`)
78
- JSON sidecars copied 1:1 to destination
79
- `telemetry_manifest.json` written to destination as a placeholder for a future FIT sync pipeline
80

            
81
## Output Format (quiet mode, default)
82

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

            
90
## Safety
91

            
92
- Destination inside source is rejected with an error
Bogdan Timofte authored a month ago
93
- `--delete-source` only deletes source after codec + duration validation passes
Bogdan Timofte authored a month ago
94
- `--dry-run` never writes files
Bogdan Timofte authored a month ago
95
- `Ctrl+C` behavior during long runs:
96
  first press requests stop after current file; second press force-stops current encode
97
- On macOS, unreadable MP4/MOV sources automatically try `avconvert --preset PresetPassthrough`
98
  as fallback before being marked as unreadable
99

            
100
Backward-compatible aliases:
101
- `--move-source` maps to `--delete-source`
102
- `--continue-on-error` maps to `--keep-going`
103

            
104
## Media Cleanup Utility
105

            
106
`cleanup_garmin_varia_media_folder.sh` is a companion utility for import and transcoded media folders.
107

            
108
What it does:
109
- Removes AppleDouble artifacts (`._*`) up to 4096 bytes
110
- Removes zero-size `.mp4` files
111
- Normalizes duplicate timestamp files:
112
  if `YYYY-MM-DD_HH-MM-SS.mp4` is missing and exactly one
113
  `YYYY-MM-DD_HH-MM-SS_<n>.mp4` exists, it renames it to base name
114
- Reports blocked duplicate groups when base exists or multiple suffixed duplicates exist
115

            
116
Usage:
117

            
118
```bash
119
# Preview only
120
./cleanup_garmin_varia_media_folder.sh --dry-run ~/Autofs/xdev/autonas/ext01/@Camera/import
121

            
122
# Apply changes
123
./cleanup_garmin_varia_media_folder.sh ~/Autofs/xdev/autonas/ext01/@Camera/import
124

            
125
# Example on transcoded output folder
126
./cleanup_garmin_varia_media_folder.sh --dry-run ~/Autofs/xdev/is-baobab/nvme0n1/@backup/Garmin
127
```
128

            
129
Exit codes:
130
- `0`: cleanup completed with no blocked duplicate groups
131
- `1`: cleanup completed but blocked duplicate groups require manual review
132
- `2`: invalid invocation or runtime error
Bogdan Timofte authored a month ago
133

            
134
## Source Files
135

            
136
```
137
SampleFootage/          Original clips (gitignored)
138
Output/                 Transcoded output (gitignored)
139
garmin_varia_transcode.sh   Main script
Bogdan Timofte authored a month ago
140
cleanup_garmin_varia_media_folder.sh   Media cleanup utility (import + transcoded folders)
Bogdan Timofte authored a month ago
141
CHANGELOG.md            Version history
142
DEVLOG.md               Development decisions and rationale
143
```