-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlt.py
More file actions
55 lines (40 loc) · 1.3 KB
/
Copy pathlt.py
File metadata and controls
55 lines (40 loc) · 1.3 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import cv2
import moviepy.editor as mpe
import matplotlib.pyplot as plt
import PILasOPENCV as Image
import PILasOPENCV as ImageDraw
import PILasOPENCV as ImageFont
''' ***** ***** ***** ***** ***** ***** *****
Lower Third -- Begin
***** ***** ***** ***** ***** ***** ***** '''
def lower_third():
text = "This is lower third text"
cap = cv2.VideoCapture("nature1.mp4")
framespersecond = float(cap.get(cv2.CAP_PROP_FPS))
res = (1920, 1080)
scale = 70
font = ImageFont.truetype("halcyon-medium.ttf", scale)
color = (0, 0, 0)
thickness = 2
margin = 2
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter("lt.mp4", fourcc, framespersecond, res)
done = False
while not done:
ret, frame = cap.read()
if not ret:
dont = True
continue;
im = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
draw = ImageDraw.Draw(im)
draw.text((370, 952), text, font=font, fill=(244, 172, 58))
mask = ImageFont.getmask(text, font)
frame = im.getim()
out.write(frame)
cap.release()
out.release()
''' ***** ***** ***** ***** ***** ***** *****
Lower Third -- End
***** ***** ***** ***** ***** ***** ***** '''
lower_third()