def main(): # Extract specific number of key frames from video # if os.name == 'nt': # multiprocessing.freeze_support() vd = Video() # folder to save extracted images output_folder_video_image = "selectedframes" out_dir_path = os.path.join(".", output_folder_video_image) if not os.path.isdir(out_dir_path): os.mkdir(out_dir_path) # number of images to be returned no_of_frames_to_returned = 20 # VIdeo file path video_file_path = os.path.join(".", "tests", "data", "pos_video.mp4") print(f"Input video file path = {video_file_path}") imgs = vd.extract_frames_as_images(no_of_frames=no_of_frames_to_returned, file_path=video_file_path) # Save it to disk for counter, img in enumerate(imgs): vd.save_frame_to_disk( img, file_path=out_dir_path, file_name="test_" + str(counter), file_ext=".jpeg", ) print(f"Exracted key frames file path = {out_dir_path}")
def main(): # Extract specific number of key frames from video vd = Video() # folder to save extracted images output_folder_video_image = "selectedframes" if not os.path.isdir(os.path.join(".", output_folder_video_image)): os.mkdir(os.path.join(".", output_folder_video_image)) # number of images to be returned no_of_frames_to_returned = 12 # VIdeo file path video_file_path = os.path.join(".", "tests", "data", "pos_video_2.mp4") print(f"video_file_path = {video_file_path}") imgs = vd.extract_frames_as_images(no_of_frames=no_of_frames_to_returned, file_path=video_file_path) # Save it to disk for counter, img in enumerate(imgs): vd.save_frame_to_disk( img, file_path=output_folder_video_image, file_name="test_" + str(counter), file_ext=".jpeg", )
def get_key_frames_from_video(path_to_video, no_of_frames): print('getting key frames from video') try: video = Video() print('begin extraction') images = video.extract_frames_as_images(no_of_frames=no_of_frames, file_path=path_to_video) print('end extraction') return images except Exception as e: print('error getting frames from videos') print(e)
def main(): # Extract specific number of key frames from video # if os.name == 'nt': # multiprocessing.freeze_support() os.chdir("/content/drive/My Drive") vid = Video() # folder to save extracted images output_folder_path = "selectedframes" output_directory = os.path.join(".", output_folder_path) if not os.path.isdir(output_directory): os.mkdir(output_directory) # number of images to be returned needed_frames = 10 # VIdeo file path video_path = os.path.join("/","content", "drive","My Drive","test2.mp4") print(f"Input video file path = {video_path}") images = vid.extract_frames_as_images( no_of_frames=needed_frames, file_path=video_path ) # Save it to disk for counter, img in enumerate(images): vid.save_frame_to_disk( img, file_path=output_directory, file_name="test_" + str(counter), file_ext=".jpeg", ) print(f"Exracted key frames file path = {output_directory}") #calling the driver function if __name__ == "__main__": multiprocessing.set_start_method('spawn', force=True) main()
def get_key_frames_from_video(path_to_video, no_of_frames): video = Video() images = video.extract_frames_as_images(no_of_frames=no_of_frames, file_path=path_to_video) return images
print(foldername) filename = 'drive/My Drive/Processedvideo/highlights_without_replay/clip' + str( count) + '.mp4' clip_extraction(filename, foldername) count = count + 1 from Katna.video import Video import os import cv2 vd = Video() clip_name = os.listdir('drive/My Drive/Processedvideo/highlights') count1 = 0 for name in clip_name: count1 = count1 + 1 filename = 'drive/My Drive/Processedvideo/highlights/' + name imgs = vd.extract_frames_as_images(no_of_frames=30, file_path=filename) foldername = 'drive/My Drive/Processedvideo/KeyFrames/clip' + str(count1) if not os.path.exists(foldername): os.makedirs(foldername) count2 = 1 for img in imgs: img_name = foldername + '/' + str(count2) + '.jpg' print(img_name) cv2.imwrite(img_name, img) count2 = count2 + 1 from google.colab.patches import cv2_imshow for img in imgs: resized = cv2.resize(img, (500, 500), interpolation=cv2.INTER_AREA) cv2_imshow(resized)