Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python cv2 write to video

import cv2
vid_capture = cv2.VideoCapture('Resources/Cars.mp4')
if (vid_capture.isOpened() == False):
  print("Error opening the video file")
else:
  # Get frame rate information
  fps = int(vid_capture.get(5))
  print("Frame Rate : ",fps,"frames per second") 
  # Get frame count
  frame_count = vid_capture.get(7)
  print("Frame count : ", frame_count)

while(vid_capture.isOpened()):
  ret, frame = vid_capture.read()
  if ret == True:
    cv2.imshow('Frame',frame)
    k = cv2.waitKey(20)
    # 113 is ASCII code for q key
    if k == 113:
      break
  else:
    break

vid_capture.release()
cv2.destroyAllWindows()
vid_capture = cv2.VideoCapture('Resources/Image_sequence/Cars%04d.jpg')
vic_capture = cv2.VideoCapture(0,cv2.CAP_DSHOW)
frame_width = int(vid_capture.get(3))
frame_height = int(vid_capture.get(4))
frame_size = (frame_width,frame_height)
fps = 20
output = cv2.VideoWriter('Resources/output_video_from_file.avi', cv2.VideoWriter_fourcc('M','J','P','G'), 20, frame_size)
while(vid_capture.isOpened()):
    ret, frame = vid_capture.read()
    if ret == True:
           output.write(frame)
    else:
         print(‘Stream disconnected’)
           break
vid_capture.release()
output.release()
Comment

PREVIOUS NEXT
Code Example
Python :: conda create environment python 3 
Python :: how to convert numpy array to cv2 image 
Python :: pandas where retuning NaN 
Python :: start process python 
Python :: static files not loading 404 error django 
Python :: remove na python 
Python :: how to type using selenium python 
Python :: check palindrome in python 
Python :: days in month function python 
Python :: how to let only admins do a command in discord.py 
Python :: python pandas read_excel 
Python :: binary search python 
Python :: find number of unique keys in the dictionary 
Python :: python get 2d array output as matrix 
Python :: get return value from transaction in brownie 
Python :: python turn positive into negative 
Python :: how to convert datetime to integer in python 
Python :: while loop odd numbers python 
Python :: associate keys as list to values in python 
Python :: split and only grab first part of string 
Python :: combine dictionaries, values to list 
Python :: basic string functions in python 
Python :: find total no of true in a list in python 
Python :: logging.basicConfig() 
Python :: load python file in jupyter notebook 
Python :: python datetime move forward one day 
Python :: how to install package offline 
Python :: Filter Pandas rows by specific string elements 
Python :: append a list to a list python 
Python :: python if elif else 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =