Last active
October 28, 2022 07:59
-
-
Save L0Lock/89a601a867003bdc9300d86faf1972ab to your computer and use it in GitHub Desktop.
Overlays drag-n-dropped files at the center of a given file (line 24) using ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, subprocess, time, os, shutil | |
# FFMPEG_PATH = "./ffmpeg/ffmpeg" | |
# text formatting | |
class cmdUtils: | |
Purple = '\033[95m' | |
Blue = '\033[94m' | |
Cyan = '\033[96m' | |
Green = '\033[92m' | |
Tan = '\033[93m' | |
Red = '\033[91m' | |
Grey = '\033[0m' # Default | |
White = '\033[1m' | |
Sound = '\007' | |
# console clearer | |
def cls(): | |
os.system('cls' if os.name=='nt' else 'clear') | |
def encode_video(inputFile, outputPath): | |
ffmpeg_cmd = FFMPEG_PATH | |
ffmpeg_cmd += f' -y' | |
ffmpeg_cmd += f' -i "BACKGROUND.jpg"' ### PUT BACKGROUND FILE PATH HERE | |
ffmpeg_cmd += f' -i "{inputFile}"' | |
ffmpeg_cmd += f' -filter_complex "overlay=(W-w)/2:(H-h)/2"' | |
ffmpeg_cmd += f' "{outputPath}"' | |
print(ffmpeg_cmd) | |
subprocess.run(ffmpeg_cmd) | |
if __name__ == "__main__": | |
### Checking FFmpeg installation | |
FFMPEG_PATH = shutil.which('ffmpeg') or './ffmpeg/ffmpeg' | |
try: | |
subprocess.run([FFMPEG_PATH, '-version'], check=True) # ensure ffmpeg is available | |
except: | |
print(f'{cmdUtils.Red}Error: Couldn\'t find FFMPEG.{cmdUtils.Grey}') | |
input() | |
sys.exit(1) | |
### Get dragndroped files and add file output suffix | |
droppedFiles = sys.argv[1:] | |
for inputFile in droppedFiles: | |
print(f'{cmdUtils.Green}Detected input files : {inputFile}{cmdUtils.Grey}') | |
outputPath = f'{inputFile.rsplit(".",1)[0]}__overlay.png' | |
print(f'{cmdUtils.Green}Output file will be: {outputPath}{cmdUtils.Grey}') | |
### Run main fun | |
encode_video(inputFile, outputPath) | |
### Success Message | |
cls() | |
print(cmdUtils.Sound) | |
print(f"{cmdUtils.Green}Encoding succesful. This window will close after 10 seconds.{cmdUtils.Grey}") | |
subprocess.call('timeout /t 10') | |
input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment