fix: fast check for ffmpeg (#101)

* add ffmpeg to readme

* check if it installed

* formating
This commit is contained in:
Tom Nijhof 2024-07-12 08:25:16 +02:00 committed by GitHub
parent fe43a21d81
commit 89676189b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 5 deletions

View File

@ -6,12 +6,21 @@ from src.config.argument_config import ArgumentConfig
from src.config.inference_config import InferenceConfig
from src.config.crop_config import CropConfig
from src.live_portrait_pipeline import LivePortraitPipeline
import subprocess
def partial_fields(target_class, kwargs):
return target_class(**{k: v for k, v in kwargs.items() if hasattr(target_class, k)})
def fast_check_ffmpeg():
try:
subprocess.run(["ffmpeg", "-version"], capture_output=True, check=True)
return True
except:
return False
def fast_check_args(args: ArgumentConfig):
if not osp.exists(args.source_image):
raise FileNotFoundError(f"source image not found: {args.source_image}")
@ -24,21 +33,28 @@ def main():
tyro.extras.set_accent_color("bright_cyan")
args = tyro.cli(ArgumentConfig)
if not fast_check_ffmpeg():
raise ImportError(
"FFmpeg is not installed. Please install FFmpeg before running this script. https://ffmpeg.org/download.html"
)
# fast check the args
fast_check_args(args)
# specify configs for inference
inference_cfg = partial_fields(InferenceConfig, args.__dict__) # use attribute of args to initial InferenceConfig
crop_cfg = partial_fields(CropConfig, args.__dict__) # use attribute of args to initial CropConfig
inference_cfg = partial_fields(
InferenceConfig, args.__dict__
) # use attribute of args to initial InferenceConfig
crop_cfg = partial_fields(
CropConfig, args.__dict__
) # use attribute of args to initial CropConfig
live_portrait_pipeline = LivePortraitPipeline(
inference_cfg=inference_cfg,
crop_cfg=crop_cfg
inference_cfg=inference_cfg, crop_cfg=crop_cfg
)
# run
live_portrait_pipeline.execute(args)
if __name__ == '__main__':
if __name__ == "__main__":
main()

View File

@ -59,6 +59,8 @@ conda activate LivePortrait
pip install -r requirements.txt
```
Make sure your system has [FFmpeg](https://ffmpeg.org/)
### 2. Download pretrained weights
Download the pretrained weights from HuggingFace: