def vid_preprocess(og_vid_dir, demo_dir, predict_label, in_fps, out_fps, width, height):
    vid_dir = set_dir(og_vid_dir)
    in_fps = float(in_fps)
    out_fps = float(out_fps)
    vid_size = (width, height)

    label = expand_label(predict_label, fps=int(in_fps))
    vid_total_frame = label.shape[0]

    # video list for saving videos
    vid_arr = []
    for vid_num in range(len(vid_dir)):
        start_frame = vid_dir[vid_num][1]
        end_frame = vid_dir[vid_num][1] + vid_total_frame
        vid_arr.append(VideoFileClip(vid_dir[vid_num][0]).subclip(frame_to_time(start_frame, out_fps),
                                                                  frame_to_time(end_frame, out_fps)))
    # make stage mix array
    stage_mix_arr = []
    for frame in range(vid_total_frame):
        # extract frame in numpy array
        vid_frame = frame_extract(vid_arr, frame, label[frame], out_fps, vid_size)

        # numpy array to ImageClip in moviepy
        vid_frame = ImageClip(vid_frame).set_duration(1 / out_fps)
        stage_mix_arr.append(vid_frame)
        print(frame)

    concat_clip = concatenate_videoclips(stage_mix_arr)
    out_vid_name = join(demo_dir, 'demo.mp4')
    concat_clip.write_videofile(out_vid_name, fps=out_fps)
    concat_clip.close()
    del stage_mix_arr
    del concat_clip
def make_stage_mix(og_vid_dir, demo_dir, predict_label, in_fps, out_fps, width,
                   height):
    _, _, vid_dir = set_dir(og_vid_dir)
    in_fps = float(in_fps)
    out_fps = float(out_fps)
    vid_size = (width, height)
    label = expand_label(predict_label, fps=int(in_fps))
    mix_clip_frames = label.shape[0]

    # video list for saving videos
    vid_clip = origin_vid_clip_read(vid_dir, mix_clip_frames, out_fps)

    # make stage mix array
    stage_mix_arr = []
    for frame in range(mix_clip_frames):
        # extract frame in numpy array
        vid_frame = frame_extract(vid_clip, frame, label[frame], out_fps,
                                  vid_size)
        # numpy array to ImageClip in moviepy
        vid_frame = ImageClip(vid_frame).set_duration(1 / out_fps)
        stage_mix_arr.append(vid_frame)

    concat_clip = concatenate_videoclips(stage_mix_arr)
    out_vid_name = join(demo_dir, 'demo.mp4')
    concat_clip.write_videofile(out_vid_name, fps=out_fps)
    concat_clip.close()
    del stage_mix_arr
    del concat_clip
Esempio n. 3
0
def vid_preprocess(base_dir, out_dir, first_vid_num):
    # setting directory
    _, label_dir, _ = set_dir(base_dir)
    # read csv label and change label sequentially
    next_label = change_label(label_dir, first_vid_num)

    # write label
    with open(out_dir, "a") as output:
        writer = csv.writer(output, lineterminator='\n')
        for i in range(next_label.shape[0]):
            value = [i, next_label[i]]
            writer.writerow(value)
Esempio n. 4
0
def vid_preprocess(args):
    vid_dir = set_dir(args.in_dir)
    in_fps = float(args.in_fps)
    out_fps = float(args.out_fps)
    split_num = args.split_num
    vid_size = (args.width, args.height)

    label = read_csv(args.label_dir)
    label = expand_label(label, fps=int(in_fps))
    vid_total_frame = label.shape[0]

    # video list for saving videos
    vid_arr = []
    for vid_num in range(len(vid_dir)):
        start_frame = vid_dir[vid_num][1]
        end_frame = vid_dir[vid_num][1] + vid_total_frame
        vid_arr.append(
            VideoFileClip(vid_dir[vid_num][0]).subclip(
                frame_to_time(start_frame, out_fps),
                frame_to_time(end_frame, out_fps)))
    # make stage mix array in split
    for i in range(split_num):
        stage_mix_arr = []
        total_split = int(vid_total_frame / split_num)
        for frame in range(total_split):
            # extract frame in numpy array
            now_frame = total_split * i + frame
            vid_frame = frame_extract(vid_arr, now_frame, label[now_frame],
                                      out_fps, vid_size)

            # =========================
            # scene change property
            # if you want to add scene change, change this part
            # =========================

            # numpy array to ImageClip in moviepy
            vid_frame = ImageClip(vid_frame).set_duration(1 / out_fps)
            stage_mix_arr.append(vid_frame)
            print(now_frame)

        concat_clip = concatenate_videoclips(stage_mix_arr)
        out_vid_name = join(args.out_dir,
                            args.vid_folder + '_' + str(i) + '_.mp4')
        concat_clip.write_videofile(out_vid_name, fps=out_fps)
        concat_clip.close()
        del stage_mix_arr
        del concat_clip
