# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # MSDS696 Project II: Object Detection in Home Video Sercurity Systems
# # Preprocessing  Data
# ## <NAME> 
# ### Ring door bell  

#Imports
import os
from moviepy.editor import *


def video_preprocess(file):
    """receives an mp4 file name, loads the file as a 
    moviepy video clip, cuts it down to 30 seconds, discards the audio and saves
    the output in a "./Data/Processed/"  directory as 'edited_filname.mp4'
    """
    clip=VideoFileClip(join(path_raw, file)).subclip(t_end=30)
    # decrease size to 640px width
    clip=clip.resize(width=640)
    new_filename="edited_"+file
    #write the result to a file
    clip.write_videofile(join(path_processed,new_filename), audio=False) # do not render audio
    clip.reader.close() #to avoid ffmpeg ghost processes when running on Windows
    if clip.audio and clip.audio.reader:
        clip.audio.reader.close_proc()


currentpath=os.getcwd() #current working directory
path_raw=currentpath + "\\Data\\Raw" #path to the raw video files
path_processed=currentpath +"\\Data\\Processed" #path to the processd video files folder

# Make a list of all raw video files
from os import listdir
from os.path import isfile, join
list_videos=[f for f in listdir(path_raw) if isfile(join(path_raw, f))]
#number of raw video files found
len(list_videos)

#call video_preprocess function for all files in the Raw folder
for file in list_videos:
    video_preprocess(file)    

# Optional preview results - this step increases the size of the notebook as video is embeded
#load the processed clip and preview the results
#include chosen file name
clip2=VideoFileClip("..\\Data\\Processed\\edited_file.mp4")
clip2.ipython_display(width=640)



StarcoderdataJupyterScriptsDedupFiltered