VideoWriter issues

asked 2018-12-11 02:58:58 -0600

WoFFeN88 gravatar image

I'm trying to save a video but I have really problems, because I create the video but when I try to play it doesn't work just stay black. I try to follow the opencv documentation but it didn't works.

https://opencv-python-tutroals.readth...

Im on win10, maybe its important to know...?

A piece of code:

import numpy as np
import cv2

cap = cv2.VideoCapture("myVideo.mp4")

fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('newVideo.avi',fourcc, 20.0, (640,480))

while(cap.isOpened()):
    grabbed, frame = cap.read()
    if (grabbed==True):
        frame = cv2.flip(frame,0)
        out.write(frame)

        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

Comments

Does it work with MJPG?

LBerger gravatar imageLBerger ( 2018-12-11 06:28:20 -0600 )edit

I tryed but it doesnt work, thank you for response:

fourcc = cv2.VideoWriter_fourcc(*'MJPG')
out = cv2.VideoWriter('newVideo.mp4',fourcc, 20.0, (640,480))
WoFFeN88 gravatar imageWoFFeN88 ( 2018-12-11 07:09:05 -0600 )edit

First try this tutorial (saving a video) using your webcam

LBerger gravatar imageLBerger ( 2018-12-11 07:33:24 -0600 )edit

Thank you for your response but as I said, I practice with openCV tutorial and with webcam its works but not when you practice with a video. You know? I follow step by step what tutorial said but it doesnt work. :(

WoFFeN88 gravatar imageWoFFeN88 ( 2018-12-11 11:41:30 -0600 )edit

If it works with a webcam it means that you can save the video. Your problem is in cv2.VideoCapture("myVideo.mp4") ?

can you check video path ? what is your opencv version ? which codec is used in myVideo.mp4 ?

for libx264 you will need cisco dll

LBerger gravatar imageLBerger ( 2018-12-11 11:49:48 -0600 )edit

Yes, the video save in the correct folder, but when I try to execute it doesn't work... I downloaded codecs from fourcc.org but I have the same problem.

WoFFeN88 gravatar imageWoFFeN88 ( 2018-12-11 12:34:31 -0600 )edit

you must use cisco dll with opencv_ffmpeg

LBerger gravatar imageLBerger ( 2018-12-11 13:06:18 -0600 )edit

@WoFFeN88.At first posted doesn't and the links solved your probem and also the links. I have done this before last year by using raspberry pi camera and webcam. I do not have it with me right now. I think it is about 20 lines.

supra56 gravatar imagesupra56 ( 2018-12-12 10:04:53 -0600 )edit

I dont understand what you try to say me... But I didn't solve the problem. I tried with many extensions, installing the codecs, following tutorials, and reading about in forums but nothing allow me to save the video correctly, just save the video on folder and when I click on it, doesn't work... I had been following even books of openCV... nothing happens... :( thank you for response.

WoFFeN88 gravatar imageWoFFeN88 ( 2018-12-12 11:40:00 -0600 )edit

@WoFFeN88You can't. It is not available on books, links, etc. playing mp4 to write avi is obsoleted. I will get back to you. Sorry for prevoiusly commeted. I erased some of my comment I will rephrased..At first posted and the links dosen't solved your problem.

supra56 gravatar imagesupra56 ( 2018-12-12 11:52:48 -0600 )edit