0

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!!

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
LC303
  • 1
  • 1
  • Welcome to Stack Overflow! Please do not edit solution announcements into the question. Accept (i.e. click the "tick" next to it) one of the existing answer, if there are any. You can also create your own answer, and even accept it, if your solution is not yet covered by an existing answer. – Yunnosch Jun 08 '21 at 18:20
  • It is probably a Player issue. See [here](https://appuals.com/0xc1010103-item-format-not-supported/) for example. When I am testing your code, the output video plays as expected. You may try other video players like VLC. You may also try installing K-Lite codec pack, and use Media Player Classic. – Rotem Jun 08 '21 at 20:15

0 Answers0