Video Files
You can extract frames out of video files using landingai.image_source.VideoFile
.
The example below iterates over each frame of a video, resizes it and saves it to a new video file.
from landingai.pipeline.image_source import VideoFile
from landingai.pipeline.frameset import FrameSet
frameset = FrameSet() # (1)!
with VideoFile("/path/to/your/file.mp4", samples_per_second=5) as video_file: # (2)!
for frame in video_file: # (3)!
frame.resize(width=256) # (4)!
frameset.append(frame) # (5)!
frameset.save_video("/tmp/resized-video.mp4") # (6)!
- Creates an empty
FrameSet
, where we will store the modified frames - Open
/path/to/your/file.mp4
video file, at a rate of 5 frames per second. - Iterate over each frame of the video file
- Resize the frame to
width=256px
(keeping aspect ratio) - Append the resized frame to the
FrameSet
- Save the resized video to
/tmp/resized-video.mp4
.