mirror of
https://github.com/facefusion/facefusion.git
synced 2026-07-15 22:47:25 +02:00
f9016dfc36
* audio metadata * audio metadata * audio metadata * audio metadata * audio metadata * audio metadata * audio metadata
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
from typing import Optional
|
|
|
|
from starlette.datastructures import Headers
|
|
from starlette.types import Scope
|
|
|
|
from facefusion.audio import detect_audio_duration
|
|
from facefusion.ffprobe import detect_audio_channel_total, detect_audio_format, detect_audio_frame_total, detect_audio_sample_rate
|
|
from facefusion.types import AudioMetadata, ImageMetadata, VideoMetadata
|
|
from facefusion.vision import count_video_frame_total, detect_image_resolution, detect_video_duration, detect_video_fps, detect_video_resolution
|
|
|
|
|
|
def get_sec_websocket_protocol(scope : Scope) -> Optional[str]:
|
|
protocol_header = Headers(scope = scope).get('Sec-WebSocket-Protocol')
|
|
|
|
if protocol_header:
|
|
protocol, _, _ = protocol_header.partition(',')
|
|
return protocol.strip()
|
|
|
|
return None
|
|
|
|
|
|
def extract_audio_metadata(file_path : str) -> AudioMetadata:
|
|
metadata : AudioMetadata =\
|
|
{
|
|
'duration' : detect_audio_duration(file_path),
|
|
'sample_rate' : detect_audio_sample_rate(file_path),
|
|
'frame_total' : detect_audio_frame_total(file_path),
|
|
'channels' : detect_audio_channel_total(file_path),
|
|
'format' : detect_audio_format(file_path)
|
|
}
|
|
return metadata
|
|
|
|
|
|
def extract_image_metadata(file_path : str) -> ImageMetadata:
|
|
metadata : ImageMetadata =\
|
|
{
|
|
'resolution' : detect_image_resolution(file_path)
|
|
}
|
|
return metadata
|
|
|
|
|
|
def extract_video_metadata(file_path : str) -> VideoMetadata:
|
|
metadata : VideoMetadata =\
|
|
{
|
|
'duration' : detect_video_duration(file_path),
|
|
'frame_total' : count_video_frame_total(file_path),
|
|
'fps' : detect_video_fps(file_path),
|
|
'resolution' : detect_video_resolution(file_path)
|
|
}
|
|
return metadata
|