Ask Your Question
0

Problem's with video output, newbi here~

asked 2017-02-01 00:43:20 -0600

Gagazet gravatar image

Hello guys. Studying openCV now, for part time job and met problem, with what i can't deal. This is simply code, as at tutorial, but i am trying to have at output black&white video. Problem in codec, i think, because i tryed to use really a lot of them - DIVX, MP4V, M4S2 and etc., at output i have 1 kb video file just with name. I am using windows, 3.5Python. With image all great~ Will be happy in help, i tryed google about this problem and all advices couldn't help me. Sorry for English, not a native speaker, but trying to do my best~

import numpy as np
import cv2

cap = cv2.VideoCapture('VideoEX.mp4')

fourcc = cv2.VideoWriter_fourcc(*"MP4V")
out = cv2.VideoWriter('output1.mp4', fourcc , 20.0, (640,480))

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret == True:
       gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
       out.write(gray)

       cv2.imshow('frame',frame)
       if cv2.waitKey(1) & 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 2017-02-01 01:24:30 -0600

berak gravatar image

updated 2017-02-01 01:45:48 -0600

you're trying to write a grayscale image, while your current setup expects a color one. so try:

out = cv2.VideoWriter('output1.mp4', fourcc , 20.0, (640,480), False)

more things to check:

  • make sure, opencv_ffmpeg320.dll is on your PATH, or accessible to cv2.pyd at runtime
  • first try with MJPG and .avi , then experiment with other codecs/containers.
  • make sure, the size you give to the VideoWriter is the actual size of the image you write later
  • check return values from out.read() and out.isOpened()
edit flag offensive delete link more

Comments

Oh btw, if you do not like the heavy compression of CV_FOURCC('M','J','P','G'), then try with CV_FOURCC('X','2','6','4') which is supported on most systems!

StevenPuttemans gravatar imageStevenPuttemans ( 2017-02-01 02:19:00 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-02-01 00:43:20 -0600

Seen: 1,762 times

Last updated: Feb 01 '17