deface is a script to automatically blur faces.
Its underlying engines onnxrt and opencv are limited to 8-bit processing.
It took me way too long to figure out how to use deface’s capabilities while preserving the full 10-bit color information (I admit, it’s very niche).
That’s why I just want to briefly mention the result here.
Using
deface – as far as I can see – there is no way to preserve the 10-bit color information.
But we can use a trick and generate an 8-bit binary mask that we can use with ffmpeg to manually blur the regions.
deface --replacewith solid <infile>
ffmpeg postprocessing arguments (--ffmpeg-config) to replace every non-black color with white.
Let’s construct the command.
Using the lossless codec ffv1, the raw command looks like this:
ffmpeg -i <infile> -vf "geq=\
r='if(bitand(eq(r(X,Y),0),bitand(eq(g(X,Y),0),eq(b(X,Y),0))),0,255)':\
g='if(bitand(eq(r(X,Y),0),bitand(eq(g(X,Y),0),eq(b(X,Y),0))),0,255)':\
b='if(bitand(eq(r(X,Y),0),bitand(eq(g(X,Y),0),eq(b(X,Y),0))),0,255)',\
negate" -c:v ffv1 <outfile>.mkv
This converts to:
deface --replacewith solid --ffmpeg-config '{
"codec": "ffv1",
"ffmpeg_params": [ "-vf", "geq='\
'r='\''if(bitand(eq(r(X,Y),0),bitand(eq(g(X,Y),0),eq(b(X,Y),0))),0,255)'\'':'\
'g='\''if(bitand(eq(r(X,Y),0),bitand(eq(g(X,Y),0),eq(b(X,Y),0))),0,255)'\'':'\
'b='\''if(bitand(eq(r(X,Y),0),bitand(eq(g(X,Y),0),eq(b(X,Y),0))),0,255)'\'',negate"]}' \
-o binary.mkv <infile>
The output is a lossless binary video:
We can now manually blur the video and use this mask to stamp out parts of it that we subsequently overlay onto the original.
Assuming we have a file in yuv420p10le:
ffmpeg -y -i <infile> -i binary.mkv -filter_complex \
"[0:v]gblur=sigma=15[blur];\
[blur][1:v]alphamerge[merge];\
[0:v][merge]overlay=format=yuv420p10" <outfile>
uv tool install deface --with onnx --with onnxruntime