I fixed Plex on my Samsung TV

I made a Plex app for Samsung TVs. It’s called samsucks, it’s free, and on my TV it opens in about a second instead of about a minute.

Loads in less than a second

The official app takes a minute

We have a 75 inch Samsung in the living room. A QN75Q60B, from 2022. It’s an okay TV. We use it to watch Plex.

The official Plex app on it takes about a minute just to load. Not a minute to find something to watch (though that sucks too), but a minute to show me the home screen.

Search is worse. Every letter you type lags. You press one, you wait for it to show up, you press the next one. Then the search itself takes forever.

The annoying part? My Plex server answers a search in 30 to 150 milliseconds. I measured it. So the server isn’t the slow part – the app is.

Samsung only lets you make web apps

The idea came from plx-native, a Plex client for LG TVs written in Rust. It skips the TV’s browser and draws everything itself, and it’s fast.

I couldn’t do that. Retail Samsung TVs only run web apps: HTML, CSS and JavaScript, running in a built in browser that’s about as old and shitty as you’d guess. No “native” code allowed.

So copying plx-native was out. The job became: make a web app fast, on a slow browser, on a TV.

Treat the browser like a game engine

Games run smoothly on weak hardware because they’re strict about what happens in each frame. I just mastered this with performance on kindlefall – so I made the app strict too.

In plain words: the TV is good at sliding pictures around and bad at redrawing them. So samsucks slides things and almost never redraws anything.

When you press Right, the highlight doesn’t move. The row slides under it. The posters are a fixed set of tiles that get reused as you scroll, so the app doesn’t grow no matter how big your library is. Every poster is fetched at the exact size it’s shown, so the TV never has to shrink a big image.

No framework. Zero dependencies. No build step. Just JavaScript.

All of that got me to 11 frames per second…..which is bad.

The 2-second gradient

Four CSS gradients: almost two seconds for one frame. Four pixels: 80 ms.

Plex gives every movie and show four colors, one per corner, pulled from the artwork. The official apps use them for a soft, colorful background that shifts as you move between items. I wanted that.

The “obvious” way to draw it is four CSS gradients, one from each corner. On a computer, that costs nothing. On my TV, one frame took 1,928 milliseconds.

That’s almost two seconds of frozen screen from one press of the remote. Most frames were fine, which is what made it sneaky. Everything looked okay until it didn’t.

I found it the boring way. The test version of the app talks to my Mac, so I could press buttons on the TV from a terminal and get back how long every frame took. Then I turned things off one at a time and measured again. Shadows: innocent. Fades: innocent. The big background artwork: innocent.

The gradient: guilty.

The fix is my favorite thing in the whole project. You don’t need a gradient to get a gradient. Make a picture that’s 2 pixels wide and 2 pixels tall, one pixel per corner color, and stretch it to fill the screen. Stretching an image blends the colors for you. It looks the same.

The first try used a regular canvas and got the worst frame down to 207 ms. Better. Still bad. The second try put the same four pixels in WebGL, which lives on the TV’s graphics chip, and the TV does the stretching for free.

Worst frame: 1,928 ms down to 80 ms. 11 frames per second up to 50.

Four pixels.

If you want to see it for yourself, there’s a setting called “Demo: original slow renderer” that brings the old gradients back, and a “Performance overlay” that shows the frame rate on screen. Turn both on and watch your TV have a bad day.

It plays everything

Video goes straight to the TV’s own hardware player. It’s about a second from pressing play to seeing the picture.

I checked every item in my library against what the TV can play by itself. 3,952 items. 98.7% play directly, no converting.

Most of the rest have DTS audio, which Samsung TVs stopped supporting years ago. For those, Plex leaves the video alone and only converts the sound. You won’t notice.

Try it

samsucks is free and open source (GPL-3.0). It’s not in the Samsung store, so you install it with the TV’s developer mode. The README has the details.

So far it’s only been tested on my TV. If you try it on another Samsung, let me know how it goes. Good or bad. samsucks on GitHub

Discover more from Rudy Faile

Subscribe now to keep reading and get access to the full archive.

Continue reading