mirror of
https://github.com/facefusion/facefusion.git
synced 2026-06-07 13:13:53 +02:00
add vp9 support
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user