Skip to content

Latest commit

Β 

History

History
49 lines (32 loc) Β· 1.68 KB

File metadata and controls

49 lines (32 loc) Β· 1.68 KB

Working with VIDEO & Webcam


VIDEO Processing Workflow

Webcam Video Stream -> Capture Video -> Process Frames -> Save Video -> Processed Video


Video Components
  1. Video : collection of images shown rapidly
  2. Webcam : records the live video
  3. Frame by Frame processing : processing each image(frame) from the collection of images

cv2.VideoCapture(source)
  • helps to open webcam , video file ; enables us to read frame by frame ; display single frame or frame by frame.
  • basically read frames
  • source -> to operate webcam { 0 : in-built webcam , 1 : external webcam }
cv2.VideoWriter()
Saving webcam video to a file using OpenCV

This process is a little complex so we are going to break it down into 2 levels.

  • Level 1

    • VideoCapture(0) -> VideoWriter() -> cap.release()
  • Level 2

    • open webcam -> what will be the width and height of the frame in video
    • start recording -> start saving the file -> show saved frames -> quit

Now lets understand cv2.VideoWriter()

Syntax -> cv2.VideoWriter(filename , codec , fps , frame_size)

  • codec -> saves in .mp4 or .avi(audio video interleave) generally .avi using XVIDCodec ; these things must be given in compression code format

  • fps -> frame per second , how smooth you want your video to be

.isOpened()

This method is used to play a video using OpenCV. The whole loop we use during cv2.VideoCapture() is used in here but instead of recording that is passing 0 as source we pass the video location.