LAB-009keiver/tomotv
Live TV · Channel wall

Live TV channel previews that loop

tomo-tvapple-tvlive-tvtvosffmpeg

Tomo TV loops a five-second live TV channel preview clip on every card of its channel wall. Each channel is opened once: the first keyframe becomes the card still and the next five seconds are encoded on device to 360p at 1 Mbps. Clips are written as a temporary file and renamed only when whole. A red badge reads LIVE for 15 seconds after the picture changes, and the strip under the card turns red, then fades to black over two minutes. The player pool starts at 12 on Apple TV and lowers itself when the hardware decoder reports busy.

keiver.dev/lab/9

A grid of channel names tells you nothing about what is on. Every card on Tomo TV's channel wall loops a five-second live TV channel preview clip, recorded on the device. The catch is the provider. It rations live streams, so each clip has to come out of a single open.

The Channels screen in Tomo TV's Mac app, four rows of six channel cards from a news provider, each resting on a strip that names the channel in capitals. One card reads LIVE on a bright red strip, a few strips carry a fading red, most are black, and the last card has no picture yet
The channel wall in the Mac app. The card reading LIVE sits on full red, a few older pictures still carry a fading red, the rest have gone black, and a card with no picture yet rests on black.

Live TV channel preview clips come from one open

Many providers cap how many live streams one account holds at once. A still from one open and a clip from another would spend two connections on one card. The engine opens each channel once and takes both.

The first keyframe becomes the card's still, on screen while the rest is read. The next five seconds become the clip. The device encodes it to at most 360 pixels tall, 15 frames per second and 1 Mbps. When the clip lands, the card swaps its still for the loop.

The sampler reads two channels at a time, never two from the same provider host. It waits a second after each start before the next, unless focus moves to a card that needs its picture. The moment playback takes the link, it stops and cancels the reads in flight.

flowchart LR
    A[Channel in view] --> B[Open to provider]
    B --> C[First keyframe: card still]
    B --> D[Next 5 s: encode clip]
    D --> E[Write as .part]
    E --> F{Whole?}
    F -- yes --> G[Rename: clip ready]
    F -- no --> H[Remove, card keeps still]
    G --> I[Card loops clip]

Written whole or not at all

A clip cut short looks broken on a loop, and plenty can cut one short. Playback starts. The viewer picks another channel group. A slow source runs into the grab's 15-second deadline.

The engine writes the clip to a .part file. It gives the file its final name only after the last frame is flushed and the MP4 trailer is written. A cancelled grab deletes the partial file, and the card keeps its still. A clip holding less than 60 percent of its five seconds is thrown away too. Three seconds is the shortest loop a card will ever play.

A live stream is joined in the middle of a group of pictures (GOP), and those first packets cannot be decoded alone. The clip waits for the first keyframe and sets its own zero on that frame's presentation time. Every loop opens on a whole picture, with no empty gap at its head.

The player had its own flash. Hiding its layer ran Core Animation's implicit fade, which painted an empty black player over the card. Hides now run with animations off. A newer clip for the same card waits for the next loop seam and cuts in there, with the layer still visible.

How old is a live TV channel preview?

A picture counts as fresh for 15 seconds after it last changed, and a red LIVE badge says so. After that, the strip under the card shows its age. It turns LIVE red when a picture lands, then fades to black by the two-minute mark, the soonest that channel is read again.

The strip names the channel, black at rest and gold on focus. The red fades in eight steps, each one second of opacity run by React Native's native animation driver. One timer per card wakes it at each step and never between, so a card changes at most nine times between two pictures: once when LIVE ends and once per step.

Our first badge told the age with motion: a pale wedge drained inside a red circle toward the next grab. Each wedge was one long animation. Reanimated, our animation library, sends such updates through a full shadow tree commit unless an opt-in flag is set, and we had not set it. A sample of a debug build on the Apple TV simulator put about 70 percent of the main thread's busy time in those updates. That is not a device number, but the cost grew with every card on the wall. A still hourglass fixed the cost and lost the message: a card wore it for at least 105 of every 120 seconds. The strip says the same thing with nine changes and no per-frame work.

The device learns its own limits

Two limits decide how many clips loop at once: the hardware decoder and the provider.

The player pool starts at 12 on Apple TV, 16 on iPhone and 48 on a Mac. When a clip fails with a decoder-busy error, the pool caps itself at the number still playing. That card keeps its still, and cards past the cap wait for a player to free up. Nobody configures this. The device finds its ceiling at the first failure.

The provider's limit is learned the same way. When an open is refused while the device already holds other connections to that provider, the number held becomes its budget. Channel Settings can also set it by hand, 1 to 5 streams per playlist, with Auto as the default. A card's first failure costs it no wait, only its place in line. From the second failure in a row it waits two minutes, doubling up to ten, and the rest of the wall keeps filling.

A hardware tuner is the exception. On an HDHomeRun behind Jellyfin, every open of a channel takes one of the box's physical tuners, the same ones every other TV and recording in the house uses, so learning its limit by being refused takes tuners from them. From Tomo TV 2.2.15 a channel only a tuner carries is never opened for its card: the card shows the picture taken from the stream while that channel was last watched (issue 116).


Background work on a TV app competes with the one thing on screen. Every connection to a provider takes a ranked lease first. A card grab ranks lowest: it waits for a slot to free rather than taking one, and playback revokes it the moment it needs the connection. Once no card is playing, idle players stay five seconds for the next scroll, then go. Let background work learn its limits from real failures, and make it yield every time.

See also: channel surfing on Apple TV with AVKit, generating video thumbnails on device, and Tomo TV on the lab page.

Tested on
Devices
Apple TV simulator, debug build, for the main-thread sampleApple TV, iPhone and Mac for the player pool ceilings
App
Tomo TV 2.2.13
Checked
2026-10-23
Notes
The main-thread share is a simulator sample, not a device number

Drafted with Claude from Tomo TV's code and device measurements. Reviewed, edited and verified by Keiver Hernandez.

Next readLAB-008keiver/tomotv
Playback engine · Posters

Generating video thumbnails on device

tomo-tvapple-tvffmpeg

Tomo TV makes video poster cards from the file itself on Apple TV and iPhone. A batch of keyframes from the 10% mark is scored by color histogram and the one nearest the batch average wins, the measure FFmpeg's thumbnail filter uses. Dark and flat frames are rejected by luma and contrast thresholds, letterbox bars are cropped using the union of every frame's content box, and decodes run one at a time from a low-priority queue, newest card first, cancelling jobs for cards that scroll off screen.

5 min read