-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexecute.py
106 lines (85 loc) · 2.95 KB
/
execute.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from stegano import lsb
from os.path import isfile, join
import time # install time ,opencv,numpy modules
import cv2
import numpy as np
import math
import os
import shutil
from subprocess import call, STDOUT
def split_string(s_str, count=10):
per_c = math.ceil(len(s_str) / count)
c_cout = 0
out_str = ''
split_list = []
for s in s_str:
out_str += s
c_cout += 1
if c_cout == per_c:
split_list.append(out_str)
out_str = ''
c_cout = 0
if c_cout != 0:
split_list.append(out_str)
return split_list
def frame_extraction(video):
if not os.path.exists("./tmp"):
os.makedirs("tmp")
temp_folder = "./tmp"
print("[INFO] tmp directory is created")
vidcap = cv2.VideoCapture(video)
count = 0
while True:
success, image = vidcap.read()
if not success:
break
cv2.imwrite(os.path.join(temp_folder, "{:d}.png".format(count)), image)
count += 1
def encode_string(input_string, root="./tmp/"):
split_string_list = split_string(input_string)
for i in range(0, len(split_string_list)):
f_name = "{}{}.png".format(root, i)
secret_enc = lsb.hide(f_name, split_string_list[i])
secret_enc.save(f_name)
print("[INFO] frame {} holds {}".format(f_name, split_string_list[i]))
def decode_string(video):
frame_extraction(video)
secret = []
root = "./tmp/"
for i in range(len(os.listdir(root))):
f_name = "{}{}.png".format(root, i)
secret_dec = lsb.reveal(f_name)
if secret_dec == None:
break
secret.append(secret_dec)
print(''.join([i for i in secret]))
clean_tmp()
return secret
def clean_tmp(path="./tmp"):
if os.path.exists(path):
shutil.rmtree(path)
print("[INFO] tmp files are cleaned up")
def main(input_string, f_name):
# input_string = input("Enter the input string :")
# f_name = input("enter the name of video")
frame_extraction(f_name)
call(["ffmpeg", "-i", f_name, "-q:a", "0", "-map", "a", "tmp/audio.mp3", "-y"], stdout=open(os.devnull, "w"),
stderr=STDOUT)
encode_string(input_string)
call(["ffmpeg", "-i", "tmp/%d.png", "-vcodec", "png", "tmp/video.mov", "-y"], stdout=open(os.devnull, "w"),
# call(["ffmpeg", "-i", "tmp/%d.png", "tmp/video.mp4", "-y"], stdout=open(os.devnull, "w"),
stderr=STDOUT)
call(["ffmpeg", "-i", "tmp/video.mov", "-i", "tmp/audio.mp3", "-codec", "copy", "video.mov", "-y"],
stdout=open(os.devnull, "w"), stderr=STDOUT)
clean_tmp()
# if __name__ == "__main__":
# while True:
# print("1.Hide a message in video 2.Reveal the secret from video")
# print("any other value to exit")
# choice = input()
# if choice == '1':
# main()
# elif choice == '2':
# decode_string(input("enter the name of video with extension"))
# else:
# break