Skip to content

Instantly share code, notes, and snippets.

@tudoanh
Created July 19, 2022 03:14
Show Gist options
  • Save tudoanh/2ecbbacc88c72fc7a605a64ef277cbf3 to your computer and use it in GitHub Desktop.
Save tudoanh/2ecbbacc88c72fc7a605a64ef277cbf3 to your computer and use it in GitHub Desktop.
Code for imaginaryCTF forensics "Subtitles" challenge
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()
@tudoanh
Copy link
Author

tudoanh commented Jul 19, 2022

0000000000000000001110000000000000000000110000000000000000001001110000000000000000000011100000001000000000000000011100000000000000000000000001110000000000000000000011000000000000000000000000111000000000000000000001110000000000000000000001110000001000000000001110000000000000001100001000000000000000011100000100000000000001110000000000000000001110000000000000001100000000000000011100000000000000000000000011100000000000000000000001110000000000000001110000000000000000000111100000000000000000110000000000000000000011100000000000000001110000000000000000000001100000000000000000011100000000000000000000000001110001000000000000000000011100000000000000000000000001110000000000000001100000000000000000011000000000000000000111000000000000000000011000000000000001111000000000000000001100000000000000000000000011100000000000000000011100000000000100000000111

@tudoanh
Copy link
Author

tudoanh commented Jul 19, 2022

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