-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsteghide-mkv.py
More file actions
160 lines (136 loc) · 5.43 KB
/
Copy pathsteghide-mkv.py
File metadata and controls
160 lines (136 loc) · 5.43 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import cv2
import subprocess
import sys
from pathlib import Path
import os
import tempfile
import math
import getpass
def hide_split(file, frames, size):
chunk_size = math.ceil(size / (frames - 1))
temp_paths = [' ']
with open(file, "rb") as f:
for i in range(1, frames):
fd, path = tempfile.mkstemp(prefix=f"chunk_{i}_", suffix=".bin")
os.close(fd)
chunk_data = f.read(chunk_size)
if not chunk_data:
break
with open(path, "wb") as chunk_file:
chunk_file.write(chunk_data)
temp_paths.append(path)
return temp_paths
def credentials(Name, extension):
fs, path = tempfile.mkstemp(prefix="credentials_", suffix=".txt")
os.close(fs)
with open(path, "w") as cred:
cred.write(f"{Name}\n{extension}")
return path
def embid(temp_files, main_file, video, frames, password,name):
cap = cv2.VideoCapture(video)
fps = cap.get(cv2.CAP_PROP_FPS)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fourcc = cv2.VideoWriter_fourcc(*'FFV1')
out = cv2.VideoWriter(name + '.mkv',cv2.CAP_FFMPEG,fourcc, fps, (width, height))
print(f"Starting embedding process across {frames} frames...")
count = 0
for i in range(0, frames):
ret, frame = cap.read()
if not ret:
break
fi, path = tempfile.mkstemp(prefix=f"frame_{i}_", suffix=".bmp")
os.close(fi)
cv2.imwrite(path, frame)
if i == 0:
file_to_hide = main_file
cmd = ["steghide", "embed", "-cf", path, "-ef", file_to_hide, "-p", password, "-f"]
elif i < len(temp_files):
file_to_hide = temp_files[i]
cmd = ["steghide", "embed", "-cf", path, "-ef", file_to_hide, "-p", password, "-f"]
else:
out.write(frame)
del frame
if i % (math.ceil(frames/40)) == 0:
count = count + 1
progress_bar = f"[{'/' * count}{'.' * (40 - count)}{math.floor((i*100)/frames)}%]"
status_text = f"{i}/{frames}"
print(f"\033[1;32m{progress_bar}\033[0m", end='\r')
continue
try:
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode != 0:
print(f"Steghide Error at frame {i}: {result.stderr}")
else:
stealth_frame = cv2.imread(path)
out.write(stealth_frame)
del stealth_frame
if True:
if i % (math.ceil(frames/40)) == 0:
count = count + 1
progress_bar = f"[{'/' * count}{'.' * (40 - count)}{math.floor((i*100)/frames)}%]"
status_text = f"{i}/{frames}"
print(f"\033[1;32m{progress_bar}\033[0m", end='\r')
os.remove(file_to_hide)
except subprocess.TimeoutExpired:
print(f"Timeout at frame {i}")
break
if os.path.exists(path):
os.remove(path)
cap.release()
out.release()
if os.path.exists(main_file):
os.remove(main_file)
for chunk in temp_files:
if os.path.exists(chunk):
os.remove(chunk)
print(f"Success! Lossless mkv created as {name + '.mkv'}")
return None
if len(sys.argv) < 5 and len(sys.argv) > 2:
path1 = Path(sys.argv[1])
path2 = Path(sys.argv[2])
if len(sys.argv) == 4 :
path3 = Path(sys.argv[3])
prefix = path3.name.split('.')[0]
name = prefix
else:
prefix = path1.name.split('.')[0]
name = prefix
prefix2 = path2.name.split('.')[0]
extenstion1 = path1.suffix.lower()
extenstion2 = path2.suffix.lower()
Name = name + '_.mpv'
size1 = os.path.getsize(sys.argv[1])
size2 = os.path.getsize(sys.argv[2])
if extenstion1 in ['.mp4','.mov','.mkv','.avi','.webm','.wmv','.flv','.avchd','.3gp']:
if True:
print("Calculating total frames...")
frame_count = 0
cap = cv2.VideoCapture(sys.argv[1])
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
frame_count += 1
h = cap.get(4)
w = cap.get(3)
cap.release()
#
if (h*w/10) >= (size2/(frame_count-1)):
if frame_count <= 1:
print("Error: Video is too short to hide data.")
sys.exit()
password = getpass.getpass("Enter password to encrypt: ")
print(f"Splitting secret data into {frame_count - 1} chunks...")
temp_files = hide_split(sys.argv[2], frame_count, size2)
credential = credentials(prefix2, extenstion2)
embid(temp_files, credential, sys.argv[1], frame_count, password,name)
else:
print("File Size is too large to hide in this video.")
print("Try using a larger Video File.")
else:
print("No Video file Submitted")
print("Format: python steghide-mp4.py [video_file] [file_to_hide]")
else:
print("steghide-mp4.py needs exactly two arguments.")
print("Format: steghide-mkv embed [video_file] [file_to_hide]")