changes for vp9 support

This commit is contained in:
henryruhs
2026-06-06 12:39:14 +02:00
parent 5287ce6dcb
commit f3bc5ffb4b
7 changed files with 61 additions and 68 deletions
+17 -8
View File
@@ -2,6 +2,8 @@ from unittest.mock import patch
import cv2
import pytest
from facefusion.types import VxpVideoCodec
from tests.assert_helper import get_test_example_file, get_test_examples_directory
from facefusion import state_manager
@@ -22,28 +24,35 @@ def before_all() -> None:
vpx_module.pre_check()
def test_create() -> None:
assert create((320, 240), 1000, 8, 16)
@pytest.mark.parametrize('video_codec', [ 'vp8', 'vp9' ])
def test_create(video_codec : VxpVideoCodec) -> None:
assert create(video_codec, (320, 240), 1000, 8, 16)
with patch('facefusion.libraries.vpx.create_static_library', return_value = None):
assert create((320, 240), 1000, 8, 16) is None
assert create(video_codec, (320, 240), 1000, 8, 16) is None
def test_encode() -> None:
@pytest.mark.parametrize('video_codec', [ 'vp8', 'vp9' ])
def test_encode(video_codec : VxpVideoCodec) -> None:
video_frame = read_video_frame(get_test_example_file('target-240p.mp4'))
video_buffer = cv2.cvtColor(video_frame, cv2.COLOR_BGR2YUV_I420).tobytes()
video_resolution = (video_frame.shape[1], video_frame.shape[0])
vpx_encoder = create(video_resolution, 1000, 1, 0)
vpx_encoder = create(video_codec, video_resolution, 1000, 1, 0)
if is_linux() or is_windows():
assert create_hash(encode(vpx_encoder, video_buffer, video_resolution, 3)) == 'ce133a1f'
if video_codec == 'vp8':
assert create_hash(encode(vpx_encoder, video_buffer, video_resolution, 3)) == 'ce133a1f'
if video_codec == 'vp9':
assert create_hash(encode(vpx_encoder, video_buffer, video_resolution, 3)) == 'b0760d5e'
if is_macos():
pytest.skip()
def test_destroy() -> None:
vpx_encoder = create((320, 240), 1000, 8, 16)
@pytest.mark.parametrize('video_codec', [ 'vp8', 'vp9' ])
def test_destroy(video_codec : VxpVideoCodec) -> None:
vpx_encoder = create(video_codec, (320, 240), 1000, 8, 16)
with patch.object(vpx_module.create_static_library(), 'vpx_codec_destroy') as mock:
destroy(vpx_encoder)