Override for Gradio's nasty convert_video_to_playable_mp4()
This commit is contained in:
@@ -7,6 +7,7 @@ from typing import Any, Dict, List, Optional
|
|||||||
import gradio
|
import gradio
|
||||||
from gradio.themes import Size
|
from gradio.themes import Size
|
||||||
|
|
||||||
|
import facefusion.uis.overrides as uis_overrides
|
||||||
from facefusion import logger, metadata, state_manager, wording
|
from facefusion import logger, metadata, state_manager, wording
|
||||||
from facefusion.exit_helper import hard_exit
|
from facefusion.exit_helper import hard_exit
|
||||||
from facefusion.filesystem import resolve_relative_path
|
from facefusion.filesystem import resolve_relative_path
|
||||||
@@ -74,7 +75,8 @@ def init() -> None:
|
|||||||
os.environ['GRADIO_TEMP_DIR'] = os.path.join(state_manager.get_item('temp_path'), 'gradio')
|
os.environ['GRADIO_TEMP_DIR'] = os.path.join(state_manager.get_item('temp_path'), 'gradio')
|
||||||
|
|
||||||
warnings.filterwarnings('ignore', category = UserWarning, module = 'gradio')
|
warnings.filterwarnings('ignore', category = UserWarning, module = 'gradio')
|
||||||
gradio.processing_utils._check_allowed = lambda path, check_in_upload_folder: None
|
gradio.processing_utils._check_allowed = uis_overrides.check_allowed #type:ignore
|
||||||
|
gradio.processing_utils.convert_video_to_playable_mp4 = uis_overrides.convert_video_to_playable_mp4
|
||||||
|
|
||||||
|
|
||||||
def launch() -> None:
|
def launch() -> None:
|
||||||
|
|||||||
29
facefusion/uis/overrides.py
Normal file
29
facefusion/uis/overrides.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
from facefusion import ffmpeg_builder
|
||||||
|
from facefusion.ffmpeg import run_ffmpeg
|
||||||
|
from facefusion.filesystem import get_file_size
|
||||||
|
from facefusion.temp_helper import create_temp_directory, get_temp_file_path
|
||||||
|
|
||||||
|
|
||||||
|
def convert_video_to_playable_mp4(video_path : str) -> str:
|
||||||
|
video_file_size = get_file_size(video_path)
|
||||||
|
max_file_size = 512 * 1024 * 1024
|
||||||
|
|
||||||
|
if video_file_size > max_file_size:
|
||||||
|
create_temp_directory(video_path)
|
||||||
|
temp_video_path = get_temp_file_path(video_path)
|
||||||
|
commands = ffmpeg_builder.chain(
|
||||||
|
ffmpeg_builder.set_input(video_path),
|
||||||
|
ffmpeg_builder.set_video_duration(10),
|
||||||
|
ffmpeg_builder.force_output(temp_video_path)
|
||||||
|
)
|
||||||
|
|
||||||
|
process = run_ffmpeg(commands)
|
||||||
|
process.communicate()
|
||||||
|
|
||||||
|
if process.returncode == 0:
|
||||||
|
return temp_video_path
|
||||||
|
return video_path
|
||||||
|
|
||||||
|
|
||||||
|
def check_allowed(path : str, check_in_upload_folder : bool) -> None:
|
||||||
|
return None
|
||||||
Reference in New Issue
Block a user