Skip to content

Commit 2140235

Browse files
authored
Merge pull request #331 from kuldip11/branch_video_watermark
watermark script added
2 parents 09595fa + f6254c2 commit 2140235

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

Diff for: Python/watermark_video/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## watermark a video with a given font
2+
- This script built in Python, using this python script you can watermark a video.
3+
- The OpenCV and Numpy Libraries are used to built this scripts.
4+
5+
## Requirements
6+
- install OpenCv (use command:- "pip install opencv-python" to install OpenCv through Command Prompt)
7+
- install ffpyplayer -4.3.2 (use command:- "pip install ffpyplayer" to install ffpyplayer through Command Prompt)
8+
9+
## Working
10+
![Image](images/input.png)
11+
- The user enters :
12+
- write the Path of the video with proper video extension and press Enter.
13+
- enter the text that you want to mark on the video, press Enter.
14+
- give two space seprated coordinate value(location where you want to mark the text).
15+
- give 3 space seprated value for text colour(RGB, Ex- 155 168 158) press Enter.
16+
- Select the font-type from the given list.
17+
- The script runs and the text is mark on the video.
18+
![Image](images/video.png)

Diff for: Python/watermark_video/images/input.png

29.2 KB
Loading

Diff for: Python/watermark_video/images/video.png

204 KB
Loading

Diff for: Python/watermark_video/watermark.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import numpy as np
2+
import cv2
3+
from ffpyplayer.player import MediaPlayer
4+
5+
# PATH of the video
6+
print('Enter the Path of the video')
7+
path=input()
8+
9+
# text
10+
print('Enter the Text')
11+
text=input()
12+
13+
# org
14+
print('Enter the coordinates of text')
15+
location = tuple(map(int,input().split()))
16+
17+
# Blue color in BGR
18+
print('Enter the color(Ex- 155 168 158)')
19+
color = tuple(map(int,input().split()))
20+
21+
# font
22+
Hershey_Simplex = cv2.FONT_HERSHEY_SIMPLEX
23+
Hershey_Plain = cv2.FONT_HERSHEY_PLAIN
24+
Hershey_Duplex = cv2.FONT_HERSHEY_DUPLEX
25+
Hershey_Complex = cv2.FONT_HERSHEY_COMPLEX
26+
Hershey_Triplex = cv2.FONT_HERSHEY_TRIPLEX
27+
Hershey_Complex_Small = cv2.FONT_HERSHEY_COMPLEX_SMALL
28+
Hershey_Script_Simplex = cv2.FONT_HERSHEY_SCRIPT_SIMPLEX
29+
Hershey_Script_Complex = cv2.FONT_HERSHEY_SCRIPT_COMPLEX
30+
font_list_index=[['0','Hershey_Simplex'],['1','Hershey_Plain'],['2','Hershey_Duplex'],['3','Hershey_Complex'],['4','Hershey_Triplex'],['5','Hershey_Complex_Small'],['6','Hershey_Script_Simplex'],['7','Hershey_Script_Complex']]
31+
font_list=[Hershey_Simplex,Hershey_Plain,Hershey_Duplex,Hershey_Complex,Hershey_Triplex,Hershey_Complex_Small,Hershey_Script_Simplex,Hershey_Script_Complex]
32+
33+
print('choose the font')
34+
print('Id',' ','item')
35+
for item in font_list_index:
36+
print(item[0],' ',str(item[1]))
37+
38+
Id = int(input())
39+
font = font_list[Id-1]
40+
41+
# fontScale
42+
fontScale = 1
43+
44+
# Window name in which image is displayed
45+
window_name = 'video'
46+
47+
# Line thickness of 2 px
48+
thickness = 2
49+
50+
video = cv2.VideoCapture(path)
51+
player = MediaPlayer(path)
52+
53+
while(True):
54+
ret, frame = video.read()
55+
audio_frame, val = player.get_frame()
56+
if ret==True:
57+
# Using cv2.putText() method
58+
image = cv2.putText(frame, text, location, font, fontScale, color, thickness, cv2.LINE_AA)
59+
60+
# Displaying the image
61+
cv2.imshow(window_name, image)
62+
63+
if val != 'eof' and audio_frame is not None:
64+
#audio
65+
img, t = audio_frame
66+
67+
if cv2.waitKey(28) & 0xFF == ord('q'):
68+
break
69+
70+
71+
# Release everything if job is finished
72+
cap.release()
73+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)