Ask Your Question
0

Video corrupted after using Canny then writing. Can you guys spot the mistake

asked 2020-05-31 04:51:07 -0600

NoobCoder gravatar image
import cv2
import numpy as np
cap = cv2.VideoCapture("video.mp4")
frame_width = int(cap.get(3))
frame_height = int(cap.get(4))
out = cv2.VideoWriter('manipulated_video.avi',cv2.VideoWriter_fourcc('M','J','P','G'), 25, (frame_width,frame_height))
while(cap.isOpened()):
    ret, frame = cap.read()
    if ret == True:
        edges = cv2.Canny(frame, 100, 200)
        cv2.imshow('Edges', edges)
        if cv2.waitKey(25) & 0xFF == ord('q'):
            break
    else:
        break
cap.release()
out.release()
cv2.destroyAllWindows()
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-05-31 07:41:04 -0600

supra56 gravatar image

I solved problem. You are missing parameter in cv2.VideoWriter.

import cv2
import numpy as np
cap = cv2.VideoCapture('video.mp4')
frame_width =  int(cap.get(3))
frame_height = int(cap.get(4))
out = cv2.VideoWriter('manipulated_video.avi',
                      cv2.VideoWriter_fourcc(*'MJPG'), 25,
                      (frame_width,frame_height), False)

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret == True:
        edges = cv2.Canny(frame, 100, 200)
        out.write(edges)
        cv2.imshow('Edges', edges)

        if cv2.waitKey(25) & 0xFF == ord('q'):
            break
    else:
        break

cap.release()
out.release()
cv2.destroyAllWindows()
edit flag offensive delete link more

Comments

It's still corrupted. Idk what I did wrong :( Can you run the code and see if it's successful?

NoobCoder gravatar imageNoobCoder ( 2020-05-31 10:03:17 -0600 )edit

It ran both pc and linux. I used OpenCV 4.3.0, Python 3.7.3. Did you added parameter in cv2.VideWriter?

supra56 gravatar imagesupra56 ( 2020-05-31 11:28:25 -0600 )edit

You gotta any errors problem?

supra56 gravatar imagesupra56 ( 2020-05-31 11:37:24 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-05-31 04:51:07 -0600

Seen: 1,533 times

Last updated: May 31 '20