How to Blur Faces in a Video from Command Line

By  on  

Privacy is always incredibly important, especially with visual media where you may not have the permission of individuals in the video. If you're filming something in public, it's likely you'll catch someone's face who simply doesn't want or need to be identified. This recently got me to thinking: what's the easiest way to blur faces in a video via command line?

The best open source utility I found for blurring faces in a video was deface. Let's have a look at how you can use deface to blur faces in videos!

Start by downloading Python-based via pip:

python3 -m pip install deface

With deface installed, simply provide the video name and get the output file with blurred faces:

sudo deface ./sample-4k-faces-video.mp4
Input:  ./sample-4k-faces-video.mp4
Output: ./sample-4k-faces-video_anonymized.mp4
100%|█████████████████████████████

The resulting video does an impressive job of blurring out faces of persons walking by in the original recording:

View the resulting video of persons walking down the streets of New York:

The default threshold for face recognition works very well, even on moving subjects. You can experiment with thresholds with the thresh argument, and even draw the thresholds out while debugging:

I downloaded a handful of YouTube videos using my favorite YouTube downloading utility youtube-dl and I was amazed at how well deface did on a variety of visual environments. Faces were identified at a reliable level even at default threshold!

Recent Features

  • By
    5 More HTML5 APIs You Didn’t Know Existed

    The HTML5 revolution has provided us some awesome JavaScript and HTML APIs.  Some are APIs we knew we've needed for years, others are cutting edge mobile and desktop helpers.  Regardless of API strength or purpose, anything to help us better do our job is a...

  • By
    Being a Dev Dad

    I get asked loads of questions every day but I'm always surprised that they're rarely questions about code or even tech -- many of the questions I get are more about non-dev stuff like what my office is like, what software I use, and oftentimes...

Incredible Demos

  • By
    Truly Responsive Images with responsive-images.js

    Responsive web design is something you hear a lot about these days. The moment I really started to get into responsive design was a few months ago when I started to realise that 'responsive' is not just about scaling your websites to the size of your...

  • By
    Face Detection with jQuery

    I've always been intrigued by recognition software because I cannot imagine the logic that goes into all of the algorithms. Whether it's voice, face, or other types of detection, people look and sound so different, pictures are shot differently, and from different angles, I...

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!