Ask Your Question

Revision history [back]

Bug in created video with cv2.VideoWriter (Python 2.7)

I'm having an issue with VideoWriter class in opencv module (version 2.4.9) for python 2.7

I'm reading a video file (MP4), performing some math transformations in each frame and writing the result as a new video (AVI), with cv2.VideoWriter.

The resulting video is being generated without any warning or error, but the last 2 columns of pixels of the video are all filled with black pixels (see the images below).

Picture 1: First frame of the original video (MP4): image description

Picture 2: First frame of the generated video (AVI) image description

Picture 3: Zoom of top-right corner of picture 2: image description

Picture 4: Zoom of the bottom-right corner of picture 2: image description

Only the last 2 pixels of the right columns in Picture 4 aren't filled with black. All the othem pixels of the columns are filled with RGB=(0,0,0)

My code is this:

cap = cv2.VideoCapture('C:\\inputVideo.mp4')
wrt = cv2.VideoWriter('C:\\outputVideo.avi',cv2.cv.CV_FOURCC('X','V','I','D'),\
2,(300,530))

while cap.get(1)<5: #catching only the first 5 frames of the video
    flag, img = cap.read()

    #I didn't put here the math transformations,
    #because the problem occurs also without the math part.

    #I'll generate a picture here for testing my code
    if cap.get(1)==1:
        cv2.imwrite('C:\\input.png', img) #Picture 1, attached above

    wrt.write(aux)
cap.release()
wrt.release()

With the following procedure I can generate "Picture 2":

cap=cv2.VideoCapture('C:\\outputVideo.avi')
flag, img = cap.read()
cv2.imwrite('C:\\output.png', img)

Anyone here have ever seen that bug? Is that a problem with the opencv library or with the codecs that I used? I don't have any possible idea of what can it be...

click to hide/show revision 2
retagged

updated 2014-09-08 02:10:54 -0600

berak gravatar image

Bug in created video with cv2.VideoWriter (Python 2.7)

I'm having an issue with VideoWriter class in opencv module (version 2.4.9) for python 2.7

I'm reading a video file (MP4), performing some math transformations in each frame and writing the result as a new video (AVI), with cv2.VideoWriter.

The resulting video is being generated without any warning or error, but the last 2 columns of pixels of the video are all filled with black pixels (see the images below).

Picture 1: First frame of the original video (MP4): image description

Picture 2: First frame of the generated video (AVI) image description

Picture 3: Zoom of top-right corner of picture 2: image description

Picture 4: Zoom of the bottom-right corner of picture 2: image description

Only the last 2 pixels of the right columns in Picture 4 aren't filled with black. All the othem pixels of the columns are filled with RGB=(0,0,0)

My code is this:

cap = cv2.VideoCapture('C:\\inputVideo.mp4')
wrt = cv2.VideoWriter('C:\\outputVideo.avi',cv2.cv.CV_FOURCC('X','V','I','D'),\
2,(300,530))

while cap.get(1)<5: #catching only the first 5 frames of the video
    flag, img = cap.read()

    #I didn't put here the math transformations,
    #because the problem occurs also without the math part.

    #I'll generate a picture here for testing my code
    if cap.get(1)==1:
        cv2.imwrite('C:\\input.png', img) #Picture 1, attached above

    wrt.write(aux)
cap.release()
wrt.release()

With the following procedure I can generate "Picture 2":

cap=cv2.VideoCapture('C:\\outputVideo.avi')
flag, img = cap.read()
cv2.imwrite('C:\\output.png', img)

Anyone here have ever seen that bug? Is that a problem with the opencv library or with the codecs that I used? I don't have any possible idea of what can it be...