Skip to content

Add color space detection and conversion for iPhone videos#1

Open
Geddart wants to merge 2 commits intoReflct:masterfrom
Geddart:fix/colorspace-conversion
Open

Add color space detection and conversion for iPhone videos#1
Geddart wants to merge 2 commits intoReflct:masterfrom
Geddart:fix/colorspace-conversion

Conversation

@Geddart
Copy link
Copy Markdown

@Geddart Geddart commented Jan 14, 2026

iPhones record video in Display P3, BT.2020, or HDR (HLG/Dolby Vision), but sharp_frames extracted frames without any color space conversion, resulting in incorrect colors.

This commit adds:

  • New colorspace.py module for detecting video color space via ffprobe
  • Automatic conversion to sRGB/BT.709 for wide gamut SDR content
  • HDR to SDR tone mapping using Hable algorithm (via zscale filter)
  • Graceful fallback when zscale is unavailable

The fix applies to all three extraction code paths:

  • FrameExtractor (new modular extractor)
  • SharpFrames processor (legacy)
  • MinimalProgressSharpFrames (TUI)

Geddart and others added 2 commits January 14, 2026 17:26
iPhones record video in Display P3, BT.2020, or HDR (HLG/Dolby Vision),
but sharp_frames extracted frames without any color space conversion,
resulting in incorrect colors.

This commit adds:
- New colorspace.py module for detecting video color space via ffprobe
- Automatic conversion to sRGB/BT.709 for wide gamut SDR content
- HDR to SDR tone mapping using Hable algorithm (via zscale filter)
- Graceful fallback when zscale is unavailable

The fix applies to all three extraction code paths:
- FrameExtractor (new modular extractor)
- SharpFrames processor (legacy)
- MinimalProgressSharpFrames (TUI)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Fixes:
- Remove unused List import from colorspace.py
- Add __all__ export list for clear public API
- Fix type hint: Optional[Any] -> Optional['VideoColorInfo']
- HDR filter now explicitly specifies input transfer/primaries/matrix
  for more reliable conversion
- Optimize ffprobe calls: extract color info from existing video_info
  instead of making a separate subprocess call
- Add parse_color_info_from_stream() as public API for reuse

Tests:
- Add comprehensive unit tests for colorspace module
- Test VideoColorInfo.needs_conversion for all color space types
- Test parse_color_info_from_stream with various ffprobe outputs
- Test build_colorspace_filter for SDR, wide gamut, and HDR
- Test zscale availability detection
- Mock subprocess calls for isolated testing

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant