Optimize the clip by keeping same functionality. code :import os import shutil import…
- User
Optimize the clip by keeping same functionality. code :import os import shutil import moviepy.editor as mp import openai import re from openai_helper import openai, generate_description import os from moviepy.editor import * from moviepy.video import fx from moviepy.video.fx import all as fx from PIL import ImageOps #from create_text_clip_overlay import create_text_clip from create_image_with_text import create_image_with_text from TESTINGvideo_creation import create_final_clip
Set the size of the final video
size = (1080, 1920)
Time to delay top attributes
delayins=5 fps_size=30
Set the directory where all the files are stored
dir_path = "C:/Python/VideoCreationTiktok/Source/" dir_path_output = "C:/Python/VideoCreationTiktok/Output/" #File to edit
TODO: EDIT this
#main_video_path = os.path.join(dir_path, "main_video1.mp4")
set the folder path for folder management
folder_path = "E:/SMART AI BOTS/Selected"
loop through all video files in the folder
for filename in os.listdir(folder_path): if filename.endswith(".mp4") or filename.endswith(".avi"): # extract the name, channel, description, and hashtags from the filename name = filename.rsplit(".", 1)[0] channel, desc_hashtags = name.split("-", 1)
desc_end_index = desc_hashtags.find("#") if desc_end_index != -1: desc = desc_hashtags[:desc_end_index].strip() hashtags = desc_hashtags[desc_end_index:].strip() else: desc = desc_hashtags.strip() hashtags = "" # print the variables for debugging purposes print(f"name: {name}") #print(f"channel: {channel}") #print(f"desc: {desc}") #print(f"hashtags: {hashtags}") # generate a description using ChatGPT prompt = f"Write a short, attention-grabbing, clickbaity description for a video as a statement. Use maximum 8 words and provide only one final result, all capital letters. This is the title: '{desc} {hashtags}'" description = generate_description(prompt) print(f"prompt: {prompt}") print(f"description: {description}") # clean up the description for use as a file name clean_description = re.sub(r'[^\w\s#-&:]','',f"{description} {hashtags}") print(f"description2: {clean_description}") clean_description = re.sub(r"\s{2,}", " ", clean_description.strip()) clean_description = re.sub(r'#+', '#', clean_description.strip()) clean_description = re.sub(r':', '-', clean_description.strip()) trimed_file_name = f"{clean_description}.mp4" print(f"description3 trimmed: {trimed_file_name}") #TODO:REMOVE # trim the video to one second video_path = os.path.join(folder_path, filename) # Get the length of the main video main_video_path=f"{folder_path}/{filename}" #path = folder path we sceraping + file name found main_video = VideoFileClip(main_video_path) main_video_length = main_video.duration # ALL EDITING GOES HERE text_center= description final_clip=create_final_clip(text_center, main_video_path) #Save final video to final folder final_path = os.path.join(folder_path, "Final", trimed_file_name) final_clip.duration=3 final_clip.write_videofile(final_path,fps=fps_size) final_clip.close() # move the original video to the Used folder original_path = os.path.join(folder_path, filename) used_path = os.path.join(folder_path, "Used", filename) shutil.move(original_path, used_path) - Assistant
- User
Traceback (most recent call last): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\shutil.py", line 816, in move os.rename(src, real_dst) PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'E:/SMART AI BOTS/Selected\bjornevag_ - Part 12 Websites that feels ILLEGAL to use #Websites #onlinetools #AI #useful #website #coolwebsites #websitesyouneed .mp4' -> 'E:/SMART AI BOTS/Selected\Used\bjornevag_ - Part 12 Websites that feels ILLEGAL to use #Websites #onlinetools #AI #useful #website #coolwebsites #websitesyouneed .mp4'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "c:\Python\VideoCreationTiktok\3test_naming_and_moving+GPTtoShorten.py", line 59, in shutil.move(original_path, used_path) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\shutil.py", line 837, in move os.unlink(src) PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'E:/SMART AI BOTS/Selected\bjornevag_ - Part 12 Websites that feels ILLEGAL to use #Websites #onlinetools #AI #useful #website #coolwebsites #websitesyouneed .mp4' PS C:\Python\VideoCreationTiktok>
- Assistant