Skip to content

Instantly share code, notes, and snippets.

@JupyterJones
Created June 21, 2023 20:56
Show Gist options
  • Save JupyterJones/741f48b4c88b3b24fc33d7316f0812ae to your computer and use it in GitHub Desktop.
Save JupyterJones/741f48b4c88b3b24fc33d7316f0812ae to your computer and use it in GitHub Desktop.
Run ffmpeg with Python
import subprocess
import os
from datetime import datetime
from random import randint
#DIR = "/home/jack/Desktop/HDD500/0WORKSHOP-with-NOTEBOOKS/shaman/"
DIR = "/home/jack/Desktop/HDD500/FLASK/static/milestones_resources/Lexica-anime/"
VIDEOS = "EXPERIMENT/XXXX1.mp4"
BORDER ="/home/jack/Desktop/HDD500/FLASK/static/assets/512x666Border.png"
current_datetime = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
filename = f"EXPERIMENT/_file_{current_datetime}.mp4"
silentFINAL = "silentTEMP.mp4"
ffmpeg_jpg_command = f"ffmpeg -hide_banner -i {DIR}%*.jpg -vf 'scale=512:666,setsar=1:1' -c:v libx264 -r 30 -pix_fmt yuv420p -y {VIDEOS}"
subprocess.run(ffmpeg_jpg_command, shell=True)
ffmpeg_mp4_command = f"ffmpeg -hide_banner -i {VIDEOS} -filter:v 'setpts=20*PTS,minterpolate=fps=25:scd=none:me_mode=bidir:vsbmc=1:search_param=200' -t 58 -y {filename}"
subprocess.run(ffmpeg_mp4_command, shell=True)
#Overlay filename with BORDER
ffmpeg_overlay_command = f"ffmpeg -i {filename} -i {BORDER} -filter_complex overlay=0:0 -c:a copy -y {silentFINAL}"
subprocess.run(ffmpeg_overlay_command, shell=True)
MUSIC = "/mnt/HDD500/collections/Music/Music-Copyright_Free_Music.mp3"
FINAL = f"/mnt/HDD500/MyTube_AI_Flask_App/static/current_project/{current_datetime}setpoint20minterpolate.mp4"
random_number = randint(0,200)
ffmpeg_final_command = f"ffmpeg -ss 0 -i {silentFINAL} -ss {random_number} -i {MUSIC} -map 0:v -map 1:a -c:v copy -c:a aac -shortest -y {FINAL}"
subprocess.run(ffmpeg_final_command, shell=True)
!vlc {FINAL}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment