mirror of
https://github.com/facefusion/facefusion.git
synced 2026-06-03 03:08:01 +02:00
improve naming, remove flags as not needed (#1108)
* improve naming, remove flags as not needed * fix lint
This commit is contained in:
@@ -63,12 +63,7 @@ def run_video_encode_loop(vision_frame_deque : deque[VisionFrame], session_id :
|
||||
|
||||
if vpx_encoder:
|
||||
yuv_frame = cv2.cvtColor(output_frame, cv2.COLOR_BGR2YUV_I420)
|
||||
vpx_flags = 0
|
||||
|
||||
if pts % keyframe_interval == 0:
|
||||
vpx_flags = 1
|
||||
|
||||
frame_buffer = encode_vpx_buffer(vpx_encoder, yuv_frame.tobytes(), frame_resolution, pts, vpx_flags)
|
||||
frame_buffer = encode_vpx_buffer(vpx_encoder, yuv_frame.tobytes(), frame_resolution, pts)
|
||||
|
||||
if frame_buffer:
|
||||
rtc_store.send_rtc_video(session_id, frame_buffer)
|
||||
|
||||
+22
-21
@@ -37,35 +37,36 @@ def create_vpx_encoder(frame_resolution : Resolution, bitrate : BitRate, thread_
|
||||
return None
|
||||
|
||||
|
||||
def collect_vpx_frame_buffer(vpx_encoder : VpxEncoder) -> bytes:
|
||||
def encode_vpx_buffer(vpx_encoder : VpxEncoder, input_buffer : bytes, frame_resolution : Resolution, frame_index : int) -> bytes:
|
||||
vpx_library = vpx_module.create_static_library()
|
||||
frame_buffer = b''
|
||||
iterator = ctypes.c_void_p(0)
|
||||
packet = vpx_library.vpx_codec_get_cx_data(vpx_encoder, ctypes.byref(iterator))
|
||||
output_buffer = b''
|
||||
|
||||
if vpx_library:
|
||||
temp_buffer = ctypes.create_string_buffer(512)
|
||||
encode_buffer = ctypes.create_string_buffer(input_buffer)
|
||||
|
||||
if vpx_library.vpx_img_wrap(temp_buffer, 0x102, frame_resolution[0], frame_resolution[1], 1, encode_buffer) and vpx_library.vpx_codec_encode(vpx_encoder, temp_buffer, frame_index, 1, 0, 1) == 0:
|
||||
output_buffer = collect_vpx_buffer(vpx_encoder)
|
||||
|
||||
return output_buffer
|
||||
|
||||
|
||||
def collect_vpx_buffer(vpx_encoder : VpxEncoder) -> bytes:
|
||||
vpx_library = vpx_module.create_static_library()
|
||||
output_buffer = b''
|
||||
|
||||
packet_cursor = ctypes.c_void_p(0)
|
||||
packet = vpx_library.vpx_codec_get_cx_data(vpx_encoder, ctypes.byref(packet_cursor))
|
||||
|
||||
while packet:
|
||||
if ctypes.c_int.from_address(packet).value == 0:
|
||||
buffer_pointer = ctypes.c_void_p.from_address(packet + 8).value
|
||||
buffer_size = ctypes.c_size_t.from_address(packet + 16).value
|
||||
frame_buffer += ctypes.string_at(buffer_pointer, buffer_size)
|
||||
output_buffer += ctypes.string_at(buffer_pointer, buffer_size)
|
||||
|
||||
packet = vpx_library.vpx_codec_get_cx_data(vpx_encoder, ctypes.byref(iterator))
|
||||
packet = vpx_library.vpx_codec_get_cx_data(vpx_encoder, ctypes.byref(packet_cursor))
|
||||
|
||||
return frame_buffer
|
||||
|
||||
|
||||
def encode_vpx_buffer(vpx_encoder : VpxEncoder, raw_frame_buffer : bytes, frame_resolution : Resolution, presentation_timestamp : int, flags : int) -> bytes:
|
||||
vpx_library = vpx_module.create_static_library()
|
||||
frame_buffer = b''
|
||||
|
||||
if vpx_library:
|
||||
output_buffer = ctypes.create_string_buffer(512)
|
||||
encode_string_buffer = ctypes.create_string_buffer(raw_frame_buffer)
|
||||
|
||||
if vpx_library.vpx_img_wrap(output_buffer, 0x102, frame_resolution[0], frame_resolution[1], 1, encode_string_buffer) and vpx_library.vpx_codec_encode(vpx_encoder, output_buffer, presentation_timestamp, 1, flags, 1) == 0:
|
||||
frame_buffer = collect_vpx_frame_buffer(vpx_encoder)
|
||||
|
||||
return frame_buffer
|
||||
return output_buffer
|
||||
|
||||
|
||||
def destroy_vpx_encoder(vpx_encoder : VpxEncoder) -> None:
|
||||
|
||||
@@ -36,12 +36,12 @@ def test_encode_vpx_buffer() -> None:
|
||||
buffer_invalid = bytes(0)
|
||||
|
||||
if is_linux() or is_windows():
|
||||
assert create_hash(encode_vpx_buffer(vpx_encoder, buffer_valid, frame_resolution, 3, 1)) == 'ce133a1f'
|
||||
assert create_hash(encode_vpx_buffer(vpx_encoder, buffer_valid, frame_resolution, 3)) == 'ce133a1f'
|
||||
|
||||
if is_macos():
|
||||
assert create_hash(encode_vpx_buffer(vpx_encoder, buffer_valid, frame_resolution, 3, 1)) == '21c36925'
|
||||
assert create_hash(encode_vpx_buffer(vpx_encoder, buffer_valid, frame_resolution, 3)) == '21c36925'
|
||||
|
||||
assert encode_vpx_buffer(vpx_encoder, buffer_invalid, frame_resolution, 0, 0) == b''
|
||||
assert encode_vpx_buffer(vpx_encoder, buffer_invalid, frame_resolution, 0) == b''
|
||||
|
||||
|
||||
def test_destroy_vpx_encoder() -> None:
|
||||
|
||||
Reference in New Issue
Block a user