I'm attempting to write a program that lets you crop videos by drawing a ROI (Region of Interest) using the MoviePY and CV2 packages. The cropping and everything works fine, the problem is saving the newly cropped video. The video ends up created, but it can't be viewed. Whenever I open the file, I get a 0xc1010103 error.
This is my code:
import cv2
from moviepy.editor import VideoFileClip
from moviepy.video.fx.all import crop, resize
clip = VideoFileClip("inputvid.mp4")
clip = resize(clip, (460,720))
im = clip.get_frame(1)
r = cv2.selectROI("Image", im, False, False)
print(r)
cv2.destroyAllWindows()
if not r == (0, 0, 0, 0):
cropped_clip = crop(clip, x1=int(r[0]), y1=int(r[1]), width=int(r[2]), height=int(r[3]))
#cropped_clip.preview()
cropped_clip.write_videofile("test.mp4")
I know that everything up until write_videofile works because the cropped_clip.preview() shows the correctly cropped video, it's only the file from the write_videofile that's not working right.
Any help would be greatly appreciated!!