← All posts

How Phonitor handles night vision without a real IR sensor

iPhones have no infrared light, so Phonitor can't see in a pitch-black room. With a nightlight or hallway lamp, it brightens the picture and keeps it steady.

Most security cameras have an infrared light. iPhones don’t, so Phonitor can’t see in a pitch-black room. With a nightlight, a hallway lamp or streetlight through the curtains, it brightens the picture and keeps it steady.

This post explains how that works. You don’t need any of it to use the app. The homepage sums it up as “cleaner, steadier video in low light, even under dim bulbs”, and the interesting part is what those words map to in practice.

What “night vision” really means here

Three things have to happen, in order:

  1. Detect that the scene has gotten dark. Not “the user pressed a button” — automatic, off the live video.
  2. Reconfigure the camera to favor low-light quality over everything else. Use the main lens, not the ultra-wide. Pick a capture format with a higher max ISO and a longer exposure window. Cap the frame rate. Keep the field of view as wide as the lens allows, because monitoring is useless if you’ve zoomed in.
  3. Hold steady under flickering or marginal lighting. The hardest part isn’t getting a good image when it’s dark. It’s not flipping in and out of dark mode every six seconds when someone walks past a hallway lamp.

Each maps to a piece of the system.

Step 1: Reading luminance off the live frames

Every frame coming through the camera pipeline is in YCbCr. The Y plane is luminance, full range, one byte per pixel. That’s a gift. You don’t need any colorspace math to ask “is the scene dark?” — the brightness of the scene is literally the average value of the Y plane.

So I attach a small handler to the live frames whose only job is to skim the Y plane and report a number:

// Illustrative — names simplified.
func averageLuma(of frame: VideoFrame) -> Float {
    let y = frame.lumaPlane          // 0..255 per pixel
    var total: UInt64 = 0
    var samples = 0
    for row in stride(from: 0, to: frame.height, by: 8) {
        for col in stride(from: 0, to: frame.width, by: 8) {
            total += UInt64(y[row, col])
            samples += 1
        }
    }
    return Float(total) / Float(samples)   // returns 0..255
}

A few details worth flagging:

  • Sampling every 8th pixel instead of every pixel. On a 1080p frame that’s a 64× speedup, about 32k samples instead of 2M, and for an average that’s plenty.
  • One sample per second, not per frame. A timer guards the work and only runs it once a second.
  • A second-stage rolling average. The per-second samples are grouped into windows of a few seconds and emitted as a single luma value. That’s the signal the rest of the system sees: one number every few seconds.

That’s all the input the decision logic needs.

Step 2: Don’t trip on noise — hysteresis, lockout, confirmation

If you take that luma signal and just say if luma < threshold { goDark() }, the user experience is awful. The light goes off in a hallway, you flip to dark mode. Someone opens a door, you flip back. Each flip restarts the camera, and the viewer sees a freeze of half a second to a second. People hate it.

Three protections, layered:

// Illustrative.
let enterDarkBelow:  Float = 50    // luma < 50: scene is dark
let exitDarkAbove:   Float = 130   // luma > 130: scene is bright
let lockoutSeconds         = 15    // wall-clock minimum between flips
let confirmSamples         = 2     // consecutive samples on the new side

Hysteresis. The threshold to enter dark mode is luma < 50. The threshold to exit is luma > 130. That gap is wide on purpose. Once dark mode engages, the camera applies low-light boost and pushes the exposure brighter — which raises measured luma. If the enter and exit thresholds were equal, we’d flip out of dark mode the instant our own corrections did their job, then immediately flip back in once they were reverted. The 80-point gap absorbs that.

Lockout. Even if every other check passes, transitions can’t happen more than once every fifteen seconds. This is the brute-force backstop for cases the threshold math didn’t catch — sudden lighting glitches, interleaved reflections, anything that produces a clean threshold crossing for a short moment.

Confirmation count. Two consecutive rolling-average samples on the new side before we commit. Each sample covers a few seconds of video, so the change has to hold for several seconds, on top of the fifteen-second lockout. A flip happens only when the scene has been clearly dark, or clearly bright, for long enough that a flicker can’t be the cause.

There’s also one explicit override:

When the user turns on the torch, freeze evaluation entirely.

Otherwise the bright cone in the middle of a dark room would lift the average luma above the exit threshold, we’d flip out of dark mode, the long-exposure format would be torn down, and the frame would go almost black.

Step 3: What actually changes when we go dark

This is the part that does the work. Detection only matters if reconfiguring the camera meaningfully improves the image.

When the state machine flips to dark, two things happen on AVCaptureDevice:

// Illustrative — wrap real calls in the proper lockForConfiguration block.
camera.automaticallyEnablesLowLightBoostWhenAvailable = true   // rear cam, where supported
camera.setExposureTargetBias(+1.0)                              // a stop brighter

The first turns on iOS’s built-in low-light boost, which raises the sensor’s gain in dark scenes. It only works on the rear camera and only on devices that support it, so we gate it accordingly.

The second is a manual exposure-target-bias of +1.0 EV. With low-light boost already raising the gain, +1.0 makes the image meaningfully brighter without clipping the bright fringes (a window, a hallway light, a passing car’s headlight). +1.5 tends to blow out those highlights, and they’re often the parts of the scene that carry the most information.

Going dark also drops the frame rate, so capture restarts with a new AVCaptureDevice.Format. The picker prioritizes things in this order:

  1. Max ISO. First filter. The format with the highest available ISO wins.
  2. Wide field of view. Among the high-ISO formats, prefer the widest. This is a monitoring app — narrow FOV in the dark is the worst possible combination.
  3. Long exposure. Among the remaining ones, prefer the format with the longest available maxExposureDuration. Long exposures are gold in low light. They’re also why the frame rate is capped at 10 fps in dark mode: the sensor needs time to gather light, and long exposures don’t go with 30fps.

Dropping FPS in the dark is a tradeoff some people will object to. But the alternative — refusing long-exposure formats so we can keep 30fps — produces a darker, noisier image. For a baby monitor or a hallway camera, 10fps is fine. For a livestream of a hummingbird at midnight, this is the wrong app.

What this isn’t

Worth being honest about what software-only night vision can and can’t do.

It cannot see in pitch black. There’s no infrared light. If the room is genuinely dark — covered windows, lights off, no moonlight — Phonitor sees what your iPhone’s camera sees, which is mostly noise.

It can make a usable picture from the light most homes still have at night: a nightlight, streetlight through curtains, a hallway lamp left on, the glow off a TV. Phonitor’s night mode is tuned for that in-between zone, where a phone camera with the right settings has enough signal to produce a calm, watchable feed.

What I’d build differently

A few things I’d revisit if I started over:

  • Use the U-V planes, not just Y. Right now luminance is the only signal. Color information could help distinguish “dark” from “very orange streetlight” (which produces high red signal but low overall luminance) — different scenes that probably benefit from different exposure policies. I haven’t done this yet.
  • Per-scene ML. A small Core ML model could probably classify “nighttime nursery” vs “dim living room” vs “room at dusk” and pick a smarter format and bias for each. I haven’t built this either.
  • Honest UX about limits. Some users in genuinely dark rooms get a noisy image and don’t know it’s a hardware ceiling, not a software bug. I should probably surface that more clearly in-app.

What you see

If you’ve used Phonitor as a baby monitor or a hallway camera, you’ve never seen any of this. The image got a little brighter when the lights went off, and it didn’t flicker when someone walked past the lamp. That’s the whole story from the user’s side.


Phonitor turns a spare iPhone, iPad or Mac into a home camera. Free on the App Store. New to this? Start with how to turn an old iPhone into a home security camera.