From 249e6b3923995dcfd57a0130e4c896e088a10286 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Mon, 5 Jun 2023 15:01:26 +0200 Subject: [PATCH 01/10] Remove path normalization --- roop/utils.py | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/roop/utils.py b/roop/utils.py index 450a7ed..eba456b 100644 --- a/roop/utils.py +++ b/roop/utils.py @@ -2,16 +2,6 @@ import os import shutil import roop.globals -sep = "/" -if os.name == "nt": - sep = "\\" - - -def path(string): - if sep == "\\": - return string.replace("/", "\\") - return string - def run_command(command, mode="silent"): if mode == "debug": @@ -20,7 +10,6 @@ def run_command(command, mode="silent"): def detect_fps(input_path): - input_path = path(input_path) output = os.popen(f'ffprobe -v error -select_streams v -of default=noprint_wrappers=1:nokey=1 -show_entries stream=r_frame_rate "{input_path}"').read() if "/" in output: try: @@ -35,25 +24,21 @@ def run_ffmpeg(args): def set_fps(input_path, output_path, fps): - input_path, output_path = path(input_path), path(output_path) run_ffmpeg(f'-i "{input_path}" -filter:v fps=fps={fps} "{output_path}"') def create_video(video_name, fps, output_dir): - output_dir = path(output_dir) - run_ffmpeg(f'-framerate "{fps}" -i "{output_dir}{sep}%04d.png" -c:v libx264 -crf 7 -pix_fmt yuv420p -y "{output_dir}{sep}output.mp4"') + run_ffmpeg(f'-framerate "{fps}" -i "{output_dir}{os.sep}%04d.png" -c:v libx264 -crf 7 -pix_fmt yuv420p -y "{output_dir}{os.sep}output.mp4"') def extract_frames(input_path, output_dir): - input_path, output_dir = path(input_path), path(output_dir) - run_ffmpeg(f'-i "{input_path}" "{output_dir}{sep}%04d.png"') + run_ffmpeg(f'-i "{input_path}" "{output_dir}{os.sep}%04d.png"') def add_audio(output_dir, target_path, video, keep_frames, output_file): video_name = os.path.splitext(video)[0] save_to = output_file if output_file else output_dir + "/swapped-" + video_name + ".mp4" - save_to_ff, output_dir_ff = path(save_to), path(output_dir) - run_ffmpeg(f'-i "{output_dir_ff}{sep}output.mp4" -i "{output_dir_ff}{sep}{video}" -c:v copy -map 0:v:0 -map 1:a:0 -y "{save_to_ff}"') + run_ffmpeg(f'-i "{output_dir}{os.sep}output.mp4" -i "{output_dir}{os.sep}{video}" -c:v copy -map 0:v:0 -map 1:a:0 -y "{save_to}"') if not os.path.isfile(save_to): shutil.move(output_dir + "/output.mp4", save_to) if not keep_frames: From d8c6581900c3b7f7f69e5ca7fbb9ebe69f224a65 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Mon, 5 Jun 2023 15:12:22 +0200 Subject: [PATCH 02/10] Remove args overrides --- roop/core.py | 13 +++++-------- roop/utils.py | 5 ----- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/roop/core.py b/roop/core.py index e548452..f93785b 100755 --- a/roop/core.py +++ b/roop/core.py @@ -20,7 +20,7 @@ import cv2 import roop.globals from roop.swapper import process_video, process_img, process_faces, process_frames -from roop.utils import is_img, detect_fps, set_fps, create_video, add_audio, extract_frames, rreplace +from roop.utils import is_img, detect_fps, set_fps, create_video, add_audio, extract_frames from roop.analyser import get_face_single import roop.ui as ui @@ -166,9 +166,6 @@ def start(preview_callback = None): elif not args.target_path or not os.path.isfile(args.target_path): print("\n[WARNING] Please select a video/image to swap face in.") return - if not args.output_path: - target_path = args.target_path - args.output_path = rreplace(target_path, "/", "/swapped-", 1) if "/" in target_path else "swapped-" + target_path target_path = args.target_path test_face = get_face_single(cv2.imread(args.source_target)) if not test_face: @@ -183,14 +180,14 @@ def start(preview_callback = None): seconds, probabilities = predict_video_frames(video_path=args.target_path, frame_interval=100) if any(probability > 0.85 for probability in probabilities): quit() - video_name_full = target_path.split("/")[-1] + video_name_full = target_path.split(os.sep)[-1] video_name = os.path.splitext(video_name_full)[0] - output_dir = os.path.dirname(target_path) + "/" + video_name if os.path.dirname(target_path) else video_name + output_dir = os.path.dirname(target_path) + os.sep + video_name if os.path.dirname(target_path) else video_name Path(output_dir).mkdir(exist_ok=True) status("detecting video's FPS...") fps, exact_fps = detect_fps(target_path) if not args.keep_fps and fps > 30: - this_path = output_dir + "/" + video_name + ".mp4" + this_path = output_dir + os.sep + video_name + ".mp4" set_fps(target_path, this_path, 30) target_path, exact_fps = this_path, 30 else: @@ -215,7 +212,7 @@ def start(preview_callback = None): create_video(video_name, exact_fps, output_dir) status("adding audio...") add_audio(output_dir, target_path, video_name_full, args.keep_frames, args.output_path) - save_path = args.output_path if args.output_path else output_dir + "/" + video_name + ".mp4" + save_path = args.output_path if args.output_path else output_dir + os.sep + video_name + ".mp4" print("\n\nVideo saved as:", save_path, "\n\n") status("swap successful!") diff --git a/roop/utils.py b/roop/utils.py index eba456b..d4b8645 100644 --- a/roop/utils.py +++ b/roop/utils.py @@ -47,8 +47,3 @@ def add_audio(output_dir, target_path, video, keep_frames, output_file): def is_img(path): return path.lower().endswith(("png", "jpg", "jpeg", "bmp")) - - -def rreplace(s, old, new, occurrence): - li = s.rsplit(old, occurrence) - return new.join(li) From 49d8103a5339aad51e77b69a428b65ccfdb67116 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Mon, 5 Jun 2023 15:22:22 +0200 Subject: [PATCH 03/10] Run test on Linux and Windows --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef5fa6c..1ea68c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,10 @@ jobs: - run: pip install flake8 - run: flake8 run.py core test: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, windows-latest ] steps: - name: Checkout uses: actions/checkout@v2 From 95096442e21ea2dca99246cc2ec0fba084903d90 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Mon, 5 Jun 2023 15:43:49 +0200 Subject: [PATCH 04/10] Run test on Linux and Windows --- .github/workflows/ci.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1ea68c5..edb6c44 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,14 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ ubuntu-latest, windows-latest ] + ubuntu: + os: ubuntu-latest + run-headless: python run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 + run-validate: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex psnr -f null - + windows: + os: windows-latest + run-headless: python run.py -f .github\examples\face.jpg -t .github\examples\target.mp4 -o .github\examples\output.mp4 + run-validate: ffmpeg -i .github\examples\snapshot.mp4 -i .github/examples\output.mp4 -filter_complex psnr -f null - steps: - name: Checkout uses: actions/checkout@v2 @@ -30,6 +37,6 @@ jobs: python-version: 3.9 - run: pip install -r requirements.txt gdown - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ - - run: ./run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 - - run: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex "psnr" -f null - + - run: ${{ matrix.run-headless }} + - run: ${{ matrix.run-validate }} From 7426295471ffc03a030255512b6d84939ee61b8a Mon Sep 17 00:00:00 2001 From: henryruhs Date: Mon, 5 Jun 2023 15:47:02 +0200 Subject: [PATCH 05/10] Run test on Linux and Windows --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index edb6c44..cf62d5f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,13 +19,13 @@ jobs: strategy: matrix: ubuntu: - os: ubuntu-latest - run-headless: python run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 - run-validate: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex psnr -f null - + os: ubuntu-latest + run-headless: python run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 + run-validate: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex psnr -f null - windows: - os: windows-latest - run-headless: python run.py -f .github\examples\face.jpg -t .github\examples\target.mp4 -o .github\examples\output.mp4 - run-validate: ffmpeg -i .github\examples\snapshot.mp4 -i .github/examples\output.mp4 -filter_complex psnr -f null - + os: windows-latest + run-headless: python run.py -f .github\examples\face.jpg -t .github\examples\target.mp4 -o .github\examples\output.mp4 + run-validate: ffmpeg -i .github\examples\snapshot.mp4 -i .github/examples\output.mp4 -filter_complex psnr -f null - steps: - name: Checkout uses: actions/checkout@v2 From 7f8406588ebfad5eb156af53be3fba113b375eac Mon Sep 17 00:00:00 2001 From: henryruhs Date: Mon, 5 Jun 2023 15:49:32 +0200 Subject: [PATCH 06/10] Run test on Linux and Windows --- .github/workflows/ci.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf62d5f..c39b294 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,15 +17,15 @@ jobs: test: runs-on: ${{ matrix.os }} strategy: - matrix: - ubuntu: - os: ubuntu-latest - run-headless: python run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 - run-validate: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex psnr -f null - - windows: - os: windows-latest - run-headless: python run.py -f .github\examples\face.jpg -t .github\examples\target.mp4 -o .github\examples\output.mp4 - run-validate: ffmpeg -i .github\examples\snapshot.mp4 -i .github/examples\output.mp4 -filter_complex psnr -f null - + matrix: + ubuntu: + os: ubuntu-latest + run-headless: python run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 + run-validate: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex psnr -f null - + windows: + os: windows-latest + run-headless: python run.py -f .github\examples\face.jpg -t .github\examples\target.mp4 -o .github\examples\output.mp4 + run-validate: ffmpeg -i .github\examples\snapshot.mp4 -i .github/examples\output.mp4 -filter_complex psnr -f null - steps: - name: Checkout uses: actions/checkout@v2 From a58a376b8747dabf23cbe8fddeda3ece37c48abc Mon Sep 17 00:00:00 2001 From: henryruhs Date: Mon, 5 Jun 2023 15:52:33 +0200 Subject: [PATCH 07/10] Run test on Linux and Windows --- .github/workflows/ci.yml | 73 ++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c39b294..3576773 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,40 +3,39 @@ name: ci on: [ push, pull_request ] jobs: - lint: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up Python 3.9 - uses: actions/setup-python@v2 - with: - python-version: 3.9 - - run: pip install flake8 - - run: flake8 run.py core - test: - runs-on: ${{ matrix.os }} - strategy: - matrix: - ubuntu: - os: ubuntu-latest - run-headless: python run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 - run-validate: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex psnr -f null - - windows: - os: windows-latest - run-headless: python run.py -f .github\examples\face.jpg -t .github\examples\target.mp4 -o .github\examples\output.mp4 - run-validate: ffmpeg -i .github\examples\snapshot.mp4 -i .github/examples\output.mp4 -filter_complex psnr -f null - - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up ffmpeg - uses: FedericoCarboni/setup-ffmpeg@v2 - - name: Set up Python 3.9 - uses: actions/setup-python@v2 - with: - python-version: 3.9 - - run: pip install -r requirements.txt gdown - - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ - - run: ${{ matrix.run-headless }} - - run: ${{ matrix.run-validate }} - + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 + - run: pip install flake8 + - run: flake8 run.py core + test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + ubuntu: + os: ubuntu-latest + run-headless: python run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 + run-validate: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex psnr -f null - + windows: + os: windows-latest + run-headless: python run.py -f .github\examples\face.jpg -t .github\examples\target.mp4 -o .github\examples\output.mp4 + run-validate: ffmpeg -i .github\examples\snapshot.mp4 -i .github/examples\output.mp4 -filter_complex psnr -f null - + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up ffmpeg + uses: FedericoCarboni/setup-ffmpeg@v2 + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 + - run: pip install -r requirements.txt gdown + - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ + - run: ${{ matrix.run-headless }} + - run: ${{ matrix.run-validate }} From 8b774af1ac45517424cbae2204adfc8ef5b351f6 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Mon, 5 Jun 2023 15:54:10 +0200 Subject: [PATCH 08/10] Run test on Linux and Windows --- .github/workflows/ci.yml | 70 +++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3576773..7d0eec8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,39 +3,37 @@ name: ci on: [ push, pull_request ] jobs: - lint: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up Python 3.9 - uses: actions/setup-python@v2 - with: - python-version: 3.9 - - run: pip install flake8 - - run: flake8 run.py core - test: - runs-on: ${{ matrix.os }} - strategy: - matrix: - ubuntu: - os: ubuntu-latest - run-headless: python run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 - run-validate: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex psnr -f null - - windows: - os: windows-latest - run-headless: python run.py -f .github\examples\face.jpg -t .github\examples\target.mp4 -o .github\examples\output.mp4 - run-validate: ffmpeg -i .github\examples\snapshot.mp4 -i .github/examples\output.mp4 -filter_complex psnr -f null - - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up ffmpeg - uses: FedericoCarboni/setup-ffmpeg@v2 - - name: Set up Python 3.9 - uses: actions/setup-python@v2 - with: - python-version: 3.9 - - run: pip install -r requirements.txt gdown - - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ - - run: ${{ matrix.run-headless }} - - run: ${{ matrix.run-validate }} + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 + - run: pip install flake8 + - run: flake8 run.py core + test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + ubuntu: + os: ubuntu-latest + run: python run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 + windows: + os: windows-latest + run: python run.py -f .github\examples\face.jpg -t .github\examples\target.mp4 -o .github\examples\output.mp4 + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up ffmpeg + uses: FedericoCarboni/setup-ffmpeg@v2 + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 + - run: pip install -r requirements.txt gdown + - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ + - run: ${{ matrix.run }} + From 4dc4436b2fb29e4227c86095a13b8af808304bc3 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Mon, 5 Jun 2023 15:57:02 +0200 Subject: [PATCH 09/10] Run test on Linux and Windows --- .github/workflows/ci.yml | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d0eec8..78efb5c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,16 +14,8 @@ jobs: python-version: 3.9 - run: pip install flake8 - run: flake8 run.py core - test: - runs-on: ${{ matrix.os }} - strategy: - matrix: - ubuntu: - os: ubuntu-latest - run: python run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 - windows: - os: windows-latest - run: python run.py -f .github\examples\face.jpg -t .github\examples\target.mp4 -o .github\examples\output.mp4 + test-ubuntu: + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 @@ -35,5 +27,20 @@ jobs: python-version: 3.9 - run: pip install -r requirements.txt gdown - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ - - run: ${{ matrix.run }} + - run: python run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 + test-windows: + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up ffmpeg + uses: FedericoCarboni/setup-ffmpeg@v2 + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 + - run: pip install -r requirements.txt gdown + - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ + - run: python run.py -f=.github\examples\face.jpg -t=.github\examples\target.mp4 -o=.github\examples\output.mp4 + From 36787d739dbd5423c9a5e31b1d455a84416bb7ca Mon Sep 17 00:00:00 2001 From: henryruhs Date: Mon, 5 Jun 2023 16:15:33 +0200 Subject: [PATCH 10/10] Revert to Ubuntu test only as Windows hangs --- .github/workflows/ci.yml | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78efb5c..de2ea3e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: python-version: 3.9 - run: pip install flake8 - run: flake8 run.py core - test-ubuntu: + test: runs-on: ubuntu-latest steps: - name: Checkout @@ -28,19 +28,3 @@ jobs: - run: pip install -r requirements.txt gdown - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ - run: python run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 - test-windows: - runs-on: windows-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up ffmpeg - uses: FedericoCarboni/setup-ffmpeg@v2 - - name: Set up Python 3.9 - uses: actions/setup-python@v2 - with: - python-version: 3.9 - - run: pip install -r requirements.txt gdown - - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ - - run: python run.py -f=.github\examples\face.jpg -t=.github\examples\target.mp4 -o=.github\examples\output.mp4 - -