(directory, orange_file)
return directories
Split multiple videos on orange frame separators
Split multiple videos on orange frame separators
Split multiple videos on orange frame separators
def split_videos(directory, orange_file):
    """Split multiple videos on orange frame separators"""
    logging.debug(
        "Splitting video on orange frames (this may take a while)...")
    directories = []
    current = 0
    found_orange = False
    video_dir = None
    frames = sorted(glob.glob(os.path.join(directory, 'video-*.png')))
    if len(frames):
        for frame in frames:
            if is_color_frame(frame, orange_file):
                if not found_orange:
                    found_orange = True
                    # Make a copy of the orange frame for the end of the
                    # current video
                    if video_dir is not None:
                        dest = os.path.join(video_dir, os.path.basename(frame))
                        shutil.copyfile(frame, dest)
                    current += 1
                    video_dir = os.path.join(directory, str(current))
                    logging.debug("Orange frame found: %s, starting video directory %s",
                                  frame, video_dir)
                    if not os.path.isdir(video_dir):
                        os.mkdir(video_dir, 0o755)
                    if os.path.isdir(video_dir):
                        video_dir = os.path.realpath(video_dir)
                        clean_directory(video_dir)
                        directories.append(video_dir)
                    else:
                        video_dir = None
            else:
                found_orange = False
            if video_dir is not None:
                dest = os.path.join(video_dir, os.path.basename(frame))
                os.rename(frame, dest)
            else:
                logging.debug("Removing spurious frame %s at the beginning", frame)
                os.remove(frame)
    return directories
def split_videos ( directory , orange_file ) : logging . debug ( "Splitting video on orange frames (this may take a while)..." ) directories = [ ] current = 0 found_orange = False video_dir = None frames = sorted ( glob . glob ( os . path . join ( directory , 'video-*.png' ) ) ) if len ( frames ) : for frame in frames : if is_color_frame ( frame , orange_file ) : if not found_orange : found_orange = True # Make a copy of the orange frame for the end of the # current video if video_dir is not None : dest = os . path . join ( video_dir , os . path . basename ( frame ) ) shutil . copyfile ( frame , dest ) current += 1 video_dir = os . path . join ( directory , str ( current ) ) logging . debug ( "Orange frame found: %s, starting video directory %s" , frame , video_dir ) if not os . path . isdir ( video_dir ) : os . mkdir ( video_dir , 0o755 ) if os . path . isdir ( video_dir ) : video_dir = os . path . realpath ( video_dir ) clean_directory ( video_dir ) directories . append ( video_dir ) else : video_dir = None else : found_orange = False if video_dir is not None : dest = os . path . join ( video_dir , os . path . basename ( frame ) ) os . rename ( frame , dest ) else : logging . debug ( "Removing spurious frame %s at the beginning" , frame ) os . remove ( frame ) return directories