mirror of
https://github.com/artegoser/image-pluser-webui.git
synced 2024-11-24 04:36:20 +03:00
feat: images to video
This commit is contained in:
parent
ca3d0969bc
commit
7bf970cf1b
5 changed files with 57 additions and 21 deletions
2
app.py
2
app.py
|
@ -23,7 +23,7 @@ for tab_name in tabs:
|
|||
all_tabs.append((tab_name, tab.app))
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error loading tab: {e}")
|
||||
print(f"Error loading tab ({tab_name}): {e}")
|
||||
|
||||
with gr.Blocks() as app:
|
||||
for tab_name, tab in all_tabs:
|
||||
|
|
|
@ -1,11 +1,24 @@
|
|||
from PIL import Image, ImageFilter
|
||||
import ffmpeg
|
||||
import os
|
||||
from processing.utils import generate_name, get_date_text
|
||||
|
||||
|
||||
def images_to_video(directory, fps):
|
||||
glob_path = os.path.join(directory, "*.png")
|
||||
video_path = os.path.join(directory, "video.mp4")
|
||||
def images_to_video(directory, fps, img_ext, img_name_format, video_name, video_ext, video_dir):
|
||||
images_pattern = os.path.join(directory, f"{img_name_format}.{img_ext}")
|
||||
|
||||
ffmpeg.input(glob_path, pattern_type="glob",
|
||||
framerate=fps).output(video_path).run()
|
||||
if video_dir:
|
||||
video_path = os.path.join(video_dir, f"{video_name}.{video_ext}")
|
||||
else:
|
||||
video_path = generate_name(
|
||||
extension=video_ext, name=video_name, subfolder="videos")
|
||||
|
||||
ffmpeg.input(images_pattern,
|
||||
framerate=fps).output(video_path, pix_fmt='yuv420p').global_args("-y").run()
|
||||
|
||||
|
||||
def video_to_images(video_path, img_ext):
|
||||
images_pattern = generate_name(
|
||||
extension=img_ext, name=video_path, subfolder=os.path.join("images", get_date_text()))
|
||||
|
||||
ffmpeg.input(video_path).output(images_pattern).run()
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
from methods.stack_methods import denoise, startracks, noise_extractor, untrack
|
||||
import os
|
||||
import datetime
|
||||
|
||||
|
||||
def generate_name():
|
||||
os.makedirs("./output/stacked", exist_ok=True)
|
||||
|
||||
return f"./output/stacked/{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.png"
|
||||
from processing.utils import generate_name
|
||||
|
||||
|
||||
def stacking(dir, method):
|
||||
|
|
16
processing/utils.py
Normal file
16
processing/utils.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
import os
|
||||
import datetime
|
||||
|
||||
|
||||
def generate_name(name=False, subfolder="stacked", extension="png", format='%Y-%m-%d_%H-%M-%S'):
|
||||
|
||||
os.makedirs(os.path.join("./output", subfolder), exist_ok=True)
|
||||
|
||||
if name is False or name == "":
|
||||
name = get_date_text(format)
|
||||
|
||||
return os.path.join("./output", subfolder, f"{name}.{extension}")
|
||||
|
||||
|
||||
def get_date_text(format='%Y-%m-%d_%H-%M-%S'):
|
||||
return datetime.datetime.now().strftime(format)
|
|
@ -2,16 +2,29 @@ import gradio as gr
|
|||
from processing.bulk import images_to_video
|
||||
|
||||
with gr.Blocks() as app:
|
||||
gr.Markdown("Convert images to video. # **WIP, not working**")
|
||||
with gr.Row():
|
||||
with gr.Column():
|
||||
gr.Markdown("Convert images to video.")
|
||||
directory = gr.Text(
|
||||
placeholder="A directory with many images of the same size", lines=1, label="Directory")
|
||||
placeholder="A directory with many images of the same size", label="Directory")
|
||||
|
||||
fps = gr.Number(label="FPS", value=30, min=0)
|
||||
|
||||
with gr.Accordion("Advanced settings", open=False) as acc:
|
||||
video_name = gr.Text(
|
||||
label="Video name", placeholder="Video name e.g. video. If not specified will be generated by time")
|
||||
video_ext = gr.Dropdown(label="Video extension", choices=[
|
||||
"mp4"], value="mp4")
|
||||
video_dir = gr.Text(
|
||||
label="Video directory", placeholder="The directory where the video will be saved. If not specified `./output/videos`")
|
||||
|
||||
img_ext = gr.Dropdown(label="Image extension", choices=[
|
||||
"png", "jpg"], value="png")
|
||||
img_name_format = gr.Text(
|
||||
label="Image name format", placeholder="ffmpeg pattern e.g. %04d is (0000.png)", value="%d")
|
||||
|
||||
fps = gr.Number(label="FPS")
|
||||
submit = gr.Button("Submit")
|
||||
|
||||
submit.click(
|
||||
fn=images_to_video,
|
||||
inputs=[directory, fps],
|
||||
inputs=[directory, fps, img_ext, img_name_format,
|
||||
video_name, video_ext, video_dir],
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue