prompt user for savefile
This commit is contained in:
parent
e6c21a4bdd
commit
0c867779a1
@ -28,12 +28,13 @@ def extract_frames(input_path, output_dir):
|
||||
os.system(f"ffmpeg -i {input_path} '{output_dir}/%04d.png'")
|
||||
|
||||
|
||||
def add_audio(current_dir, output_dir, target_path, keep_frames):
|
||||
def add_audio(current_dir, output_dir, target_path, keep_frames, output_file):
|
||||
video = target_path.split("/")[-1]
|
||||
video_name = video.split(".")[0]
|
||||
os.system(f"ffmpeg -i {output_dir}/output.mp4 -i {output_dir}/{video} -c:v copy -map 0:v:0 -map 1:a:0 -y {current_dir}/swapped-{video_name}.mp4")
|
||||
save_to = output_file if output_file else current_dir + "/swapped-" + video_name + ".mp4"
|
||||
os.system(f"ffmpeg -i {output_dir}/output.mp4 -i {output_dir}/{video} -c:v copy -map 0:v:0 -map 1:a:0 -y {save_to}")
|
||||
if not os.path.isfile(current_dir + "/swapped-" + video_name + ".mp4"):
|
||||
shutil.move(output_dir + "/output.mp4", current_dir + "/swapped-" + video_name + ".mp4")
|
||||
shutil.move(output_dir + "/output.mp4", save_to)
|
||||
if not keep_frames:
|
||||
shutil.rmtree(output_dir)
|
||||
|
||||
|
9
run.py
9
run.py
@ -5,6 +5,7 @@ import os
|
||||
from pathlib import Path
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
from tkinter.filedialog import asksaveasfilename
|
||||
from core.processor import process_video, process_img
|
||||
from core.utils import is_img, detect_fps, set_fps, create_video, add_audio, extract_frames
|
||||
import webbrowser
|
||||
@ -52,6 +53,10 @@ def toggle_fps_limit():
|
||||
args['keep_fps'] = limit_fps.get() != True
|
||||
|
||||
|
||||
def save_file():
|
||||
args['output_file'] = asksaveasfilename(initialfile='output.mp4', defaultextension=".mp4", filetypes=[("All Files","*.*"),("Videos","*.mp4")])
|
||||
|
||||
|
||||
def start():
|
||||
if not args['source_img'] or not os.path.isfile(args['source_img']):
|
||||
print("\n[WARNING] Please select an image containing a face.")
|
||||
@ -83,7 +88,7 @@ def start():
|
||||
))
|
||||
start_processing()
|
||||
create_video(video_name, fps, output_dir)
|
||||
add_audio(current_dir, output_dir, target_path, args['keep_frames'])
|
||||
add_audio(current_dir, output_dir, target_path, args['keep_frames'], args['output_file'])
|
||||
print("\n\nVideo saved as:", current_dir + "/swapped-" + video_name + ".mp4", "\n\n")
|
||||
|
||||
|
||||
@ -115,6 +120,6 @@ if __name__ == "__main__":
|
||||
fps_checkbox.select()
|
||||
|
||||
# Start button
|
||||
start_button = tk.Button(window, text="Start", bg="green", command=start)
|
||||
start_button = tk.Button(window, text="Start", bg="green", command=lambda: [save_file(), start()])
|
||||
start_button.pack(side=tk.BOTTOM, padx=10, pady=10)
|
||||
window.mainloop()
|
||||
|
Loading…
Reference in New Issue
Block a user