Created
July 19, 2022 03:14
-
-
Save tudoanh/2ecbbacc88c72fc7a605a64ef277cbf3 to your computer and use it in GitHub Desktop.
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() |
awk 'NR % 4 == 0' subtitles.srt > label.txt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
0000000000000000001110000000000000000000110000000000000000001001110000000000000000000011100000001000000000000000011100000000000000000000000001110000000000000000000011000000000000000000000000111000000000000000000001110000000000000000000001110000001000000000001110000000000000001100001000000000000000011100000100000000000001110000000000000000001110000000000000001100000000000000011100000000000000000000000011100000000000000000000001110000000000000001110000000000000000000111100000000000000000110000000000000000000011100000000000000001110000000000000000000001100000000000000000011100000000000000000000000001110001000000000000000000011100000000000000000000000001110000000000000001100000000000000000011000000000000000000111000000000000000000011000000000000001111000000000000000001100000000000000000000000011100000000000000000011100000000000100000000111