Skip to content

Commit

Permalink
Fixed some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailCosmin committed Jul 30, 2022
1 parent 285362a commit aeb7686
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 21 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# monkeyshot
Utility for making easy screenshots

Works on Windows
TODO: Make it work on Linux
3 changes: 3 additions & 0 deletions build_exe.bat
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ rem if exist "dist\" @RD /S /Q "dist"
rem del "monkeyshot.spec"
if exist "monkeyShot_venv\" @RD /S /Q "monkeyShot_venv"

:: Copy 3rd folder to dist
robocopy 3rd\ "dist\monkeyshot\3rd" /E

timeout /t 100
3 changes: 2 additions & 1 deletion monkeyshot.spec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ a.datas += [('img\\monkey.ico','monkeyshot\\img\\monkey.ico', "DATA"),
('img\\record_button_48px_#AA0000.png','monkeyshot\\img\\record_button_48px_#AA0000.png', "DATA"),
('img\\region_record_button_48px_#AA0000.png','monkeyshot\\img\\region_record_button_48px_#AA0000.png', "DATA"),
('img\\settings_button_48px_#AA0000.png','monkeyshot\\img\\settings_button_48px_#AA0000.png', "DATA"),
('img\\static_screenshot_button_48px_#AA0000.png','monkeyshot\\img\\static_screenshot_button_48px_#AA0000.png', "DATA")
('img\\static_screenshot_button_48px_#AA0000.png','monkeyshot\\img\\static_screenshot_button_48px_#AA0000.png', "DATA"),
('img\\streamer_button_48px_#AA0000.png','monkeyshot\\img\\streamer_button_48px_#AA0000.png', "DATA"),
]

pyz = PYZ(a.pure, a.zipped_data,
Expand Down
62 changes: 43 additions & 19 deletions monkeyshot/monkeyshot.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,21 @@ def get_audio_devices() -> (str, list):
"""
audio_devices_raw = query_devices()
audio_devices = []
default_input_device = "None"
for audio_device in f"{audio_devices_raw}".split('\n'):
device_name = audio_device[4:].split(", ")[0].strip()
if '>' in audio_device:
default_input_device = device_name
elif device_name not in audio_devices and ")" in device_name and "0 in" not in audio_device:
audio_devices.append(device_name)

default_audio = None
for audio_device in f"{audio_devices_raw}".split('\n'):
if default_input_device in audio_device:
default_audio = audio_device[4:].split(", ")[0].strip()

audio_devices.remove(default_audio)
if default_audio in audio_devices:
audio_devices.remove(default_audio)
return default_audio, audio_devices

class MonkeyHouse:
Expand Down Expand Up @@ -652,33 +656,46 @@ class MonkeyShot:
self.window.mainloop()
return self.monkey_screenshot

def record(self, region=None, audio: str = None):
ffmpeg = "D:\\monkeyshot\\3rd\\ffmpeg.exe"
def record(self, region=None, audio: str = None) -> None:
"""Record a video of the screen
Args:
region (list, optional): Region to record. Defaults to None.
audio (str, optional): Audio to record. Defaults to None.
Returns:
None
"""
ffmpeg = abspath(".//3rd//ffmpeg.exe")
width, height = size()
resolution = f'{width}x{height}'
if region is not None:
resolution = f'{region[2]}x{region[3]}'

filename = "Video_recording.mp4"

default_input_device = "None"
if audio is None:
audio_devices = query_devices()
for audio_device in f"{audio_devices}".split('\n'):
if '>' in audio_device:
default_input_device = audio_device[4:].split(", ")[0].strip()
break

for audio_device in f"{audio_devices}".split('\n'):
if default_input_device in audio_device:
input_device = audio_device[4:].split(", ")[0].strip()
break

audio = input_device
audio = f'-f dshow -channel_layout stereo -thread_queue_size 1024 -i audio="{input_device}"' \
if default_input_device != "None" else ''

offset_x = 0
offset_y = 0
if region is not None:
offset_x = region[0]
offset_y = region[1]

cmd = f"""{ffmpeg} -y \
cmd = f'"{ffmpeg}" -y \
-rtbufsize 200M \
-f gdigrab \
-thread_queue_size 1024 \
Expand All @@ -690,32 +707,38 @@ class MonkeyShot:
-offset_x {offset_x} \
-offset_y {offset_y} \
-i desktop \
-f dshow \
-channel_layout stereo \
-thread_queue_size 1024 \
-i audio="{audio}" \
{audio} \
-c:v libx264 \
-r 10 -preset ultrafast \
-tune zerolatency \
-crf 25 \
-pix_fmt yuv420p \
-c:a aac \
-strict -2 -ac 2 -b:a 128k \
-vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" "{filename}" """

-vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" "{filename}" '.replace(" ", "")
print(f"cmd = {cmd}")
with Popen(cmd, shell=False, stdin=PIPE, creationflags=CREATE_NO_WINDOW) as ffmpeg_process:
wait_for_key('esc')
ffmpeg_process.stdin.write(b'q') # send q to end ffmpeg process

def streaming_record(self, region=None, audio: str = None):
ffmpeg = "D:\\monkeyshot\\3rd\\ffmpeg.exe"
def streaming_record(self, region=None, audio: str = None) -> None:
"""Record a video of the screen
Args:
region (list, optional): Region to record. Defaults to None.
audio (str, optional): Audio to record. Defaults to None.
Returns:
None
"""
ffmpeg = abspath(".//3rd//ffmpeg.exe")
width, height = size()
resolution = f'{width}x{height}'
if region is not None:
resolution = f'{region[2]}x{region[3]}'

filename = "Video_recording.mp4"

default_input_device = "None"
if audio is None:
audio_devices = query_devices()
for audio_device in f"{audio_devices}".split('\n'):
Expand All @@ -725,7 +748,7 @@ class MonkeyShot:
if default_input_device in audio_device:
input_device = audio_device[4:].split(", ")[0].strip()

audio = input_device
audio = f':audio="{input_device}"' if default_input_device != "None" else ''

camera = get_video_devices()[0]
offset_x = 0
Expand All @@ -734,7 +757,7 @@ class MonkeyShot:
offset_x = region[0]
offset_y = region[1]

cmd = f'''{ffmpeg} -f gdigrab \
cmd = f'{ffmpeg} -f gdigrab \
-rtbufsize 100M \
-probesize 20M \
-framerate 24 \
Expand All @@ -746,11 +769,12 @@ class MonkeyShot:
-f dshow \
-rtbufsize 100M \
-probesize 20M \
-i video="{camera}":audio="{audio}" \
-i video="{camera}"{audio} \
-filter_complex "[0:v] scale=1920x1080[desktop]; \
[1:v] scale=320x240 [webcam]; \
[desktop][webcam] overlay=x=W-w-50:y=H-h-50" \
"{filename}"'''
"{filename}"'.replace(" ", "")
print(f"cmd = {cmd}")

with Popen(cmd, shell=False, stdin=PIPE, creationflags=CREATE_NO_WINDOW) as ffmpeg_process:
wait_for_key('esc')
Expand Down
2 changes: 1 addition & 1 deletion monkeyshot/settings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Settings>
<AudioDevice>Microphone (Realtek High Definition Audio)</AudioDevice>
<AudioDevice>Mikrofonarray (Realtek HD Audio Mic input)</AudioDevice>
<VideoDevice>USB Camera</VideoDevice>
</Settings>
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pyinstaller==4.5
pyautogui==0.9.53
pillow==8.4.0
keyboard==0.13.5
sounddevice

0 comments on commit aeb7686

Please sign in to comment.