From 5d6258e17e4e2410071e15e1c0c5c5924843f0cf Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 6 Jun 2026 11:39:53 +0200 Subject: [PATCH] add vp9 support --- facefusion/codecs/vpx_decoder.py | 11 ++++++++--- facefusion/codecs/vpx_encoder.py | 16 +++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/facefusion/codecs/vpx_decoder.py b/facefusion/codecs/vpx_decoder.py index 70c02037..894a1e01 100644 --- a/facefusion/codecs/vpx_decoder.py +++ b/facefusion/codecs/vpx_decoder.py @@ -3,15 +3,20 @@ import struct from typing import Optional from facefusion.libraries import vpx as vpx_module -from facefusion.types import VpxDecoder, VpxPointer +from facefusion.types import VideoCodec, VpxDecoder, VpxPointer -def create(thread_count : int) -> Optional[VpxDecoder]: +def create(video_codec : VideoCodec, thread_count : int) -> Optional[VpxDecoder]: vpx_library = vpx_module.create_static_library() if vpx_library: vpx_decoder = ctypes.create_string_buffer(64) - vpx_codec = ctypes.c_void_p.in_dll(vpx_library, 'vpx_codec_vp8_dx_algo') + vpx_algo = 'vpx_codec_vp8_dx_algo' + + if video_codec == 'vp9': + vpx_algo = 'vpx_codec_vp9_dx_algo' + + vpx_codec = ctypes.c_void_p.in_dll(vpx_library, vpx_algo) config_buffer = ctypes.create_string_buffer(128) struct.pack_into('I', config_buffer, 0, thread_count) diff --git a/facefusion/codecs/vpx_encoder.py b/facefusion/codecs/vpx_encoder.py index 078a3e7c..ac7ccaf0 100644 --- a/facefusion/codecs/vpx_encoder.py +++ b/facefusion/codecs/vpx_encoder.py @@ -3,24 +3,30 @@ import struct from typing import Optional from facefusion.libraries import vpx as vpx_module -from facefusion.types import BitRate, Resolution, VpxEncoder +from facefusion.types import BitRate, Resolution, VideoCodec, VpxEncoder -def create(frame_resolution : Resolution, bitrate : BitRate, thread_count : int, cpu_count : int) -> Optional[VpxEncoder]: +def create(video_codec : VideoCodec, frame_resolution : Resolution, bitrate : BitRate, thread_count : int, cpu_count : int) -> Optional[VpxEncoder]: vpx_library = vpx_module.create_static_library() if vpx_library: vpx_encoder = ctypes.create_string_buffer(640) - vp8_codec = ctypes.c_void_p.in_dll(vpx_library, 'vpx_codec_vp8_cx_algo') + vpx_algo = 'vpx_codec_vp8_cx_algo' + + if video_codec == 'vp9': + vpx_algo = 'vpx_codec_vp9_cx_algo' + + vpx_codec = ctypes.c_void_p.in_dll(vpx_library, vpx_algo) config_buffer = ctypes.create_string_buffer(512) - if vpx_library.vpx_codec_enc_config_default(ctypes.byref(vp8_codec), config_buffer, 0) == 0: + if vpx_library.vpx_codec_enc_config_default(ctypes.byref(vpx_codec), config_buffer, 0) == 0: struct.pack_into('I', config_buffer, 4, thread_count) struct.pack_into('I', config_buffer, 12, frame_resolution[0]) struct.pack_into('I', config_buffer, 16, frame_resolution[1]) struct.pack_into('I', config_buffer, 28, 1) struct.pack_into('I', config_buffer, 36, 0) + struct.pack_into('I', config_buffer, 44, 0) struct.pack_into('I', config_buffer, 72, 0) struct.pack_into('I', config_buffer, 112, bitrate) struct.pack_into('I', config_buffer, 116, 2) @@ -28,7 +34,7 @@ def create(frame_resolution : Resolution, bitrate : BitRate, thread_count : int, struct.pack_into('I', config_buffer, 124, 50) struct.pack_into('I', config_buffer, 128, 50) - if vpx_library.vpx_codec_enc_init_ver(vpx_encoder, ctypes.byref(vp8_codec), config_buffer, 0, 39) == 0: + if vpx_library.vpx_codec_enc_init_ver(vpx_encoder, ctypes.byref(vpx_codec), config_buffer, 0, 39) == 0: vpx_library.vpx_codec_control_(vpx_encoder, 13, ctypes.c_int(cpu_count)) vpx_library.vpx_codec_control_(vpx_encoder, 12, ctypes.c_int(0)) vpx_library.vpx_codec_control_(vpx_encoder, 27, ctypes.c_int(10))