Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
xtsea authored Dec 23, 2023
1 parent c32c062 commit 84a1b7d
Show file tree
Hide file tree
Showing 19 changed files with 632 additions and 0 deletions.
83 changes: 83 additions & 0 deletions RyuzakiLib/types/input_stream/audio_image_piped.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from typing import Dict
from typing import Optional

from ntgcalls import InputMode

from ...ffmpeg import build_command
from ...ffmpeg import check_stream
from .audio_parameters import AudioParameters
from .audio_stream import AudioStream
from .smart_stream import SmartStream
from .video_parameters import VideoParameters
from .video_stream import VideoStream


class AudioImagePiped(SmartStream):
def __init__(
self,
audio_path: str,
image_path: str,
audio_parameters: AudioParameters = AudioParameters(),
video_parameters: VideoParameters = VideoParameters(),
headers: Optional[Dict[str, str]] = None,
additional_ffmpeg_parameters: str = '',
):
self._image_path = image_path
self._audio_path = audio_path
video_parameters.frame_rate = 1
self._audio_data = (
additional_ffmpeg_parameters,
self._audio_path,
audio_parameters,
[],
headers,
)
self._video_data = (
additional_ffmpeg_parameters,
self._image_path,
video_parameters,
[
'-loop',
'1',
'-framerate',
str(video_parameters.frame_rate),
],
headers,
)
super().__init__(
AudioStream(
InputMode.Shell,
' '.join(
build_command(
'ffmpeg',
*self._audio_data,
),
),
audio_parameters,
),
VideoStream(
InputMode.Shell,
' '.join(
build_command(
'ffmpeg',
*self._video_data,
),
),
video_parameters,
),
)

async def check_stream(self):
await check_stream(
*self._audio_data,
)
await check_stream(
*self._video_data,
need_image=True,
)
self.stream_video.path = ' '.join(
build_command(
'ffmpeg',
*self._video_data,
),
)
17 changes: 17 additions & 0 deletions RyuzakiLib/types/input_stream/audio_parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from ..py_object import PyObject
from .audio_quality import AudioQuality


class AudioParameters(PyObject):
def __init__(
self,
bitrate: int = 48000,
channels: int = 1,
):
max_bit, max_chan = max(AudioQuality, key=lambda x: x.value[0]).value
self.bitrate: int = min(bitrate, max_bit)
self.channels: int = min(channels, max_chan)

@staticmethod
def from_quality(quality: AudioQuality):
return AudioParameters(*quality.value)
45 changes: 45 additions & 0 deletions RyuzakiLib/types/input_stream/audio_piped.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from typing import Dict
from typing import Optional

from ntgcalls import InputMode

from ...ffmpeg import build_command
from ...ffmpeg import check_stream
from .audio_parameters import AudioParameters
from .audio_stream import AudioStream
from .smart_stream import SmartStream


class AudioPiped(SmartStream):
def __init__(
self,
path: str,
audio_parameters: AudioParameters = AudioParameters(),
headers: Optional[Dict[str, str]] = None,
additional_ffmpeg_parameters: str = '',
):
self._path = path
self._audio_data = (
additional_ffmpeg_parameters,
self._path,
audio_parameters,
[],
headers,
)
super().__init__(
AudioStream(
InputMode.Shell,
' '.join(
build_command(
'ffmpeg',
*self._audio_data,
),
),
audio_parameters,
),
)

async def check_stream(self):
await check_stream(
*self._audio_data,
)
8 changes: 8 additions & 0 deletions RyuzakiLib/types/input_stream/audio_quality.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from enum import Enum


class AudioQuality(Enum):
STUDIO = (96000, 2)
HIGH = (48000, 2)
MEDIUM = (36000, 1)
LOW = (24000, 1)
16 changes: 16 additions & 0 deletions RyuzakiLib/types/input_stream/audio_stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from ntgcalls import InputMode

from ..py_object import PyObject
from .audio_parameters import AudioParameters


