-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblur.py
39 lines (30 loc) · 1.24 KB
/
blur.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
-Takes in a video clip
-In each scene it looks for faces
-Using the coordinates it blurs the face region
-Then searches the next scene
-Finally stitches all images into one video
"""
import os
def breakVideo(self, video):
# Takes video and separates it frame by frame
audioCommand = ("ffmpeg -i ", video, "videoSound.mp3")
imageCommand = ("ffmpeg -i ", video, "images%06d.jpg -hide_banner")
os.system(audioCommand)
os.system(imageCommand)
return(True)
def findFace(self):
# Use opencv to find the coordinates of the face in the scence if any
import opencv
return True
def blurCoordinates(self, image):
# Using the coordinates of the face, the edge coordinates of face is blurred out
from PIL import Image, ImageFilter
coordinates = findFace()
croppedImage = image.crop(coordinates)
blurredImage = croppedImage.filter(ImageFilter.GaussianBlur(radius=20))
image.paste(blurredImage, coordinates)
def stitchImages(self, frameRate, resolution):
# Stitches all the images together and adds in the audio
stitchCommand = ("ffmpeg -r ", frameRate, "-s ", resolution, "-i images%04d.png -i videoSound.mp3 -vcodec libx264 -b 4M -vpre normal -acodec copy FinalVideo.mp4 ")
os.system(stitchCommand)