Skip to content

Commit

Permalink
Add video settings component to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
henryruhs committed Aug 15, 2023
1 parent 638d95e commit 9efbc1a
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 22 deletions.
4 changes: 2 additions & 2 deletions roop/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def parse_args() -> None:
program.add_argument('--trim-frame-start', help='start frame use for extraction', dest='trim_frame_start', type=int)
program.add_argument('--trim-frame-end', help='end frame use for extraction', dest='trim_frame_end', type=int)
program.add_argument('--temp-frame-format', help='image format used for frame extraction', dest='temp_frame_format', default='jpg', choices=['jpg', 'png'])
program.add_argument('--temp-frame-quality', help='image quality used for frame extraction', dest='temp_frame_quality', type=int, default=0, choices=range(101), metavar='[0-100]')
program.add_argument('--temp-frame-quality', help='image quality used for frame extraction', dest='temp_frame_quality', type=int, default=100, choices=range(101), metavar='[0-100]')
program.add_argument('--output-video-encoder', help='encoder used for the output video', dest='output_video_encoder', default='libx264', choices=['libx264', 'libx265', 'libvpx-vp9', 'h264_nvenc', 'hevc_nvenc'])
program.add_argument('--output-video-quality', help='quality used for the output video', dest='output_video_quality', type=int, default=35, choices=range(101), metavar='[0-100]')
program.add_argument('--output-video-quality', help='quality used for the output video', dest='output_video_quality', type=int, default=90, choices=range(101), metavar='[0-100]')
program.add_argument('--max-memory', help='maximum amount of RAM in GB', dest='max_memory', type=int)
program.add_argument('--execution-providers', help='list of available execution providers (choices: cpu, ...)', dest='execution_providers', default=['cpu'], choices=suggest_execution_providers(), nargs='+')
program.add_argument('--execution-thread-count', help='number of execution threads', dest='execution_thread_count', type=int, default=suggest_execution_thread_count())
Expand Down
25 changes: 12 additions & 13 deletions roop/uis/__components__/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@ def render() -> None:
global OUTPUT_IMAGE
global OUTPUT_VIDEO

with gradio.Column():
with gradio.Row():
START_BUTTON = gradio.Button('Start')
CLEAR_BUTTON = gradio.Button('Clear')
with gradio.Row():
with gradio.Box():
OUTPUT_IMAGE = gradio.Image(
label='OUTPUT'
)
OUTPUT_VIDEO = gradio.Video(
label='OUTPUT',
visible=False
)
with gradio.Row():
with gradio.Box():
OUTPUT_IMAGE = gradio.Image(
label='OUTPUT',
visible=False
)
OUTPUT_VIDEO = gradio.Video(
label='OUTPUT'
)
with gradio.Row():
START_BUTTON = gradio.Button('Start')
CLEAR_BUTTON = gradio.Button('Clear')


def listen() -> None:
Expand Down
42 changes: 42 additions & 0 deletions roop/uis/__components__/output_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from typing import Optional
import gradio

import roop.globals
from roop.typing import OutputVideoEncoder

from roop.uis.typing import Update

OUTPUT_VIDEO_ENCODER_DROPDOWN: Optional[gradio.Dropdown] = None
OUTPUT_VIDEO_QUALITY_SLIDER: Optional[gradio.Slider] = None


def render() -> None:
global OUTPUT_VIDEO_ENCODER_DROPDOWN
global OUTPUT_VIDEO_QUALITY_SLIDER

with gradio.Box():
OUTPUT_VIDEO_ENCODER_DROPDOWN = gradio.Dropdown(
label='OUTPUT VIDEO ENCODER',
choices=['libx264', 'libx265', 'libvpx-vp9', 'h264_nvenc', 'hevc_nvenc'],
value=roop.globals.output_video_encoder
)
OUTPUT_VIDEO_QUALITY_SLIDER = gradio.Slider(
label='OUTPUT VIDEO QUALITY',
value=roop.globals.output_video_quality,
step=1
)


