OpenScrub 1.0.74__tar.gz → 1.0.76__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: OpenScrub
3
- Version: 1.0.74
3
+ Version: 1.0.76
4
4
  Summary: Local, GPU-accelerated redaction for video and screen recordings — blur, black-box, or mosaic faces, names, and any regex-matchable PII, with human review.
5
5
  Project-URL: Homepage, https://github.com/austinmabry/OpenScrub
6
6
  Project-URL: Repository, https://github.com/austinmabry/OpenScrub
@@ -36,7 +36,7 @@ from dataclasses import dataclass, asdict
36
36
  import cv2
37
37
  import numpy as np
38
38
 
39
- VERSION = "1.0.74"
39
+ VERSION = "1.0.76"
40
40
 
41
41
  # ----------------------------------------------------------------------------
42
42
  # OCR backends
@@ -3153,10 +3153,73 @@ def _dedupe_dense(act):
3153
3153
  if not (d.dense and d.track >= 0 and latest[d.track] is not d)]
3154
3154
 
3155
3155
 
3156
+ def _suppress_textless_bands(bands, n_raw_hits):
3157
+ """-> (bands, suppressed). Safety bands exist to cover unscanned TEXT
3158
+ scrolling into view. A scan whose OCR found ZERO text in any sampled
3159
+ frame has proven there is nothing for bands to protect — but camera
3160
+ bob still fakes scroll offsets on handheld footage that
3161
+ probe_camera_motion reads as static (too steady to look like a
3162
+ camera), and a real selfie job (address category, no on-screen text)
3163
+ shipped with a thin phantom blur bar at the bottom edge. With zero
3164
+ text hits there is no text-leak risk to mitigate, so dropping the
3165
+ bands is fail-closed by construction; any text hit at all keeps them
3166
+ untouched."""
3167
+ if n_raw_hits or not any(abs(x) > 2 or abs(y) > 2 for x, y in bands):
3168
+ return bands, False
3169
+ return [(0.0, 0.0)] * len(bands), True
3170
+
3171
+
3172
+ # Output quality tiers (--out-quality): per-encoder constant-quality
3173
+ # values. archival = visually lossless (the historical fixed setting —
3174
+ # a 12s 1080x1920/60 HDR clip came out 142MB, too big to share);
3175
+ # balanced ~ 1/3 the size; share ~ 1/8, still clean for messaging.
3176
+ # OUTPUT renders only — scan copies and HDR intermediates stay
3177
+ # near-lossless (they feed detection and re-renders). HEVC steps are one
3178
+ # larger per tier (its quality scale runs ~1 lower than H.264's).
3179
+ _OUT_QUALITY = {
3180
+ "h264_nvenc": {"archival": "19", "balanced": "24", "share": "29"},
3181
+ "hevc_nvenc": {"archival": "19", "balanced": "25", "share": "30"},
3182
+ "h264_qsv": {"archival": "19", "balanced": "24", "share": "29"},
3183
+ "hevc_qsv": {"archival": "19", "balanced": "25", "share": "30"},
3184
+ "libx264": {"archival": "18", "balanced": "23", "share": "28"},
3185
+ "libx265": {"archival": "18", "balanced": "23", "share": "28"},
3186
+ }
3187
+
3188
+
3189
+ def _out_q(codec, quality):
3190
+ return _OUT_QUALITY.get(codec, _OUT_QUALITY["libx264"]).get(
3191
+ quality or "archival", _OUT_QUALITY[codec]["archival"])
3192
+
3193
+
3194
+ # bits-per-pixel budgets for the size-oriented tiers on NVENC. Constant-
3195
+ # quality NVENC has no size anchor: on noisy 4K/60 HDR footage cq~30
3196
+ # still produced a 123MB 12-second "share" file. A VBR ceiling scaled by
3197
+ # resolution and fps makes the tiers mean something in MB (12s of 4K60
3198
+ # HEVC "share" ≈ 30MB, 1080p30 h264 ≈ 5MB); quality mode still governs
3199
+ # below the ceiling. archival stays pure constant-quality, uncapped.
3200
+ _TIER_BPP = {"balanced": {"h264": 0.14, "hevc": 0.10},
3201
+ "share": {"h264": 0.06, "hevc": 0.04}}
3202
+
3203
+
3204
+ def _rate_cap_args(codec, out_quality, w, h, fps):
3205
+ """-> extra ffmpeg args (possibly []) putting a resolution-scaled
3206
+ bitrate ceiling on NVENC for the balanced/share tiers. Pure —
3207
+ unit-tested. CPU x264/x265 CRF and QSV global_quality already track
3208
+ size predictably and are left alone."""
3209
+ if not codec.endswith("_nvenc"):
3210
+ return []
3211
+ bpp = _TIER_BPP.get(out_quality or "", {}).get(
3212
+ "hevc" if codec.startswith("hevc") else "h264")
3213
+ if not bpp:
3214
+ return []
3215
+ cap = int(w * h * max(1.0, fps) * bpp)
3216
+ return ["-maxrate", str(cap), "-bufsize", str(2 * cap)]
3217
+
3218
+
3156
3219
  def render_hdr(src, dst, detections, cum, bands, fps, pad, mode,
3157
3220
  encoder, tags, band_margin=25, progress_every=60, cb=None,
3158
3221
  mode_map=None, face_shape="ellipse", audio_spans=None,
3159
- mute_tracks=()):
3222
+ mute_tracks=(), out_quality="archival"):
3160
3223
  """render(), but 10-bit end to end: decode the HDR source to raw
3161
3224
  yuv420p10le, blur the planes in place, encode 10-bit HEVC with the
3162
3225
  source's color tags (PQ/HLG + BT.2020) carried over. `hvc1` tagging
@@ -3179,15 +3242,17 @@ def render_hdr(src, dst, detections, cum, bands, fps, pad, mode,
3179
3242
  "-f", "rawvideo", "-pix_fmt", "yuv420p10le", "pipe:1"],
3180
3243
  stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
3181
3244
  bufsize=w * h * 6)
3182
- vargs = (["-c:v", "hevc_nvenc", "-preset", "p4", "-cq", "19",
3245
+ q = _out_q(encoder, out_quality)
3246
+ vargs = (["-c:v", "hevc_nvenc", "-preset", "p4", "-cq", q,
3183
3247
  "-profile:v", "main10", "-pix_fmt", "p010le"]
3184
3248
  if encoder == "hevc_nvenc" else
3185
3249
  ["-c:v", "hevc_qsv", "-preset", "medium",
3186
- "-global_quality", "19", "-profile:v", "main10",
3250
+ "-global_quality", q, "-profile:v", "main10",
3187
3251
  "-pix_fmt", "p010le"]
3188
3252
  if encoder == "hevc_qsv" else
3189
- ["-c:v", "libx265", "-crf", "18", "-preset", "fast",
3253
+ ["-c:v", "libx265", "-crf", q, "-preset", "fast",
3190
3254
  "-pix_fmt", "yuv420p10le"])
3255
+ vargs += _rate_cap_args(encoder, out_quality, w, h, fps)
3191
3256
  targs = [a for kv in (tags or {}).items() for a in kv]
3192
3257
  if os.path.splitext(dst)[1].lower() in (".mp4", ".mov"):
3193
3258
  targs += ["-tag:v", "hvc1"] # QuickTime/Apple compatibility
@@ -3301,7 +3366,7 @@ def render(src, dst, detections, cum, bands, fps, pad, mode, preview,
3301
3366
  encoder="auto", band_margin=25, progress_every=60, cb=None,
3302
3367
  mode_map=None, draw_scores=False, vcodec="h264",
3303
3368
  face_shape="ellipse", audio_spans=None, clip=None,
3304
- mute_tracks=()):
3369
+ mute_tracks=(), out_quality="archival"):
3305
3370
  # mode_map: {category: "blur"|"box"} overrides the global `mode` per
3306
3371
  # category. Lets you black-box the reversible-blur-vulnerable categories
3307
3372
  # (SSN, MRN, account numbers) while blurring faces, in one render.
@@ -3330,20 +3395,22 @@ def render(src, dst, detections, cum, bands, fps, pad, mode, preview,
3330
3395
  cb.log(f" encoder: {codec}"
3331
3396
  + (" (GPU)" if codec.endswith(("_nvenc", "_qsv"))
3332
3397
  else " (CPU)"))
3398
+ q = _out_q(codec, out_quality)
3333
3399
  if codec == "h264_nvenc":
3334
- vargs = ["-c:v", "h264_nvenc", "-preset", "p4", "-cq", "19"]
3400
+ vargs = ["-c:v", "h264_nvenc", "-preset", "p4", "-cq", q]
3335
3401
  elif codec == "hevc_nvenc":
3336
- vargs = ["-c:v", "hevc_nvenc", "-preset", "p4", "-cq", "19"]
3402
+ vargs = ["-c:v", "hevc_nvenc", "-preset", "p4", "-cq", q]
3337
3403
  elif codec == "h264_qsv":
3338
3404
  vargs = ["-c:v", "h264_qsv", "-preset", "medium",
3339
- "-global_quality", "19"]
3405
+ "-global_quality", q]
3340
3406
  elif codec == "hevc_qsv":
3341
3407
  vargs = ["-c:v", "hevc_qsv", "-preset", "medium",
3342
- "-global_quality", "19"]
3408
+ "-global_quality", q]
3343
3409
  elif codec == "libx265":
3344
- vargs = ["-c:v", "libx265", "-crf", "20", "-preset", "fast"]
3410
+ vargs = ["-c:v", "libx265", "-crf", q, "-preset", "fast"]
3345
3411
  else:
3346
- vargs = ["-c:v", "libx264", "-crf", "18", "-preset", "fast"]
3412
+ vargs = ["-c:v", "libx264", "-crf", q, "-preset", "fast"]
3413
+ vargs += _rate_cap_args(codec, out_quality, w, h, fps)
3347
3414
  if codec in ("hevc_nvenc", "hevc_qsv", "libx265") \
3348
3415
  and os.path.splitext(dst)[1].lower() in (".mp4", ".mov"):
3349
3416
  vargs += ["-tag:v", "hvc1"] # QuickTime/Apple compatibility
@@ -4991,11 +5058,35 @@ _STATE_NAMES = (
4991
5058
  r"ohio|oklahoma|oregon|pennsylvania|rhode\s+island|south\s+carolina|"
4992
5059
  r"south\s+dakota|tennessee|texas|utah|vermont|virginia|washington|"
4993
5060
  r"west\s+virginia|wisconsin|wyoming")
5061
+ # ZIP tolerant of ASR number formatting: whisper renders "72211" as
5062
+ # "72,211" (thousands comma) on some builds, and occasionally as spaced/
5063
+ # hyphenated digits ("7 2 2 1 1"). Anchored right after a state name, the
5064
+ # tolerance cannot false-positive on ordinary prose.
5065
+ _ZIP_ASR = r"(?:\d{5}|\d{2},\d{3}|\d(?:[ \-]\d){4})(?:-\d{4})?"
4994
5066
  RE_SPOKEN_STATEZIP = re.compile(
4995
5067
  r"(?i)\b(?:[A-Za-z.'\-]+\s+){0,3}(?:" + _STATE_NAMES +
4996
5068
  r"|AL|AK|AZ|AR|CA|CO|CT|DE|FL|GA|HI|ID|IL|IN|IA|KS|KY|LA|ME|MD|MA|MI|"
4997
5069
  r"MN|MS|MO|MT|NE|NV|NH|NJ|NM|NY|NC|ND|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VT|"
4998
- r"VA|WA|WV|WI|WY)[,\s]+\d{5}(?:-\d{4})?\b")
5070
+ r"VA|WA|WV|WI|WY)[,\s]+" + _ZIP_ASR + r"\b")
5071
+
5072
+ # Street line with a SPOKEN house number: whisper sometimes writes "one
5073
+ # thirteen Main Street" instead of "113 Main Street" — RE_STREET's \d head
5074
+ # can never match that. Number words (1-6 of them) replace the digit head;
5075
+ # the same street-suffix requirement keeps false positives low.
5076
+ _NUMWORDS = (r"(?:zero|oh|one|two|three|four|five|six|seven|eight|nine|ten|"
5077
+ r"eleven|twelve|thir(?:teen|ty)|four(?:teen|ty)|fif(?:teen|ty)|"
5078
+ r"six(?:teen|ty)|seven(?:teen|ty)|eigh(?:teen|ty)|"
5079
+ r"nine(?:teen|ty)|twenty|hundred|thousand)")
5080
+ RE_SPOKEN_STREET = re.compile(r"""(?ix)
5081
+ \b(?:\d{1,6}|""" + _NUMWORDS + r"""(?:[\s\-]+""" + _NUMWORDS + r"""){0,5})\s+
5082
+ (?:[NSEW]\.?\s+|(?:north|south|east|west)\s+)?
5083
+ [A-Za-z0-9.'\-]+(?:\s+[A-Za-z0-9.'\-]+){0,4}?\s+
5084
+ (?:st|street|ave|avenue|blvd|boulevard|rd|road|dr|drive|ln|lane|ct|court|
5085
+ cir|circle|way|pl|place|ter|terrace|pkwy|parkway|hwy|highway|trl|trail|
5086
+ loop|pike|row|run|path|crossing|xing|square|sq)\.?
5087
+ (?:\s+(?:apt|apartment|suite|ste|unit|bldg|building|fl|floor|rm|room)\.?\s*
5088
+ \#?\s*\w+)?
5089
+ \b""")
4999
5090
 
5000
5091
  _SPEECH_CHECKS = (
5001
5092
  ("ssn", lambda s: RE_SSN.search(s)),
@@ -5009,10 +5100,11 @@ _SPEECH_CHECKS = (
5009
5100
  ("crypto", lambda s: RE_ETH.search(s) or RE_BECH32.search(s)),
5010
5101
  # address was MISSING here entirely — an address-only spoken-PII job
5011
5102
  # could never suggest anything (a real user hit exactly that).
5012
- # RE_STREET covers "113 Main Street"; the other two cover the
5013
- # city/state/ZIP tail in written and spoken forms.
5014
- ("address", lambda s: RE_STREET.search(s) or RE_CITYSTATEZIP.search(s)
5015
- or RE_SPOKEN_STATEZIP.search(s)),
5103
+ # RE_SPOKEN_STREET covers the street line (digit AND word-number house
5104
+ # numbers); the other two cover the city/state/ZIP tail in written and
5105
+ # spoken forms.
5106
+ ("address", lambda s: RE_SPOKEN_STREET.search(s)
5107
+ or RE_CITYSTATEZIP.search(s) or RE_SPOKEN_STATEZIP.search(s)),
5016
5108
  )
5017
5109
 
5018
5110
 
@@ -5033,10 +5125,13 @@ def _speech_suggestions(words, cats, nlp=None, custom_res=()):
5033
5125
  out = []
5034
5126
 
5035
5127
  def add(a, b, cat, snip):
5128
+ # ±0.5s pad: whisper word timestamps drift by hundreds of ms
5129
+ # across builds/quantizations, and a 0.35s pad let the first
5130
+ # digit of a spoken house number escape a mute on a real clip.
5036
5131
  wi = idx[max(0, min(a, len(idx) - 1))]
5037
5132
  wj = idx[max(0, min(b - 1, len(idx) - 1))]
5038
- out.append({"t0": round(max(0.0, words[wi][0] - 0.35), 2),
5039
- "t1": round(words[wj][1] + 0.35, 2),
5133
+ out.append({"t0": round(max(0.0, words[wi][0] - 0.5), 2),
5134
+ "t1": round(words[wj][1] + 0.5, 2),
5040
5135
  "category": cat, "text": snip.strip()[:80]})
5041
5136
 
5042
5137
  # regex windows: scan a sliding join so matches can span tokens
@@ -5095,19 +5190,23 @@ def transcribe_audio_pii(video, cats, cb, model_size="base", nlp=None,
5095
5190
  """Fully LOCAL speech-to-PII: extract the audio, transcribe with
5096
5191
  faster-whisper (word timestamps, VAD), and run the text engine's
5097
5192
  patterns over the transcript. Spoken names, numbers and addresses
5098
- leak PII no matter how good the visual blur is. Returns suggestion
5099
- dicts; [] (with a loud note) when faster-whisper is not installed
5100
- or the file has no audio. Nothing leaves the machine."""
5193
+ leak PII no matter how good the visual blur is. Returns
5194
+ (suggestions, transcript) where transcript is [[t0, t1, word], ...]
5195
+ — the review UI shows it with matched spans highlighted so a human
5196
+ can SEE what was heard and mute anything the patterns missed
5197
+ (ASR output varies; the transcript view is the fail-closed check).
5198
+ ([], []) with a loud note when faster-whisper is not installed or
5199
+ the file has no audio. Nothing leaves the machine."""
5101
5200
  try:
5102
5201
  from faster_whisper import WhisperModel
5103
5202
  except ImportError:
5104
5203
  cb.log(" spoken-PII: faster-whisper is not installed — "
5105
5204
  "`pip install faster-whisper` enables local speech "
5106
5205
  "transcription (the Docker images include it)")
5107
- return []
5206
+ return [], []
5108
5207
  if not probe_has_audio(video):
5109
5208
  cb.log(" spoken-PII: no audio track — skipped")
5110
- return []
5209
+ return [], []
5111
5210
  import tempfile
5112
5211
  wav = tempfile.NamedTemporaryFile(suffix=".wav", delete=False).name
5113
5212
  try:
@@ -5117,7 +5216,7 @@ def transcribe_audio_pii(video, cats, cb, model_size="base", nlp=None,
5117
5216
  capture_output=True, text=True)
5118
5217
  if p.returncode != 0:
5119
5218
  cb.log(" spoken-PII: audio extraction failed — skipped")
5120
- return []
5219
+ return [], []
5121
5220
  cb.log(f" spoken-PII: transcribing locally (whisper "
5122
5221
  f"{model_size}, CPU)…")
5123
5222
  model = WhisperModel(
@@ -5136,10 +5235,11 @@ def transcribe_audio_pii(video, cats, cb, model_size="base", nlp=None,
5136
5235
  for s in sugg[:12]:
5137
5236
  cb.log(" %.1f-%.1fs %-8s %s"
5138
5237
  % (s["t0"], s["t1"], s["category"], s["text"]))
5139
- return sugg
5238
+ return sugg, [[round(t0, 2), round(t1, 2), tok]
5239
+ for t0, t1, tok in words]
5140
5240
  except Exception as e:
5141
5241
  cb.log(f" spoken-PII: transcription failed ({e}) — skipped")
5142
- return []
5242
+ return [], []
5143
5243
  finally:
5144
5244
  try:
5145
5245
  os.remove(wav)
@@ -5186,6 +5286,8 @@ def write_report(path, args, state, output_path=None):
5186
5286
  {"t0": a, "t1": b, "mode": m} for a, b, m in aspans]
5187
5287
  if state.get("audio_suggestions"):
5188
5288
  doc["audio_suggestions"] = state["audio_suggestions"]
5289
+ if state.get("audio_transcript"):
5290
+ doc["audio_transcript"] = state["audio_transcript"]
5189
5291
  with open(path, "w", encoding="utf-8") as f:
5190
5292
  json.dump(doc, f, indent=1)
5191
5293
  try:
@@ -5546,6 +5648,12 @@ def build_parser():
5546
5648
  "cropped word/face (default 8)")
5547
5649
  ap.add_argument("--no-vfr-fix", action="store_true",
5548
5650
  help="skip automatic CFR normalization of VFR input")
5651
+ ap.add_argument("--out-quality", choices=["archival", "balanced", "share"],
5652
+ default="archival",
5653
+ help="output file quality/size: archival = visually "
5654
+ "lossless (largest, the default), balanced = ~1/3 "
5655
+ "the size, share = ~1/8 — still clean, sized for "
5656
+ "messaging and upload")
5549
5657
  ap.add_argument("--codec", choices=["h264", "hevc"], default="h264",
5550
5658
  help="video codec for the output: h264 (default, plays "
5551
5659
  "everywhere) or hevc (H.265, smaller files). HDR "
@@ -7070,11 +7178,17 @@ def run_scan(args, cb=None):
7070
7178
  cb.log(" top recalled strings (check for false positives): "
7071
7179
  + ", ".join(f"'{k}'x{v}" for k, v in top))
7072
7180
 
7073
- audio_sugg = []
7181
+ bands, _bsup = _suppress_textless_bands(bands, len(raw))
7182
+ if _bsup:
7183
+ cb.log(" safety bands: suppressed — the scan found no text "
7184
+ "anywhere, so edge bands (which exist to cover unscanned "
7185
+ "text) could only be camera-motion artifacts")
7186
+
7187
+ audio_sugg, audio_tx = [], []
7074
7188
  if getattr(args, "audio_pii", False):
7075
7189
  # spoken names/numbers/addresses leak PII no matter how good the
7076
7190
  # visual blur is — transcribe locally and suggest mute spans
7077
- audio_sugg = transcribe_audio_pii(
7191
+ audio_sugg, audio_tx = transcribe_audio_pii(
7078
7192
  getattr(args, "original_video", None) or args.video, cats, cb,
7079
7193
  model_size=getattr(args, "audio_pii_model", "base") or "base",
7080
7194
  nlp=getattr(namer, "nlp", None) if namer else None,
@@ -7082,6 +7196,7 @@ def run_scan(args, cb=None):
7082
7196
 
7083
7197
  return {"fps": fps, "cum": cum, "bands": bands, "detections": detections,
7084
7198
  "zdropped": zdropped, "audio_suggestions": audio_sugg,
7199
+ "audio_transcript": audio_tx,
7085
7200
  "input_sha256": sha256_file(args.video),
7086
7201
  "stats": {"scans": n_scans, "raw_hits": len(raw),
7087
7202
  "regions": len(detections), "recalls": n_recalled,
@@ -7127,6 +7242,10 @@ def run_render(args, state, cb=None):
7127
7242
  clip = None
7128
7243
  dets_r = apply_coverage(state["detections"],
7129
7244
  getattr(args, "coverage", "tight"), cb)
7245
+ out_q = getattr(args, "out_quality", "archival") or "archival"
7246
+ if out_q != "archival":
7247
+ cb.log(f" output quality: {out_q} (smaller file; archival is "
7248
+ "the visually-lossless default)")
7130
7249
  if getattr(args, "hdr_source", None) and not args.preview:
7131
7250
  render_hdr(args.hdr_source, dst, dets_r, state["cum"],
7132
7251
  state["bands"], state["fps"], pad=args.pad, mode=args.mode,
@@ -7134,7 +7253,8 @@ def run_render(args, state, cb=None):
7134
7253
  tags=getattr(args, "hdr_tags", {}),
7135
7254
  face_shape=getattr(args, "face_shape", "ellipse"),
7136
7255
  mode_map=getattr(args, "mode_map", None),
7137
- audio_spans=aspans, mute_tracks=mute_tracks, cb=cb)
7256
+ audio_spans=aspans, mute_tracks=mute_tracks, cb=cb,
7257
+ out_quality=out_q)
7138
7258
  else:
7139
7259
  render(args.video, dst, dets_r, state["cum"],
7140
7260
  state["bands"],
@@ -7144,7 +7264,7 @@ def run_render(args, state, cb=None):
7144
7264
  vcodec=getattr(args, "codec", "h264"),
7145
7265
  face_shape=getattr(args, "face_shape", "ellipse"),
7146
7266
  encoder=args.encoder, audio_spans=aspans, clip=clip,
7147
- mute_tracks=mute_tracks, cb=cb)
7267
+ mute_tracks=mute_tracks, cb=cb, out_quality=out_q)
7148
7268
  if args.report:
7149
7269
  write_report(args.report, args, state, output_path=dst)
7150
7270
  cb.log(f" audit report: {args.report} (contains PII text — protect it)")
@@ -7164,8 +7284,13 @@ def run_pipeline(args, cb=None):
7164
7284
  dets, rstate, prov = load_report(args.from_report)
7165
7285
  try:
7166
7286
  with open(args.from_report, encoding="utf-8") as _f:
7287
+ _adoc = json.load(_f)
7167
7288
  rstate["audio_suggestions"] = (
7168
- json.load(_f).get("audio_suggestions") or [])
7289
+ _adoc.get("audio_suggestions") or [])
7290
+ # keep the transcript through the render-end report
7291
+ # rewrite — load_report drops unknown fields
7292
+ rstate["audio_transcript"] = (
7293
+ _adoc.get("audio_transcript") or [])
7169
7294
  except Exception:
7170
7295
  pass
7171
7296
  # audio redactions ride in the report (the web review writes them
@@ -354,6 +354,10 @@ def build_args(job, for_render=False):
354
354
  else "match"),
355
355
  "--codec", (o.get("codec")
356
356
  if o.get("codec") in ("h264", "hevc") else "h264"),
357
+ "--out-quality", (o.get("out_quality")
358
+ if o.get("out_quality") in
359
+ ("archival", "balanced", "share")
360
+ else "archival"),
357
361
  "--face-shape", (o.get("face_shape")
358
362
  if o.get("face_shape") in ("ellipse", "rect")
359
363
  else "ellipse"),
@@ -1487,7 +1491,49 @@ function applyAudioSugg(i){
1487
1491
  if(!(BE.audio||[]).some(a=>Math.abs(a.t0-s.t0)<0.05&&Math.abs(a.t1-s.t1)<0.05))
1488
1492
  BE.audio.push({t0:s.t0,t1:s.t1,mode:"mute"});
1489
1493
  }
1490
- renderAudioSugg();beTLDraw();
1494
+ renderAudioSugg();renderTranscript();beTLDraw();
1495
+ }
1496
+ // Full transcript with matched spans highlighted — the fail-closed check
1497
+ // for spoken PII: ASR patterns can miss (a real half-muted address shipped
1498
+ // once), but a human reading the transcript catches it in seconds. Click a
1499
+ // start word then an end word to mute that range directly.
1500
+ function renderTranscript(){
1501
+ const el=document.getElementById("beATx");
1502
+ if(!el)return;
1503
+ const tx=BE.audioTx||[];
1504
+ if(!tx.length){el.style.display="none";el.innerHTML="";return;}
1505
+ el.style.display="block";
1506
+ const wasOpen=el.querySelector("details")?el.querySelector("details").open:true;
1507
+ const esc=s=>String(s).replace(/[<>&]/g,"");
1508
+ const muted=w=>(BE.audio||[]).some(a=>w[0]<a.t1&&w[1]>a.t0);
1509
+ const sugg=w=>(BE.audioSugg||[]).some(a=>w[0]<a.t1&&w[1]>a.t0);
1510
+ let h='<details'+(wasOpen?' open':'')+'><summary style="font-size:12px;color:#94a3b8;cursor:pointer">&#128221; Transcript ('+tx.length+' words) — verify nothing sensitive slipped through</summary>'
1511
+ +'<div style="max-height:150px;overflow-y:auto;line-height:2.1;padding:6px 2px;font-size:12.5px;color:#cbd5e1">';
1512
+ tx.forEach((wd,i)=>{
1513
+ const m=muted(wd),g=sugg(wd),a=i===BE.txAnchor;
1514
+ let st='cursor:pointer;border-radius:4px;padding:1px 3px;';
1515
+ if(a)st+='outline:2px solid #f59e0b;';
1516
+ if(m)st+='background:#7f1d1d;color:#fecaca;text-decoration:line-through;';
1517
+ else if(g)st+='background:#78350f;color:#fde68a;';
1518
+ h+='<span style="'+st+'" title="'+wd[0].toFixed(2)+'&ndash;'+wd[1].toFixed(2)+'s'+(m?' (will be muted)':'')+'" onclick="txWordClick('+i+')">'+esc(wd[2])+'</span>';
1519
+ });
1520
+ h+='</div><div style="font-size:11px;color:#64748b">'
1521
+ +(BE.txAnchor>=0?'<b style="color:#f59e0b">now click the last word of the range to mute it</b>'
1522
+ :'<span style="background:#7f1d1d;border-radius:3px;padding:0 4px">red</span> will be muted &nbsp;'
1523
+ +'<span style="background:#78350f;border-radius:3px;padding:0 4px">amber</span> detected PII (not yet added) &nbsp;'
1524
+ +'— click a start word, then an end word, to mute a missed range (&plusmn;0.5s pad)')
1525
+ +'</div></details>';
1526
+ el.innerHTML=h;
1527
+ }
1528
+ function txWordClick(i){
1529
+ const tx=BE.audioTx||[];if(!tx[i])return;
1530
+ if(BE.txAnchor<0){BE.txAnchor=i;renderTranscript();return;}
1531
+ const a=Math.min(BE.txAnchor,i),b=Math.max(BE.txAnchor,i);
1532
+ BE.txAnchor=-1;
1533
+ BE.audio.push({t0:Math.max(0,+(tx[a][0]-0.5).toFixed(2)),
1534
+ t1:+(tx[b][1]+0.5).toFixed(2),
1535
+ mode:(document.getElementById("beAMode")||{}).value||"mute"});
1536
+ renderTranscript();renderAudioSugg();beTLDraw();
1491
1537
  }
1492
1538
  const CATDN={mrn:"regex",person:"person (full body)",manual:"tracked object",qrcode:"QR / barcode",screen:"screen (tv/laptop/phone)",anytext:"all text",bank:"bank number",crypto:"crypto address",passport:"passport / MRZ"}; // display names — ids are a compat surface
1493
1539
  async function refreshModelPanel(){
@@ -1740,6 +1786,7 @@ async function loadBoxEdit(fromReview){
1740
1786
  <button class="tog" id="beMute" onclick="beMuteMode()">&#128263; Audio span</button>
1741
1787
  <button class="danger" id="beARm" style="display:none" onclick="beAudioRm()">Delete span</button></div>
1742
1788
  <div id="beASugg" style="display:none;margin-top:6px"></div>
1789
+ <div id="beATx" style="display:none;margin-top:6px"></div>
1743
1790
  <div class="row" style="margin-top:6px">
1744
1791
  <button class="tog" id="beAdd" onclick="beAddMode()">&#65291; Add box</button>
1745
1792
  <button class="tog" id="beTrk" onclick="beTrackMode()">&#8857; Track object</button>
@@ -1783,7 +1830,8 @@ async function tlInit(){
1783
1830
  BE.tlspans=Object.values(per);
1784
1831
  BE.audio=(doc.audio_redactions||[]).map(s=>({t0:s.t0,t1:s.t1,mode:s.mode||"mute"}));
1785
1832
  BE.audioSugg=doc.audio_suggestions||[];
1786
- renderAudioSugg();
1833
+ BE.audioTx=doc.audio_transcript||[];BE.txAnchor=-1;
1834
+ renderAudioSugg();renderTranscript();
1787
1835
  }catch(e){BE.tlspans=[];}
1788
1836
  beTLDraw();
1789
1837
  }
@@ -1864,6 +1912,7 @@ function tlHook(){
1864
1912
  if(s.t1-s.t0<0.15){BE.audio.pop();BE.audioSel=-1;} // stray click
1865
1913
  BE.muteArm=false;document.getElementById("beMute").classList.remove("on");
1866
1914
  document.getElementById("beARm").style.display=BE.audioSel>=0?"inline-block":"none";
1915
+ renderTranscript();
1867
1916
  }
1868
1917
  BE.tlDrag=null;beTLDraw();
1869
1918
  });
