Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i make video to pause/continue while recording? [closed]

Tags:

python

opencv

How can I make video to pause/continue while recording in OpenCV Python?

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):
   # Capture frame-by-frame
   ret, frame = cap.read()

   out.write(frame)
  # Display the resulting frame
   cv2.imshow('video recording', frame)

   if cv2.waitKey(1) & 0xFF == ord('q'):
       break
   # When everything done, release the capture
     cap.release()
    out.release()
    cv2.destroyAllWindows()
like image 308
Nouran Adel Avatar asked Oct 22 '25 04:10

Nouran Adel


1 Answers

You'll get continuous frames from the VideoCapture live feed. You can set a flag to decide whether a frame should be written or not:

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))
isRecording=true
while (cap):
   # Capture frame-by-frame
   ret, frame = cap.read()
   if(isRecording):#read the boolean to decide whether to write frame or not
        out.write(frame)
  # Display the resulting frame
   cv2.imshow('video recording', frame)

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

   if cv2.waitKey(1) & 0xFF == ord('p'):#Pause
       isRecording=false
   if cv2.waitKey(1) & 0xFF == ord('c'):#Continue
       isRecording=true

   # When everything done, release the capture
    cap.release()
    out.release()
    cv2.destroyAllWindows()
like image 93
Saransh Kejriwal Avatar answered Oct 23 '25 19:10

Saransh Kejriwal