ai newsSo., 25. Okt.

Build an AI-Powered Ad Blocker for Any Smart TV in 2024

AI‑Powered Ad Blocker for Smart TV 2024 — A Hands‑On Guide Inspired by Hipertextual & Xataka Introduction Imagine watching your favorite 4K series without a single pre‑roll or banner stealing bandwidth and patience. In 2024 that vision is no longer a hype article—it’s a ready‑to‑run solution you ca

dev.toSonntag 09:58 · 25.10.4 Min. Lesezeit
Bild: dev.to

Imagine watching your favorite 4K series without a single pre‑roll or banner stealing bandwidth and patience. In 2024 that vision is no longer a hype article—it’s a ready‑to‑run solution you can install on any modern TV, a Raspberry Pi, or a spare home‑NAS. After the viral Hipertextual and Xataka tutorials, searches for “smart TV ad blocker” and “AI remove ads TV” spiked to breakout status on Google Trends.

This guide shows you exactly how to assemble the stack, configure the network proxy, and tune the on‑device AI so you can start blocking ads today. We also share real‑world performance numbers so you can decide whether the setup fits your hardware and bandwidth constraints.

Tip: If you already have a spare SSD‑based NAS, the Docker route is the cleanest—no OS changes, easy updates.

Below are the exact commands for a Raspberry Pi running Raspberry OS (64‑bit). Adjust package names for other distros.

# 1️⃣ Update & install dependencies sudo apt update && sudo apt install -y git build-essential cmake python3-pip ffmpeg libopencv-dev # 2️⃣ Install llama.cpp (quantized LLM runtime) git clone https://github.com/ggerganov/llama.cpp cd llama.cpp make -j $( nproc ) # 3️⃣ Download a 7‑B GGML INT8 model (e.g., LLaMA‑2‑7B‑Chat) wget https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/resolve/main/llama-2-7b-chat.ggmlv3.q4_0.bin -O models/llama-2-7b-chat.ggmlv3.q4_0.bin # 4️⃣ Install TinyYOLO‑v4 (ONNX + OpenCV DNN) pip3 install --upgrade pip pip3 install opencv-python-headless onnxruntime # 5️⃣ Clone the ad‑filter repo (contains detection scripts & config) git clone https://github.com/yourname/smart-tv-ad-filter.git cd smart-tv-ad-filter pip3 install -r requirements.txt Enter fullscreen mode Exit fullscreen mode TinyYOLO‑v4 model download wget https://github.com/AlexeyAB/darknet/releases/download/darknet_yolo_v4_pre/yolov4-tiny.weights wget https://raw.githubusercontent.com/AlexeyAB/darknet/master/cfg/yolov4-tiny.cfg python3 convert_to_onnx.py yolov4-tiny.cfg yolov4-tiny.weights yolov4-tiny.onnx Enter fullscreen mode Exit fullscreen mode Why these models? The 7‑B LLM handles textual ad cues (e.g., “Sponsored”, “Ad”) while TinyYOLO‑v4 spots visual overlays (logo watermarks, banner boxes) in the video stream. Both run under 2 GB RAM when quantized.

We use mitmproxy as a transparent man‑in‑the‑middle (MITM) that forwards TV traffic through a Python filter script.

# Install mitmproxy sudo apt install -y mitmproxy # Create a systemd service (optional but recommended) cat << EOF | sudo tee /etc/systemd/system/mitmproxy.service [Unit] Description=MITM Proxy for AI TV Ad Blocking After=network-online.target Wants=network-online.target [Service] User=pi ExecStart=/usr/bin/mitmproxy -p 8080 --mode transparent --set block_global=false -s /home/pi/smart-tv-ad-filter/filter.py Restart=on-failure [Install] WantedBy=multi-user.target EOF sudo systemctl daemon-reload sudo systemctl enable --now mitmproxy Enter fullscreen mode Exit fullscreen mode filter.py – the heart of the blocker import json import cv2 import numpy as np from pathlib import Path from mitmproxy import http # Load TinyYOLO‑v4 ONNX model once net = cv2. dnn. readNetFromONNX ( " /home/pi/smart-tv-ad-filter/yolov4-tiny.onnx " ) net. setPreferableBackend ( cv2. dnn. DNN_BACKEND_OPENCV ) net. setPreferableTarget ( cv2. dnn. DNN_TARGET_CPU ) # Load LLM (llama.cpp wrapper) from llama_cpp import Llama llm = Llama ( model_path = " /home/pi/llama.cpp/models/llama-2-7b-chat.ggmlv3.q4_0.bin ", n_ctx = 512 ) def detect_visual_ad ( frame: np. ndarray ) -> bool: blob = cv2. dnn. blobFromImage ( frame, 1 / 255.0, ( 416, 416 ), swapRB = True, crop = False ) net. setInput ( blob ) outs = net. forward () for detection in outs [ 0, 0 ]: confidence = float ( detection [ 2 ]) if confidence > 0.45: # tuned for ad overlays return True return False def detect_textual_ad ( chunk: bytes ) -> bool: # Simple heuristic: run LLM on extracted subtitles / captions prompt = f " Is the following text an? \\ n \\ n { chunk. decode ( errors = ' ignore ' ) } " resp = llm ( prompt, max_tokens = 5, stop = [ " \\ n " ]) return " yes " in resp. lower () def response ( flow: http.

HTTPFlow ) -> None: # Only inspect video segments (MPEG‑TS, MP4 fragments) if " video " not in flow. response. headers. get ( " content-type ", "" ): return # Grab first few KB for quick analysis sample = flow. response. content [: 8192 ] # 1️⃣ Visual detection (decode a frame) nparr = np. frombuffer ( sample, np. uint8 ) img = cv2. imdecode ( nparr, cv2. IMREAD_COLOR ) if img is not None and detect_visual_ad ( img ): flow. response = http. HTTPResponse. make ( 204, b "", {}) # drop segment return # 2️⃣ Textual detection (captions/subtitles) if detect_textual_ad ( sample ): flow. response = http.

HTTPResponse. make ( 204, b "", {}) Enter fullscreen mode Exit fullscreen mode How it works:

uci add firewall redirect uci set firewall.@redirect[-1].src = 'lan' uci set firewall.@redirect[-1].src_dport = '80,443' uci set firewall.@redirect[-1].dest = '192.168.1.42' # Pi IP uci set firewall.@redirect[-1].dest_port = '8080' uci commit firewall /etc/init.d/firewall restart Enter fullscreen mode Exit fullscreen mode Manual DNS method – Install Herramienta mencionada: Groq Cloud

Quelle: dev.to (dev.to). Original öffnen