def stage_mix_split(args):
    _, _, vid_dir = set_dir(args.in_dir)
    in_fps = float(args.in_fps)
    out_fps = float(args.out_fps)
    split_num = args.split_num
    vid_size = (args.vid_w, args.vid_h)
    effect_num = args.effect_num

    label = read_label(args.label_dir)
    label = expand_label(label, fps=int(in_fps))
    effect_frames = find_effect_frame(label, effect_num)
    mix_clip_frames = label.shape[0]

    # video list for saving videos
    vid_clip = origin_vid_clip_read(vid_dir, mix_clip_frames, out_fps)

    # make stage mix array in split
    changed_frames = 0
    for i in range(split_num):
        total_split = int(mix_clip_frames / split_num)
        split_frame = total_split * i
        print('start split_num')
        for i, frame in enumerate(range(changed_frames, total_split)):
            if i == 0:
                changed_frames = 0

            # extract frame in numpy array
            now_frame = split_frame + frame + changed_frames

            # =========================
            # scene change property
            # if you want to add scene change, change this part
            if now_frame in effect_frames:
                # bbox effect
                # search_result = bbox_search()
                # if search_result:
                #     bbox_effect()
                # scene change
                # else:

                # 투명도 전환

                changed_frames += effect_num * 2
            else:
                vid_frame = frame_extract(vid_clip, now_frame, label[now_frame], out_fps, vid_size)
                print(now_frame)
Esempio n. 6
0
def vid_labeling(args):
    base_dir = args.base_dir
    mix_dir, label_dir, vid_dir = set_dir(base_dir)
    vid_size = (args.vid_w, args.vid_h)
    fps = args.fps
    # CSV file writer
    CSVlogger = LogCSV(log_dir=join(base_dir, "label.csv"))

    mix_clip = mix_vid_clip_read(mix_dir, fps)
    mix_clip_frames = int(mix_clip.fps * mix_clip.duration)
    vid_clip = origin_vid_clip_read(vid_dir, mix_clip_frames, fps)

    # show video video frames in window
    for frame in range(mix_clip_frames):
        # first column
        vid0 = frame_extract(vid_clip, frame, 0, fps, vid_size)
        vid1 = frame_extract(vid_clip, frame, 1, fps, vid_size)
        vid2 = frame_extract(vid_clip, frame, 2, fps, vid_size)
        img1 = np.concatenate((vid0, vid1, vid2), axis=0)

        # second column
        vid3 = frame_extract(vid_clip, frame, 3, fps, vid_size)
        mix = frame_extract(mix_clip, frame, None, fps, vid_size)
        vid4 = frame_extract(vid_clip, frame, 4, fps, vid_size)
        img2 = np.concatenate((vid3, mix, vid4), axis=0)

        # third column
        vid5 = frame_extract(vid_clip, frame, 5, fps, vid_size)
        vid6 = frame_extract(vid_clip, frame, 6, fps, vid_size)
        vid7 = frame_extract(vid_clip, frame, 7, fps, vid_size)
        img3 = np.concatenate((vid5, vid6, vid7), axis=0)

        # concat all column
        img = np.concatenate((img1, img2, img3), axis=1)
        cv2.imshow("", img)
        k = int(cv2.waitKey(0))
        # 0 is 48 in window
        # below value is ubuntu setting, if you use windows system, please delete below operation
        k -= 48
        print(k)

        CSVlogger([frame, k])
Esempio n. 7
0
def stage_mix_split(args):
    _, _, vid_dir = set_dir(args.in_dir)
    in_fps = float(args.in_fps)
    out_fps = float(args.out_fps)
    split_num = args.split_num
    vid_size = (args.vid_w, args.vid_h)

    label = read_label(args.label_dir)
    label = expand_label(label, fps=int(in_fps))
    mix_clip_frames = label.shape[0]

    # video list for saving videos
    vid_clip = origin_vid_clip_read(vid_dir, mix_clip_frames, out_fps)

    # make stage mix array in split
    for i in range(split_num):
        stage_mix_arr = []
        total_split = int(mix_clip_frames / split_num)
        for frame in range(total_split):
            # extract frame in numpy array
            now_frame = total_split * i + frame
            vid_frame = frame_extract(vid_clip, now_frame, label[now_frame],
                                      out_fps, vid_size)

            # =========================
            # scene change property
            # if you want to add scene change, change this part
            # =========================

            # numpy array to ImageClip in moviepy
            vid_frame = ImageClip(vid_frame).set_duration(1 / out_fps)
            stage_mix_arr.append(vid_frame)
            print(now_frame)

        concat_clip = concatenate_videoclips(stage_mix_arr)
        out_vid_name = join(args.out_dir,
                            args.vid_folder + '_' + str(i) + '_.mp4')
        concat_clip.write_videofile(out_vid_name, fps=out_fps)
        concat_clip.close()
        del stage_mix_arr
        del concat_clip