Created
July 19, 2022 03:14
Code for imaginaryCTF forensics "Subtitles" challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ffmpeg | |
from tensorflow import keras | |
import cv2 | |
def video_to_data(): | |
# Extract frames from video every 1 second and save to data dir using ffmpeg and start from 0 | |
ffmpeg.input("./subtitles.mp4").output("./data/%d.png", ss="0").run() | |
def main(): | |
labels = open("./label.txt", "rt").read().split("\n") | |
video_to_data() | |
# Load model.h5 to keras using GPU | |
model = keras.models.load_model("./model.h5") | |
res = [] | |
# Loop every images in data dir and compare label with prediction | |
for i in range(len(labels) - 1): | |
image = cv2.imread(f"./data/{i + 1}.png")[:, :, 0] | |
label = model.predict(image.reshape(1, 28, 28, 1)) | |
label = label.argmax() | |
if str(label) != labels[i]: | |
res.append("1") | |
else: | |
res.append("0") | |
print("".join(res)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
awk 'NR % 4 == 0' subtitles.srt > label.txt