openCV video saving in python

user4594264

I am trying to save the video but it's not working. I followed the instructions from the openCV documentation.

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

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

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==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()

What is wrong?

Nurul Akter Towhid

Try this. It's working for me.

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

# Define the codec and create VideoWriter object
#fourcc = cv2.cv.CV_FOURCC(*'DIVX')
#out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
out = cv2.VideoWriter('output.avi', -1, 20.0, (640,480))

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

        # write the flipped frame
        out.write(frame)

        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Saving a Video in OpenCV (Linux, Python)

From Dev

Saving a video capture in python with openCV : empty video

From Dev

Opencv Saving Video

From Dev

Reading video and saving in pgm format images using python-openCV

From Dev

OpenCV (Python) video subplots

From Dev

No video output OpenCV Python

From Dev

Read a video in opencv (python)

From Dev

Python opencv video writer

From Dev

Cannot open video in OpenCV (Python)

From Dev

How to record video using OpenCV and Python?

From Dev

Specify Compression Quality in Python for OpenCV Video Object

From Dev

How to Capture Video Stream with OpenCV (Python)

From Dev

Limiting video capture frame rate on python and opencv

From Dev

Not able to play video in opencv (Python 2.7)

From Dev

Python OpenCV video format play in browser

From Dev

Python creating video from images using opencv

From Dev

How to generate a video with python, matplotlib and opencv?

From Dev

video not refreshing when using OpenCV in python

From Dev

video is saving but showing 0 KB only. What is the probable error in these code of OpenCv

From Dev

Saving videos doesnt work in opencv2-python

From Dev

OpenCV and Python: object tracking and saving the object being tracked as an image

From Dev

Saving videos doesnt work in opencv2-python

From Dev

Saving real time data into txt file in python from opencv

From Dev

Saving blob video with php

From Dev

Saving Video Files in Rails

From Dev

Android saving a video to a file

From Dev

Saving video with EMGU

From Dev

AVCaptureSession Video Not Saving

From Dev

Saving video to DocumentsDirectory