added FFMPEG Expert options (for colors, compression, lossless etc)

overmask_scale_mainframes
Georg Legato 2023-05-14 21:37:30 +02:00
parent 8c857ff234
commit 637eb1e537
5 changed files with 36 additions and 6 deletions

View File

@ -15,6 +15,7 @@ class InfZoomConfig():
video_zoom_mode:int #0: ZoomOut, 1: ZoomIn
video_start_frame_dupe_amount:int
video_last_frame_dupe_amount:int
video_ffmpeg_opts: str
inpainting_mask_blur:int
inpainting_fill_mode:int
zoom_speed:float

View File

@ -94,7 +94,13 @@ class InfZoomer:
self.main_frames = self.main_frames[::-1]
if not self.outerZoom:
self.contVW = ContinuousVideoWriter(self.out_config["video_filename"], self.main_frames[0],self.C.video_frame_rate,int(self.C.video_start_frame_dupe_amount))
self.contVW = ContinuousVideoWriter(
self.out_config["video_filename"],
self.main_frames[0],
self.C.video_frame_rate,
int(self.C.video_start_frame_dupe_amount),
self.C.video_ffmpeg_opts
)
self.fnInterpolateFrames() # changes main_frame and writes to video
@ -129,7 +135,7 @@ class InfZoomer:
)
self.save2Collect(current_image, f"init_custom.png")
else:
load_model_from_setting("infzoom_txt2img_model", self.C.progress, "Loading Model for txt2img: ")
load_model_from_setting("infzoom_inpainting_model", self.C.progress, "Loading Model for txt2img: ")
processed, newseed = self.renderFirstFrame()
@ -451,7 +457,8 @@ class InfZoomer:
self.contVW = ContinuousVideoWriter(self.out_config["video_filename"],
self.cropCenterTo(current_image,(self.width,self.height)),
self.C.video_frame_rate,int(self.C.video_start_frame_dupe_amount))
self.C.video_frame_rate,int(self.C.video_start_frame_dupe_amount),
self.C.video_ffmpeg_opts)
outzoomSize = (self.width+self.mask_width*2, self.height+self.mask_height*2)
target_size = (self.width, self.height)
@ -491,7 +498,8 @@ class InfZoomer:
self.contVW = ContinuousVideoWriter(self.out_config["video_filename"],
(firstImage,(self.width,self.height)),
self.C.video_frame_rate,int(self.C.video_start_frame_dupe_amount))
self.C.video_frame_rate,int(self.C.video_start_frame_dupe_amount),
self.C.video_ffmpeg_opts)
for i in range(len(self.main_frames) - 1):
# interpolation steps between 2 inpainted images (=sequential zoom and crop)

View File

@ -17,6 +17,7 @@ def createZoom(
video_zoom_mode:int,
video_start_frame_dupe_amount:int,
video_last_frame_dupe_amount:int,
video_ffmpeg_opts:str,
inpainting_mask_blur:int,
inpainting_fill_mode:int,
zoom_speed:float,
@ -50,6 +51,7 @@ def createZoom(
video_zoom_mode,
video_start_frame_dupe_amount,
video_last_frame_dupe_amount,
video_ffmpeg_opts,
inpainting_mask_blur,
inpainting_fill_mode,
zoom_speed,

View File

@ -215,6 +215,20 @@ def on_ui_tabs():
step=0.1,
info="Zoom speed in seconds (higher values create slower zoom)",
)
with gr.Accordion("FFMPEG Expert", open=False):
gr.Markdown(
"""# I need FFMPEG control
You can put CLI options here as documented https://ffmpeg.org/ffmpeg.html#Options
## Examples:
* ```-vf scale=320:240 ``` scales your video to 320x240
* ```-c:v libx264 -preset veryslow -qp 0``` uses lossless compression
"""
)
video_ffmpeg_opts=gr.Textbox(
value="", label="FFMPEG Opts"
)
with gr.Tab("Outpaint"):
outpaint_amount_px = gr.Slider(
@ -303,6 +317,7 @@ Our best experience and trade-off is the R-ERSGAn4x upscaler.
video_zoom_mode,
video_start_frame_dupe_amount,
video_last_frame_dupe_amount,
video_ffmpeg_opts,
inpainting_mask_blur,
inpainting_fill_mode,
video_zoom_speed,

View File

@ -47,7 +47,7 @@ class ContinuousVideoWriter:
_writer = None
def __init__(self, file_path, initframe, fps, start_frame_dupe_amount=15):
def __init__(self, file_path, initframe, fps, start_frame_dupe_amount=15, video_ffmpeg_opts=""):
"""
Writes initial frame to a new mp4 video file
:param file_path: Path to output video, must end with .mp4
@ -56,7 +56,11 @@ class ContinuousVideoWriter:
:param reversed: if order of images to be reversed (default = True)
"""
writer = imageio.get_writer(file_path, fps=fps, macro_block_size=None)
ffopts = []
if video_ffmpeg_opts is not "":
ffopts= video_ffmpeg_opts.split(" ")
writer = imageio.get_writer(file_path, fps=fps, macro_block_size=None, ffmpeg_params=ffopts)
start_frames = [initframe] * start_frame_dupe_amount
for f in start_frames:
writer.append_data(np.array(f))