No more TV ads, Machine Learning to the rescue !

Ads are everywhere, the whole digital economy is fuelled by ads, the world is a gigantic commercial.
Content is created only for enabling maximum visibility of targeted ads.

We are trapped !

Well… a bit extreme vision, hopefully we have some good solutions to eliminate most of them on the WWW:

Saying that, let’s consider we can reasonably escape from massive ads flood on Internet. It’s a matter of few hours investment to find the suitable system for your internet consumption.
Among the alternate solutions we also have pay content like VOD, online paper subscription…

Now here’s my problem, I live in the middle of nowhere with a bandwidth around 2.5MB…

Got 2 lovely kids, nourished with Youtube and Fortnite and a wonderful wife, watching pets on facebook.

Then by default and as a good Al Bundy I consume terrestrial TV quite a lot. Can’t wait 20 seconds to watch 15 seconds of program, VOD is technically not viable with my internet connection performance.

I’m then facing ads invasion on terrestrial TV, mmmm… a bigger challenge than filtering web content…
Yes, some of you will say “time shifting”, but I’m “hopping” like crazy and even if we have only 27 free channels in France, it’s too much hardware for the purpose.

PIP ? Picture in Picture was really a great feature, but unfortunately dual tuner TVs are not very common nowadays (why ?), I’ll need to buy an extra tuner for each TV in the house, no go…

My holly grail: when I watch a program and commercial starts, TV swap automatically to any other channel, get back to the original program when ads end. Simple, isn’t it ?

My requirements/constraints

The clumsy solution

Device connects to a web page on the PI through the home wifi network.

Web page is showing the TV live stream from the PI, served by FFserver and proxied by Nginx. Format is mjpeg, the most universal solution I’ve found to stream video without sound and with very limited latency.


From a dedicated page, user can “teach” when the tv channel is showing ads or not. Simply by pressing a button. The model is then automatically uploaded to the PI. Timing was too short to think about good looking UI…

on the laptop (but works also on the phone)

Tracking naughty ads

In the device browser, model is downloaded and cached in local DB. User can select the channel to monitor. The nodejs process, proxied by Nginx , is receiving the requested channel id, stop the current FFmpeg streaming, start on the new channel.

Live stream received on the page is passed for prediction to deaplearn knn model created previously.

On the phone

Show big RED message when ads, back to BLUE when finished so you can continue to watch your favourite program.

Complete flow


Found a little TVHat for the raspberry PI, works like a charm but others TV tuner dongle also work very well.

I used a previous prototype showing how you can train and run a model in the browser thanks to deaplearn js (now tensorflowJS). Super easy, I’ve spent time only on developing the ability to export/persist the trained model. TV channels are using DOG (Digital on-screen graphic), the DOG is removed during ads to avoid hiding ads elements. Good for us, we can track this DOG, knn is doing a good job but there’s for sure better solutions, I hope… learn more here

Mmmm… working on canvas to create tensor requires it’s tainted from the same origin. Simple solution, proxy everything with Nginx, basta

I don’t need audio so mjpeg (motion jpeg) is the best streaming format I’ve found, widely natively supported…

FFmpeg manual compilation to support GPU acceleration, tuning, again, again and again… Cropping the image has been a good bonus, actually I just need to grab part of the screen where tv channels are putting their DOG. At the end, Raspberry CPU is showing 25% activity on average and rock solid.


info here

info here

setup here

setup here

setup here

Total cost: 50$ (PI + TV Hat).

You can lower by buying a cheaper TV dongle, seen some around 5$…

What’s still on the table



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store