mirror of
https://github.com/KwaiVGI/LivePortrait.git
synced 2024-12-22 20:42:38 +00:00
fix: fast check for ffmpeg (#101)
* add ffmpeg to readme * check if it installed * formating
This commit is contained in:
parent
fe43a21d81
commit
89676189b9
26
inference.py
26
inference.py
@ -6,12 +6,21 @@ from src.config.argument_config import ArgumentConfig
|
|||||||
from src.config.inference_config import InferenceConfig
|
from src.config.inference_config import InferenceConfig
|
||||||
from src.config.crop_config import CropConfig
|
from src.config.crop_config import CropConfig
|
||||||
from src.live_portrait_pipeline import LivePortraitPipeline
|
from src.live_portrait_pipeline import LivePortraitPipeline
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
def partial_fields(target_class, kwargs):
|
def partial_fields(target_class, kwargs):
|
||||||
return target_class(**{k: v for k, v in kwargs.items() if hasattr(target_class, k)})
|
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):
|
def fast_check_args(args: ArgumentConfig):
|
||||||
if not osp.exists(args.source_image):
|
if not osp.exists(args.source_image):
|
||||||
raise FileNotFoundError(f"source image not found: {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")
|
tyro.extras.set_accent_color("bright_cyan")
|
||||||
args = tyro.cli(ArgumentConfig)
|
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 the args
|
||||||
fast_check_args(args)
|
fast_check_args(args)
|
||||||
|
|
||||||
# specify configs for inference
|
# specify configs for inference
|
||||||
inference_cfg = partial_fields(InferenceConfig, args.__dict__) # use attribute of args to initial InferenceConfig
|
inference_cfg = partial_fields(
|
||||||
crop_cfg = partial_fields(CropConfig, args.__dict__) # use attribute of args to initial CropConfig
|
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(
|
live_portrait_pipeline = LivePortraitPipeline(
|
||||||
inference_cfg=inference_cfg,
|
inference_cfg=inference_cfg, crop_cfg=crop_cfg
|
||||||
crop_cfg=crop_cfg
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# run
|
# run
|
||||||
live_portrait_pipeline.execute(args)
|
live_portrait_pipeline.execute(args)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
@ -59,6 +59,8 @@ conda activate LivePortrait
|
|||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Make sure your system has [FFmpeg](https://ffmpeg.org/)
|
||||||
|
|
||||||
### 2. Download pretrained weights
|
### 2. Download pretrained weights
|
||||||
|
|
||||||
Download the pretrained weights from HuggingFace:
|
Download the pretrained weights from HuggingFace:
|
||||||
|
Loading…
Reference in New Issue
Block a user