def listen() -> None:
OUTPUT_VIDEO_ENCODER_DROPDOWN.select(update_output_video_encoder, inputs=OUTPUT_VIDEO_ENCODER_DROPDOWN, outputs=OUTPUT_VIDEO_ENCODER_DROPDOWN)
OUTPUT_VIDEO_QUALITY_SLIDER.change(update_output_video_quality, inputs=OUTPUT_VIDEO_QUALITY_SLIDER, outputs=OUTPUT_VIDEO_QUALITY_SLIDER)


def update_output_video_encoder(output_video_encoder: OutputVideoEncoder) -> Update:
roop.globals.output_video_encoder = output_video_encoder
return gradio.update(value=output_video_encoder)


def update_output_video_quality(output_video_quality: int) -> Update:
roop.globals.output_video_quality = output_video_quality
return gradio.update(value=output_video_quality)
5 changes: 2 additions & 3 deletions roop/uis/__components__/temp_frame.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from typing import List, Optional
from typing import Optional
import gradio

import roop.globals
from roop.processors.frame.core import list_frame_processors_names, load_frame_processor_module, clear_frame_processors_modules
from roop.typing import TempFrameFormat
from roop.uis import core as ui

from roop.uis.typing import Update

TEMP_FRAME_FORMAT_DROPDOWN: Optional[gradio.Dropdown] = None
Expand Down
6 changes: 4 additions & 2 deletions roop/uis/__layouts__/default.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gradio

from roop.uis.__components__ import processor, execution, temp_frame, settings, source, target, preview, trim_frame, face_analyser, face_selector, output
from roop.uis.__components__ import processor, execution, temp_frame, settings, source, target, preview, trim_frame, face_analyser, face_selector, output_settings, output


def render() -> gradio.Blocks:
Expand All @@ -11,9 +11,10 @@ def render() -> gradio.Blocks:
execution.render()
temp_frame.render()
settings.render()
with gradio.Column(scale=1):
with gradio.Column(scale=2):
source.render()
target.render()
output_settings.render()
output.render()
with gradio.Column(scale=3):
preview.render()
Expand All @@ -34,4 +35,5 @@ def listen() -> None:
trim_frame.listen()
face_selector.listen()
face_analyser.listen()
output_settings.listen()
output.listen()
4 changes: 2 additions & 2 deletions roop/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def detect_fps(target_path: str) -> float:

def extract_frames(target_path: str, fps: float = 30) -> bool:
temp_directory_path = get_temp_directory_path(target_path)
temp_frame_quality = roop.globals.temp_frame_quality * 31 // 100
temp_frame_quality = round(31 - (roop.globals.temp_frame_quality * 0.31))
trim_frame_start = roop.globals.trim_frame_start
trim_frame_end = roop.globals.trim_frame_end
commands = ['-hwaccel', 'auto', '-i', target_path, '-q:v', str(temp_frame_quality), '-pix_fmt', 'rgb24']
Expand All @@ -61,7 +61,7 @@ def extract_frames(target_path: str, fps: float = 30) -> bool:
def create_video(target_path: str, fps: float = 30) -> bool:
temp_output_path = get_temp_output_path(target_path)
temp_directory_path = get_temp_directory_path(target_path)
output_video_quality = (roop.globals.output_video_quality + 1) * 51 // 100
output_video_quality = round(51 - (roop.globals.output_video_quality * 0.5))
commands = ['-hwaccel', 'auto', '-r', str(fps), '-i', os.path.join(temp_directory_path, '%04d.' + roop.globals.temp_frame_format), '-c:v', roop.globals.output_video_encoder]
if roop.globals.output_video_encoder in ['libx264', 'libx265', 'libvpx']:
commands.extend(['-crf', str(output_video_quality)])
Expand Down

0 comments on commit 9efbc1a

Please sign in to comment.