-
Notifications
You must be signed in to change notification settings - Fork 1
/
enc_video.py
81 lines (72 loc) · 2.28 KB
/
enc_video.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import cv2,sys,glob
import numpy as np
from imgstg import encode
# to open video file
myfile = open("test.txt", "rt") # open lorem.txt for reading text
msg = myfile.read() # read the entire file into a string
myfile.close() # close the file
message = msg
mm = message
message = message.replace("\n","||||||||||||")
# message = input("Enter a message \n")
# message = 'This project is made by Ayush Kejariwal , Subhanjan Dash , Sourav bera. The project to be presented in ICCIC international conference'
imgloc = 'D:/sample.mkv'
# imgloc = input('enter location of video which you want to decode : ')
cap = cv2.VideoCapture(imgloc)
fps = cap.get(cv2.CAP_PROP_FPS)
count = 100000
for i in range (0,600):
message+=' '
# print (i)
# extracting frames and saving it new folder
while(cap.isOpened()):
ret, frame = cap.read()
if(ret):
# print('Read %d frame :'%count,ret)
# frame = cv2.flip(frame,1)
# this line flips the image horizontally ; for vertical,both replace 1 by 0,2 respectively
cv2.imwrite('D:/data/frame{:d}.png'.format(count),frame)
# this above one saves it in the location
count += 1
else:
break
# r = int(5*len(message)/(count%100000))+1
# print(r)
i=100000
l1 = 0
l2 = 250
while(True):
msg = message[l1:l2]
# print (msg)
imgoc = 'D:/data/frame%d.png'%i
encode(msg,imgoc)
print ('message %d encoded'%i)
if l2==len(message):
break
l1=l2
l2=l2+250
if l2>=len(message):
l2=len(message)
i+=1
print ('message has been encoded and msg is')
print(mm)
i+=1
# while(i<=count):
# imgoc = 'D:/data/frame%d.png'%i
# img = cv2.imread(imgloc)
# cv2.imwrite(imgloc, img, [cv2.IMWRITE_PNG_COMPRESSION, 9])
# i+=1
cap.release()
cv2.destroyAllWindows()
img_array = []
for filename in glob.glob('D:/data/*.png'):
# print (filename)
img = cv2.imread(filename)
height, width, layers = img.shape
size = (width,height)
img_array.append(img)
out = cv2.VideoWriter('project1.mkv',cv2.VideoWriter_fourcc(*'HFYU'), fps, size)
for i in range(len(img_array)):
out.write(img_array[i])
out.release()
print ('output video is project.mkv at the location of this prg')