Last active
September 9, 2020 08:36
-
-
Save rsnk96/cab4d282ec347c4fc61f0b33e4b75316 to your computer and use it in GitHub Desktop.
Outline of a parallelized video processing code
This file contains 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
def process_video(group_number): | |
cap = cv2.VideoCapture("input_file.mp4") | |
cap.set(cv2.CAP_PROP_POS_FRAMES, frame_jump * group_number) | |
proc_frames = 0 | |
out = cv2.VideoWriter("output_{}.avi".format(group_number), ...) | |
while proc_frames < frame_jump: | |
ret, frame = cap.read() | |
# ... DO SOME STUFF TO frame ... # | |
proc_frames += 1 | |
out.write(frame) | |
return None | |
# Process the video by splitting it into as many fragments as the number of virtual cores you have | |
import multiprocessing as mp | |
frame_jump = cv2.VideoCapture("input_file.mp4").get(cv2.CAP_PROP_FRAME_COUNT) // mp.cpu_count() | |
mp.Pool(num_processes).map(process_video, range(num_processes)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment