Skip to content

Commit 4da9209

Browse files
authored
Uploaded first version of ccc.py and devices.py
1 parent f2d1bb6 commit 4da9209

2 files changed

Lines changed: 102 additions & 0 deletions

File tree

CheapCaptureCard.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import cv2
2+
import numpy as np
3+
import pyaudio
4+
import threading
5+
6+
cap = cv2.VideoCapture(0)
7+
8+
def make_1080p():
9+
cap.set(3, 1920)
10+
cap.set(4, 1080)
11+
def make_720p():
12+
cap.set(3, 1280)
13+
cap.set(4, 720)
14+
def make_480p():
15+
cap.set(3, 640)
16+
cap.set(4, 480)
17+
def change_res(width, height):
18+
cap.set(3, width)
19+
cap.set(4, height)
20+
21+
make_1080p()
22+
change_res(1920, 1080)
23+
24+
# Check if the webcam is opened correctly
25+
if not cap.isOpened():
26+
raise IOError("Cannot open webcam")
27+
28+
cv2.namedWindow('Nintendo Switch', cv2.WINDOW_NORMAL)
29+
p = pyaudio.PyAudio()
30+
31+
# SELECT AUDIO DEVICE
32+
input_device_index = 8
33+
34+
FORMAT = pyaudio.paInt16
35+
CHANNELS = 1
36+
RATE = 44100
37+
CHUNK = 1024
38+
39+
stream = p.open(format=FORMAT,
40+
channels=CHANNELS,
41+
rate=RATE,
42+
input=True,
43+
output=True,
44+
input_device_index=input_device_index,
45+
frames_per_buffer=CHUNK)
46+
47+
def audio_thread():
48+
while True:
49+
try:
50+
audio_data = stream.read(CHUNK)
51+
stream.write(audio_data)
52+
except KeyboardInterrupt:
53+
break
54+
55+
audio_thread = threading.Thread(target=audio_thread)
56+
audio_thread.start()
57+
58+
while True:
59+
ret, frame = cap.read()
60+
frame = cv2.resize(frame, (1920, 1057), fx=1, fy=1, interpolation=cv2.INTER_AREA)
61+
cv2.imshow('Nintendo Switch', frame)
62+
63+
# Get the window size
64+
width = cv2.getWindowImageRect('Nintendo Switch')[2]
65+
height = cv2.getWindowImageRect('Nintendo Switch')[3]
66+
67+
print(f"{width}, {height}")
68+
69+
c = cv2.waitKey(1)
70+
if c == 27:
71+
break
72+
73+
cap.release()
74+
cv2.destroyAllWindows()

devices.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pyaudio
2+
import threading
3+
import cv2
4+
5+
p = pyaudio.PyAudio()
6+
7+
print('Mics:')
8+
9+
# Print available audio devices
10+
for i in range(p.get_device_count()):
11+
info = p.get_device_info_by_index(i)
12+
print(f"Index {i}: {info['name']}")
13+
print('')
14+
print('Cameras:')
15+
16+
17+
# Print available cameras
18+
i = 0
19+
while True:
20+
cap = cv2.VideoCapture(i)
21+
if not cap.isOpened():
22+
break
23+
print(f"Camera index {i}: {cap.get(cv2.CAP_PROP_BACKEND)} - {cap.get(cv2.CAP_PROP_FRAME_WIDTH)}x{cap.get(cv2.CAP_PROP_FRAME_HEIGHT)}")
24+
cap.release()
25+
i += 1
26+
27+
print('')
28+
input('Press Any Key to close')

0 commit comments

Comments
 (0)