How to remove grid in video using Ffmpeg

How to remove grid in video using Ffmpeg

During my life I was also a camera operator during a concert. There were a concert in the Radio I’ve collaborated for and I was with the camera during the concert. 

We had 3 camera, 2 fixed and I had the mobile one. Unfortunately during the recording, the director didn’t catch the fact the my camera sent the grid to the video mixer… this means that, at the end, all my shoots are affected with this GRID effect in the video:

It was a real mess. And we didn’t record each camera shoot.. so there were no way to remove my part or other fast-fix. But we could, at least, try to fix it in post production. Lucky for us, there is a plugin in Ffmpeg that can do what we need:

  1. Remove the grid that is in a fixed position
  2. Replace the pixel for each frame, with the most logic pixel (an average of the pixels surrounding)

The plugin is delogo. Here there is the documentation for delogo plugin . The plugin is intended for removal of video logo (suppress a TV station logo by a simple interpolation of the surrounding pixels) and can do what we exactly need. Due to the gird nature itself, first of all we need to find the positions of each line. Video is 1080×1920 . grid lines are 3 pixel width and so we can use multiple filter, each one to remove a line:

  1. ffmpeg -i input.mp4 -vf delogo=x=635:y=1:w=3:h=1078 -c:a copy output1.mp4
  2. ffmpeg -ioutput1.mp4 -vf delogo=x=1278:y=1:w=3:h=1078 -c:a copy output2.mp4
  3. ffmpeg -ioutput2.mp4 -vf delogo=x=1:y=360:w=1918:h=3 -c:a copy output3.mp4
  4. ffmpeg -ioutput3.mp4 -vf delogo=x=1:y=720:w=1918:h=3 -c:a copy final-output.mp4

Where each time the output of a filtering is then pass to the next filter. This is not very efficient and Ffmpeg has a better method to link a chain of filters with the use of filter_complex plugin (filter_complex documentation). You can also see this post as an example. At the end, the final command is:

 

ffmpeg -i input.mp4 -filter_complex “[0:v]delogo=x=635:y=1:w=3:h=1078[a];[a]delogo=x=1278:y=1:w=3:h=1078[b];[b]delogo=x=1:y=360:w=1918:h=3[c];[c]delogo=x=1:y=720:w= 1918:h=3[d]” -map [d] -c:a copy output.mp4

 

This is the input file

And this is the final result

Awesome! If you think that Ffmpeg is a free software. 

MiroAdmin