Skip to content
Snippets Groups Projects
Commit 3af92d8b authored by Hussain Kanafani's avatar Hussain Kanafani
Browse files

extract frames from videos

parent 90a737bc
No related branches found
No related tags found
No related merge requests found
import os
import cv2
import subprocess
import argparse
def resize_(img_path, width, height):
img = cv2.imread('/home/img/python.png', cv2.IMREAD_UNCHANGED)
dim = (width, height)
resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
return resized
def video2frames(video_path, fps, out_img_dir):
subprocess.call('ffmpeg -i {video} -vf fps={fps} {out_img_dir}/frame%06d.png'.format(
video=video_path,
fps=fps,
out_img_dir=out_img_dir
), shell=True)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Extract frames')
parser.add_argument('--videos_dir', metavar='DIR',
default='./videos',
help='path input videos')
parser.add_argument('--fps', default=2, type=int,
help='Frames per second for the extraction')
parser.add_argument('--out_dir',
default='frames/video',
help='path to extracted frames')
args = parser.parse_args()
videos_dir = args.videos_dir
fps = args.fps
out_dir = args.out_dir
for idx, video in enumerate(os.listdir(videos_dir)):
frames_dir = '{}{}'.format(out_dir, int(idx + 1))
print(frames_dir)
if not os.path.exists(frames_dir):
os.makedirs(frames_dir)
video = os.path.join(videos_dir, video)
video2frames(video, 2, frames_dir)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment