-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
632 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
Oops, something went wrong.