I'm reading a video file, process it 10 seconds by 10 seconds and view every 10s as soon as its processing stage is finished like the following code:
from moviepy.editor import VideoFileClip, AudioFileClip
delay = 10
for i in range(0, int(video_clip.duration), delay):
cur_video_clip = video_clip.subclip(i, i+delay)
process_the_sub_clip(cur_video_clip)
cur_video_clip.preview()
but there is a lag between every previewing of a subclip because of processing time So that I'm using threads to make the previewing done in parallel and the main thread do the processing of the subclip, It worked and the lag is done
the code:
import threading
from moviepy.editor import VideoFileClip, AudioFileClip
def video_preview(clip):
clip.preview()
def do_nothing():
pass
preview_video_thread = threading.Thread(target=do_nothing)
preview_video_thread.start()
delay = 10
for i in range(0, int(video_clip.duration), delay):
cur_video_clip = video_clip.subclip(i, i+delay)
process_the_sub_clip(cur_video_clip)
preview_video_thread.join()
preview_video_thread = threading.Thread(target=video_preview, args=(cur_video_clip,))
preview_video_thread.start()
The problem is that after the previewing the first 10s, the window of VideoFileClip shutdown and the sound of the clip is still on, and with no lag.
I tried using multiprocessing instead of threading but didn't work I also tried to workaround with the logic of the program but also didn't work I tried to create a thread for every cycle in the loop and store them in a list to avoid the join but another error appeared