@@ -1877,7 +1926,8 @@ function beMuteMode(){
1877
1926
  }
1878
1927
  function beAudioRm(){
1879
1928
  if(BE.audioSel>=0){BE.audio.splice(BE.audioSel,1);BE.audioSel=-1;
1880
- document.getElementById("beARm").style.display="none";beTLDraw();}
1929
+ document.getElementById("beARm").style.display="none";
1930
+ renderTranscript();renderAudioSugg();beTLDraw();}
1881
1931
  }
1882
1932
  function beTrackMode(){
1883
1933
  BE.trk=!BE.trk;BE.add=false;BE.addAnchor=null;BE.muteArm=false;
@@ -820,6 +820,99 @@ def test_audio_redaction_mute_and_report_roundtrip(tmp_path):
820
820
  assert acodec == ["-c:a", "copy"], "no audio stream -> plain copy"
821
821
 
822
822
 
823
+ def test_textless_band_suppression():
824
+ """A scan with ZERO OCR text hits must drop its safety bands: bands
825
+ exist to cover unscanned text, and on handheld footage the camera-
826
+ motion probe reads as static, camera bob fakes scroll offsets — a
827
+ real address-only selfie job shipped a thin phantom blur bar at the
828
+ bottom edge. Any text hit at all keeps bands untouched (fail
829
+ closed)."""
830
+ moving = [(0.0, 0.0), (0.0, -4.0), (3.0, 0.0), (0.0, 0.0)]
831
+ out, sup = openscrub._suppress_textless_bands(list(moving), 0)
832
+ assert sup and all(x == 0 and y == 0 for x, y in out)
833
+ assert len(out) == len(moving)
834
+ # text WAS found -> bands untouched, no matter the offsets
835
+ out, sup = openscrub._suppress_textless_bands(list(moving), 7)
836
+ assert not sup and out == moving
837
+ # already-quiet bands (sub-threshold jitter) -> untouched, not "suppressed"
838
+ quiet = [(0.0, 0.0), (1.0, -1.5)]
839
+ out, sup = openscrub._suppress_textless_bands(list(quiet), 0)
840
+ assert not sup and out == quiet
841
+
842
+
843
+ def test_rate_cap_args_nvenc_only():
844
+ """The balanced/share bitrate ceiling applies to NVENC only (constant-
845
+ quality NVENC has no size anchor — a 12s 4K 'share' render came out
846
+ 123MB), scales with resolution/fps, and never touches archival or the
847
+ CPU/QSV encoders."""
848
+ a = openscrub._rate_cap_args("hevc_nvenc", "share", 3840, 2160, 60.0)
849
+ assert a[0] == "-maxrate" and a[2] == "-bufsize"
850
+ cap = int(a[1])
851
+ assert cap == int(3840 * 2160 * 60 * 0.04) and int(a[3]) == 2 * cap
852
+ small = int(openscrub._rate_cap_args(
853
+ "h264_nvenc", "share", 1080, 1920, 30.0)[1])
854
+ assert small < cap # scales down
855
+ assert openscrub._rate_cap_args("hevc_nvenc", "archival",
856
+ 3840, 2160, 60.0) == []
857
+ assert openscrub._rate_cap_args("libx264", "share", 3840, 2160, 60.0) == []
858
+ assert openscrub._rate_cap_args("hevc_qsv", "share", 3840, 2160, 60.0) == []
859
+
860
+
861
+ def test_out_quality_tiers_shrink_output(tmp_path):
862
+ """--out-quality maps to per-encoder constant-quality values: share <
863
+ balanced < archival in file size, with identical frame counts (the
864
+ tier changes bitrate only — never timeline or redaction strength)."""
865
+ src = str(tmp_path / "q.mp4")
866
+ subprocess.run(["ffmpeg", "-y", "-loglevel", "error", "-f", "lavfi",
867
+ "-i", "testsrc2=s=320x240:r=30:d=2", "-c:v", "libx264",
868
+ "-pix_fmt", "yuv420p", src], check=True)
869
+
870
+ class Q(openscrub.Callbacks):
871
+ def log(self, m):
872
+ pass
873
+ n, sizes, frames = 60, {}, {}
874
+ for q in ("archival", "balanced", "share"):
875
+ dst = str(tmp_path / f"q_{q}.mp4")
876
+ openscrub.render(src, dst, [], [(0, 0)] * n, [(0, 0)] * n, 30.0,
877
+ pad=4, mode="blur", preview=False, cb=Q(),
878
+ out_quality=q)
879
+ sizes[q] = os.path.getsize(dst)
880
+ frames[q] = int(cv2.VideoCapture(dst).get(cv2.CAP_PROP_FRAME_COUNT))
881
+ assert sizes["share"] < sizes["balanced"] < sizes["archival"], sizes
882
+ assert len(set(frames.values())) == 1, frames
883
+ # every ladder codec has all three tiers defined
884
+ for codec, tiers in openscrub._OUT_QUALITY.items():
885
+ assert set(tiers) == {"archival", "balanced", "share"}, codec
886
+
887
+
888
+ def test_audio_transcript_report_persistence(tmp_path):
889
+ """The review transcript view reads audio_transcript from the report:
890
+ write_report must persist it beside audio_suggestions, and the
891
+ no-whisper/no-audio paths must return the ([], []) tuple shape (the
892
+ caller unpacks two values)."""
893
+ d = openscrub.Detection(1.0, 1.5, (10, 10, 50, 50), "face", "face",
894
+ 0.9, (0, 0))
895
+ args = openscrub.build_parser().parse_args(["dummy.mp4"])
896
+ tx = [[0.7, 1.3, " My"], [1.3, 1.9, " address"]]
897
+ sugg = [{"t0": 0.35, "t1": 2.4, "category": "address", "text": "x"}]
898
+ state = {"fps": 30.0, "cum": [(0.0, 0.0)], "bands": [(0.0, 0.0)],
899
+ "detections": [d], "input_sha256": "x",
900
+ "audio_suggestions": sugg, "audio_transcript": tx}
901
+ rp = str(tmp_path / "r.json")
902
+ openscrub.write_report(rp, args, state)
903
+ with open(rp, encoding="utf-8") as f:
904
+ doc = json.load(f)
905
+ assert doc["audio_transcript"] == tx
906
+ assert doc["audio_suggestions"] == sugg
907
+
908
+ class Q(openscrub.Callbacks):
909
+ def log(self, m):
910
+ pass
911
+ out = openscrub.transcribe_audio_pii(
912
+ str(tmp_path / "missing.mp4"), {"address"}, Q())
913
+ assert out == ([], []), "failure paths must keep the tuple shape"
914
+
915
+
823
916
  def test_categories_none_manual_only(tmp_path):
824
917
  """--categories none = manual-only job: no detectors, no OCR, but a
825
918
  valid report with render_state so review can add tracked objects."""
@@ -2323,6 +2416,22 @@ def test_speech_suggestions_spoken_address():
2323
2416
  # unselected category: nothing (gating unchanged)
2324
2417
  assert openscrub._speech_suggestions(words, {"ssn"}) == []
2325
2418
 
2419
+ # ASR formatting variance (all three leaked a real address between
2420
+ # whisper builds): thousands-comma ZIP ("62,704"), spaced-digit ZIP,
2421
+ # and a word-number house ("one thirteen Main Street" — RE_STREET's
2422
+ # digit head can never match it)
2423
+ assert openscrub.RE_SPOKEN_STATEZIP.search("Springfield Illinois 62,704")
2424
+ assert openscrub.RE_SPOKEN_STATEZIP.search("Springfield Illinois 6 2 7 0 4")
2425
+ assert openscrub.RE_SPOKEN_STREET.search("one thirteen Main Street")
2426
+ assert openscrub.RE_SPOKEN_STREET.search(
2427
+ "eleven twenty two West Elm Avenue apartment 4B")
2428
+ # ordinary prose stays clean — no false positives from the widening
2429
+ for clean in ("I walked down the street yesterday",
2430
+ "the meeting is in room 12",
2431
+ "turn left in five hundred feet"):
2432
+ assert not openscrub.RE_SPOKEN_STREET.search(clean), clean
2433
+ assert not openscrub.RE_SPOKEN_STATEZIP.search(clean), clean
2434
+
2326
2435
 
2327
2436
  def test_person_seg_migration_lives_in_init():
2328
2437
  """The seg-to-onnxruntime migration must run at LOAD TIME as the
@@ -172,6 +172,12 @@ details .inner .full{grid-column:1/-1}
172
172
  <div><label>Codec</label><select id="vcodec"><option>h264</option><option>hevc</option></select></div>
173
173
  <div><label>Output format</label><select id="outfmt"><option>mp4</option>
174
174
  <option>mov</option><option>mkv</option></select></div>
175
+ <div><label>Output quality <span class="qm" data-tip="File size vs quality. Archival is visually lossless but LARGE (a 12s phone clip can be 100MB+) - great for records, too big to text. Balanced is about a third of that size; Share-friendly about an eighth, still clean enough for messaging and uploads. Redaction strength is identical in all three.">?</span></label>
176
+ <select id="outqual">
177
+ <option value="archival">Archival (largest)</option>
178
+ <option value="balanced">Balanced (~1/3 size)</option>
179
+ <option value="share">Share-friendly (~1/8 size)</option>
180
+ </select></div>
175
181
  <div class="full"><label>Allow names (keep visible, one per line)</label>
176
182
  <textarea id="allow" rows="2"></textarea></div>
177
183
  <div class="full"><label>Always blur (extra names)</label>
@@ -1045,6 +1051,7 @@ async function startScan(){
1045
1051
  face_shape:$("fshape").value,detect_scale:+$("dscale").value,
1046
1052
  hdr_output:$("hdrout").value,codec:$("vcodec").value,
1047
1053
  out_format:$("outfmt").value,
1054
+ out_quality:$("outqual").value,
1048
1055
  allow_names:$("allow").value,extra_names:$("extra").value,
1049
1056
  dense_faces:$("densefaces").checked,face_heads:$("faceheads").checked,
1050
1057
  audio_pii:$("audiopii").checked,skip_review:$("skiprev").checked,
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes