Created
September 20, 2024 22:37
-
-
Save AdelMmdi/f2597466d121722f2bb6da10c39f09ef to your computer and use it in GitHub Desktop.
text on video ffmpeg clip auto manual font first rotate movie for instagram show: movie-0xFFFFFF-0x000000-300.mp4
This file contains hidden or 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 subprocess | |
| import os | |
| #you feel: | |
| ffmpegPath = '.\ffmpeg.exe'#your ffmpeg | |
| ff = "far.ttf"#your font | |
| path="."#directory movies | |
| #movie-0xFFFFFF-0x000000-300.mp4 | |
| for filename in os.listdir(path): | |
| if (filename.endswith(".mkv")): #or .avi, .mpeg, whatever. | |
| print(filename) | |
| clip = filename | |
| form = clip[-4:] | |
| clip = clip[:-4] | |
| c = clip.split('-')#name analys for options | |
| print(c) | |
| name = c[0]#title | |
| fc = c[1]#font color | |
| bc = c[2]#background font color | |
| fs=c[3]#font size | |
| #s = clip.j | |
| #print(name) | |
| #extractPNG = subprocess.Popen(r'''.\ffmpeg -i .\{0}{1} -vframes 1 -f image2 {0}.jpg'''.format(clip, form)) | |
| #fontcolor, boxcolor:color_extraction.get_counts(img) | |
| #https://stackoverflow.com/questions/89228/how-do-i-execute-a-program-or-call-a-system-command | |
| rotate = subprocess.Popen(r'''{3} -i "{0}{1}" -vf "transpose=1" "{2}x{1}"'''.format(clip, form, name, ffmpegPath)) | |
| #https://stackoverflow.com/questions/17623676/text-on-video-ffmpeg | |
| rotate.wait() | |
| textOnVideo = subprocess.Popen(r'''{6} -i "{0}x{1}" -vf "drawtext=fontfile={2}:text="{0}":fontcolor={3}:fontsize={4}:box=1:boxcolor={5}@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2:enable='between(t,0,1)" -codec:a copy "{0}insta{1}"'''.format(name, form, ff, fc, fs, bc, ffmpegPath), | |
| shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
| for line in textOnVideo.stdout.readlines(): | |
| print(line) | |
| retval = textOnVideo.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment