How to split a video into frames and create jobs in GT Studio

To perform video annotation in GT Studio, you'll need to break video files into frames. You can use the following python script.

import cv2
import os
import shutil


file = 'video_demo.mp4' #Enter the video file name here, make sure to have that mp4 file in the same directory of your python script
vidcap = cv2.VideoCapture(file)
video_name = file.split('.')[0]
success,image = vidcap.read()
count = 0

main_folder = 'image_sequences' #zip file will go into this folder
if not os.path.isdir(main_folder):
    os.makedirs(main_folder)
    os.makedirs(main_folder + '/' + video_name)

while success:    
    cv2.imwrite(main_folder + "/" + video_name+'/'  + "frame{}".format(count)+ ".jpg", image)     # save frame as JPEG file      
    success,image = vidcap.read()
    count += 1
    
shutil.make_archive(main_folder + '/' + video_name, 'zip', main_folder + "/" ) #To create a zip file

After converting the video file with the above python script, you can upload the zip file generated in GT Studio.

Last updated