extract images from the video
|
|
@ -0,0 +1,44 @@
|
|||
import cv2
|
||||
import numpy as np
|
||||
|
||||
# Open the video file
|
||||
cap = cv2.VideoCapture("video_signal.mp4")
|
||||
|
||||
# Get the video frames per second (fps) and frame size
|
||||
fps = cap.get(cv2.CAP_PROP_FPS)
|
||||
frame_size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
|
||||
int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
|
||||
|
||||
# Define the desired output frame rate and the codec
|
||||
output_fps = 24.0
|
||||
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
|
||||
|
||||
# Create a video writer object
|
||||
out = cv2.VideoWriter("output.mp4", fourcc, output_fps, frame_size)
|
||||
|
||||
# Create a buffer to store the previous frame
|
||||
previous_frame = None
|
||||
|
||||
# Loop over the frames of the input video
|
||||
while True:
|
||||
ret, frame = cap.read()
|
||||
if not ret:
|
||||
break
|
||||
|
||||
# Skip every (fps / output_fps) - 1 frame
|
||||
if previous_frame is not None and (fps / output_fps) > 1.5:
|
||||
skip_frame = int(fps / output_fps) - 1
|
||||
for i in range(skip_frame):
|
||||
cap.grab()
|
||||
else:
|
||||
# Interpolate the frame to match the desired output frame rate
|
||||
if previous_frame is not None:
|
||||
frame = (previous_frame + frame) / 2.0
|
||||
previous_frame = frame
|
||||
|
||||
# Write the frame to the output video
|
||||
out.write(np.uint8(frame))
|
||||
|
||||
# Release the video capture and writer objects
|
||||
cap.release()
|
||||
out.release()
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
import cv2
|
||||
|
||||
# Open the video file
|
||||
cap = cv2.VideoCapture("output.mp4")
|
||||
|
||||
# Get the video frames per second (fps) and frame size
|
||||
fps = cap.get(cv2.CAP_PROP_FPS)
|
||||
frame_size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
|
||||
int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
|
||||
|
||||
# Calculate the number of frames in the first 30 seconds of the video
|
||||
total_frames = int(fps * 30)
|
||||
|
||||
# Define the codec and create a video writer object
|
||||
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
|
||||
out = cv2.VideoWriter("output2.mp4", fourcc, fps, frame_size)
|
||||
|
||||
# Loop over the first 30 seconds of the video
|
||||
for i in range(total_frames):
|
||||
ret, frame = cap.read()
|
||||
if not ret:
|
||||
break
|
||||
|
||||
# Write the frame to the output video
|
||||
out.write(frame)
|
||||
|
||||
# Release the video capture and writer objects
|
||||
cap.release()
|
||||
out.release()
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
import cv2
|
||||
import os
|
||||
|
||||
# Open the video file
|
||||
cap = cv2.VideoCapture("output2.mp4")
|
||||
|
||||
# Get the video frames per second (fps) and frame size
|
||||
fps = cap.get(cv2.CAP_PROP_FPS)
|
||||
frame_size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
|
||||
int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
|
||||
|
||||
# Calculate the number of frames in the first 30 seconds of the video
|
||||
total_frames = int(fps * 30)
|
||||
|
||||
# Create a directory to store the extracted frames
|
||||
os.makedirs("frames", exist_ok=True)
|
||||
|
||||
# Loop over the first 30 seconds of the video
|
||||
for i in range(total_frames):
|
||||
ret, frame = cap.read()
|
||||
if not ret:
|
||||
break
|
||||
|
||||
# Save the frame as an image
|
||||
filename = f"frames/frame_{i:05d}.jpg"
|
||||
cv2.imwrite(filename, frame)
|
||||
|
||||
# Release the video capture object
|
||||
cap.release()
|
||||
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 77 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 63 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 70 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 70 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 63 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 70 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 63 KiB |
|
After Width: | Height: | Size: 67 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 70 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 62 KiB |
|
After Width: | Height: | Size: 67 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 74 KiB |