class AudioStream(PyObject):
def __init__(
self,
input_mode: InputMode,
path: str,
parameters: AudioParameters = AudioParameters(),
):
self.input_mode: InputMode = input_mode
self.path: str = path
self.parameters: AudioParameters = parameters
74 changes: 74 additions & 0 deletions RyuzakiLib/types/input_stream/audio_video_piped.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from typing import Dict
from typing import Optional

from ntgcalls import InputMode

from ...ffmpeg import build_command
from ...ffmpeg import check_stream
from .audio_parameters import AudioParameters
from .audio_stream import AudioStream
from .smart_stream import SmartStream
from .video_parameters import VideoParameters
from .video_stream import VideoStream


class AudioVideoPiped(SmartStream):
def __init__(
self,
path: str,
audio_parameters: AudioParameters = AudioParameters(),
video_parameters: VideoParameters = VideoParameters(),
headers: Optional[Dict[str, str]] = None,
additional_ffmpeg_parameters: str = '',
):
self._path = path
self._audio_data = (
additional_ffmpeg_parameters,
self._path,
audio_parameters,
[],
headers,
)
self._video_data = (
additional_ffmpeg_parameters,
self._path,
video_parameters,
[],
headers,
)
super().__init__(
AudioStream(
InputMode.Shell,
' '.join(
build_command(
'ffmpeg',
*self._audio_data,
),
),
audio_parameters,
),
VideoStream(
InputMode.Shell,
' '.join(
build_command(
'ffmpeg',
*self._video_data,
),
),
video_parameters,
),
)

async def check_stream(self):
await check_stream(
*self._audio_data,
)
await check_stream(
*self._video_data,
)
self.stream_video.path = ' '.join(
build_command(
'ffmpeg',
*self._video_data,
),
)
31 changes: 31 additions & 0 deletions RyuzakiLib/types/input_stream/capture_audio_device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from ntgcalls import InputMode

from ...ffmpeg import build_command
from ...media_devices.device_info import DeviceInfo
from .audio_parameters import AudioParameters
from .audio_stream import AudioStream
from .smart_stream import SmartStream


class CaptureAudioDevice(SmartStream):
def __init__(
self,
audio_info: DeviceInfo,
audio_parameters: AudioParameters = AudioParameters(),
):
self._audio_path: str = audio_info.build_ffmpeg_command()
super().__init__(
AudioStream(
InputMode.Shell,
' '.join(
build_command(
'ffmpeg',
'',
self._audio_path,
audio_parameters,
audio_info.ffmpeg_parameters,
),
),
audio_parameters,
),
)
66 changes: 66 additions & 0 deletions RyuzakiLib/types/input_stream/capture_av_desktop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from typing import Dict
from typing import Optional

from ntgcalls import InputMode

from ...ffmpeg import build_command
from ...ffmpeg import check_stream
from ...media_devices.screen_info import ScreenInfo
from .audio_parameters import AudioParameters
from .audio_stream import AudioStream
from .smart_stream import SmartStream
from .video_parameters import VideoParameters
from .video_stream import VideoStream


class CaptureAVDesktop(SmartStream):
def __init__(
self,
audio_path: str,
screen_info: ScreenInfo,
headers: Optional[Dict[str, str]] = None,
additional_ffmpeg_parameters: str = '',
audio_parameters: AudioParameters = AudioParameters(),
video_parameters: VideoParameters = VideoParameters(),
):
self._audio_path = audio_path
self._video_path = screen_info.build_ffmpeg_command(
video_parameters.frame_rate,
)
self._audio_data = (
additional_ffmpeg_parameters,
self._audio_path,
audio_parameters,
[],
headers,
)
super().__init__(
AudioStream(
InputMode.Shell,
' '.join(
build_command(
'ffmpeg',
*self._audio_data,
),
),
audio_parameters,
),
VideoStream(
InputMode.Shell,
' '.join(
build_command(
'ffmpeg',
'',
self._video_path,
video_parameters,
screen_info.ffmpeg_parameters,
),
),
video_parameters,
),
)

async def check_stream(self):
await check_stream(
*self._audio_data,
)
Loading

0 comments on commit 84a1b7d

Please sign in to comment.