Emil's Projects & Reviews

OpenHardware & OpenSource

Entries tagged "delogo".

Video Delogo: Finding the Logo Position and Size in a Video Stream 4th February 2016

Removing the logo from a video stream can be achieved using the ffmpeg 'delogo' video filter. ffmpeg is a cross platform command line utility but very powerfull. Its library 'libffmpeg' is used as a backend by many graphical video editors.

I wanted to automatically convert a lot of video captures to my preffered resolotion and encoding and while doing this I also wanted to get rid of the TV station logo. These logos come in a variaty of shapes and sizes and are placed in variour corners of the screen.

The ffmpeg delogo filter takes 5 parameters: the X,Y position and the W,H sizes of the blured rectangle and an optional border width. To automate the finding of these parameters I wrote a C program which searches for the logo and prints a string ready for ffmpeg use. It also detects any black bands and prints another string to be passed to the 'crop' filter.

A typical output from the 'delogo' program looks like this:

Size: 1920x1080
crop=1920:822:0:129
delogo=x=1799:y=986:w=106:h=79 corner 3
Duration: 1184.680 (00:19:45) BitRate: 1807594 fps: 25.00 Codec: H264

Detecting the logo takes about 5 seconds on my machine and then I'm using a Perl script which builds all the required ffmpeg parameters from its output.

The program C code and the compiled linux executable can be downloaded from github.


The detection algorithm starts by getting equally spaced timestamps of the input video file (64 by default). Then from those timestamps it searches the first key frames and saves the Y plane of those frames (for YUV 4:2:0 and 4:2:2 encodings). To speed detection only the 4 corners of an image are saved while the middle bands are discarded. The percentage of these corners are configurable with switch options.
To find the logo position all the saved frames are cross-correlated and the constant pixels will emerge. For static videos sometimes the detection fails and then it is better to apply first and edge detection algorithm (Canny) and cross-correlate the edges.

This entry has been cut, click to read on.

Tags: delogo, ffmpeg, video.

RSS Feed