示例#1
0
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",
        )
示例#2
0
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}")
示例#3
0
def write_images_into_folder(images, no_of_frames, path):
    video = Video()
    for i in range(no_of_frames):
        video.save_frame_to_disk(images[i],
                                 file_path=path,
                                 file_name="image" + str(i + 1),
                                 file_ext=".png")
示例#4
0
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)
示例#5
0
def write_images_into_folder(images, no_of_frames, path):
    print('writing images into folder')
    print(no_of_frames)
    print(path)
    try:
        video = Video()
        for i in range(no_of_frames):
            print('saving ' + str(i + 1) + ' frame')
            video.save_frame_to_disk(images[i],
                                     file_path=path,
                                     file_name="image" + str(i + 1),
                                     file_ext=".png")
    except Exception as e:
        print('error saving extracted frames to disk')
        print(e)
示例#6
0
def kframe_test():
    vd = Video()
    from datetime import datetime
    dt_start = datetime.now()
    test_video_path = '/Users/omelnyk/Work/vidiscovery-recognition/data/KALUSH feat alyona alyona  Гори_v720P.mp4'
    duration = vd._get_video_duration_with_ffmpeg(test_video_path)
    print(int(duration))
    imgs = vd.extract_video_keyframes(no_of_frames=int(duration), file_path=test_video_path)
    print(len(imgs))
    print("extraction time: " + str((datetime.now() - dt_start).total_seconds()))
    _, axs = plt.subplots(4, 5, figsize=(20, 20))
    axs = axs.flatten()
    for img, ax in zip(imgs, axs):
        ax.imshow(img)
    plt.show()
def main_single_video():

    # resize the pos_video.mp4 in same directory with na,e pos_video_resize.mp4
    abs_file_path_output = os.path.join(".", "tests", "data",
                                        "pos_video_resize.mp4")
    file_path = os.path.join(".", "tests", "data", "pos_video.mp4")

    vd = Video(autoflip_build_path, autoflip_model_path)

    # update configuration
    app_config.MediaPipe.AutoFlip.set_conf(conf)

    try:
        vd.resize_video(file_path=file_path,
                        abs_file_path_output=abs_file_path_output,
                        aspect_ratio=aspect_ratio)
    except Exception as e:
        raise e
    print(f"output resized video file path = {abs_file_path_output}")
def main_folder():
    dir_path = file_path = os.path.join(".", "tests", "data")

    # will create a resize_result dir inside data folder and dump videos there
    abs_dir_path_output = os.path.join(".", "tests", "data", "resize_results")

    vd = Video(autoflip_build_path, autoflip_model_path)

    # update configuration
    app_config.MediaPipe.AutoFlip.set_conf(conf)

    try:
        vd.resize_video_from_dir(dir_path=dir_path,
                                 abs_dir_path_output=abs_dir_path_output,
                                 aspect_ratio=aspect_ratio)
    except Exception as e:
        raise e

    print(f"output resized video dir path = {abs_dir_path_output}")
示例#9
0
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()
示例#10
0
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
    count = 1
    for filename in glob.glob(
            "drive/My Drive/Processedvideo/highlights_without_replay/*.mp4"):
        foldername = 'drive/My Drive/Processedvideo/keyframe/clip' + str(count)
        if not os.path.exists(foldername):
            os.makedirs(foldername)
        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