You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import os
import subprocess
from queue import Queue
from threading import Thread
from gooey import Gooey, GooeyParser
# Define the function to process a video
def process_video(input_path, output_path, watermark_image):
# Construct the FFmpeg command for adding the watermark
ffmpeg_command = [
'ffmpeg',
'-y', # Overwrite output files without asking
'-i', input_path, # Input video file
'-i', watermark_image, # Watermark image
'-filter_complex', '[1:v][0:v]scale2ref=w=iw/4:h=ow/mdar[watermark][video];[video][watermark]overlay=W-w-10:10', # Resize watermark and place it in the top right corner
'-codec:v', 'libx264', # Use H.264 video codec
'-movflags', 'faststart', # Move the moov atom to the start of the file
'-codec:a', 'aac', # Use AAC audio codec
output_path # Output video file
]
subprocess.run(ffmpeg_command)
# Define the function to iterate through a directory
def iterate_directory(directory, output_directory, watermark_image):
tasks = Queue()
# Loop through all files in the video directory
for video_file in os.listdir(directory):
# Check if the file is a video (you can add more extensions if needed)
if video_file.lower().endswith(('.mp4', '.mkv', '.avi','.mov')):
input_path = os.path.join(directory, video_file)
output_file_name = os.path.splitext(video_file)[0] + '.mp4' # Change the output file extension to .mp4
output_path = os.path.join(output_directory, output_file_name)
tasks.put((input_path, output_path))
total_tasks = tasks.qsize()
# Process the tasks
for i in range(total_tasks):
input_path, output_path = tasks.get()
print(f'Progress: {i+1}/{total_tasks}')
print("Processing:", input_path)
process_video(input_path, output_path, watermark_image)
tasks.task_done()
@Gooey(progress_regex=r"^Progress: (?P<current>\d+)/(?P<total>\d+)$",
progress_expr="current / total * 100",show_restart_button=False, richtext_controls=True)
def main():
parser = GooeyParser(description="This program adds a watermark to all videos in a directory")
parser.add_argument('input_directory', type=str, help='Source directory', widget='DirChooser')
parser.add_argument('output_directory', type=str, help='Output directory', widget='DirChooser', default=os.getcwd()+os.sep+'output')
parser.add_argument('watermark_image', type=str, help='Watermark image', widget='FileChooser', default=os.getcwd()+os.sep+'logo.png')
args = parser.parse_args()
# Ensure the output directory exists
if not os.path.exists(args.output_directory):
os.makedirs(args.output_directory)
iterate_directory(args.input_directory, args.output_directory, args.watermark_image)
if __name__ == '__main__':
main()
Found a bug? Just a friendly heads up, debugging it requires information from you! Make sure the template below is filled out in its entirety.
MacOS Ventura 13.3.1 (22E261)
Python Version : Python 3.12.2
Gooey Version: gooey==1.0.8.1, colored==1.4.4 (to prevent another bug)
Thorough description of problem
Expected, no crash , exits successfully
Actual Behavior, crashes
The text was updated successfully, but these errors were encountered:
When I exit the program it crashes.
command line prints:
Code for
batchwatermark.py
is thisFound a bug? Just a friendly heads up, debugging it requires information from you! Make sure the template below is filled out in its entirety.
The text was updated successfully, but these errors were encountered: