/
camera.py
62 lines (53 loc) · 2.31 KB
/
camera.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import PyQt5.QtMultimedia as QtMultimedia
from PyQt5.QtCore import QUrl, QObject
from PyQt5.QtMultimedia import QMediaRecorder, QCamera, QCameraInfo, QCameraViewfinderSettings, QAudioEncoderSettings, \
QVideoEncoderSettings
from PyQt5.QtMultimediaWidgets import QCameraViewfinder
class Camera(QObject):
def __init__(self, parent=QObject()):
super(Camera, self).__init__(parent)
# chooses the system default camera
self.cam = QCamera()
self.caminfo = QCameraInfo(self.cam)
self.camvfind = QCameraViewfinder()
self.camvfindset = QCameraViewfinderSettings()
self.recorder = QMediaRecorder(self.cam)
def iniCamera(self):
cameras = QCameraInfo.availableCameras()
for cameraInfo in cameras:
# select the capturing device if it is available
if (cameraInfo.description().find("Capture") is not -1):
self.cam = QCamera(cameraInfo)
self.caminfo = QCameraInfo(self.cam)
self.recorder = QMediaRecorder(self.cam)
print("Camera Chosen: " + self.caminfo.description())
print(self.cam.supportedViewfinderFrameRateRanges())
if self.cam.isCaptureModeSupported(QCamera.CaptureVideo):
print("Capturemode supported")
def startVid(self):
self.cam.load()
# self.camvfind.show()
self.cam.setViewfinder(self.camvfind)
self.cam.setCaptureMode(QCamera.CaptureVideo)
self.cam.start()
audio = QAudioEncoderSettings()
audio.setCodec("audio/amr")
audio.setQuality(QtMultimedia.QMultimedia.NormalQuality)
video = QVideoEncoderSettings()
# video.setCodec("video/mp4")
video.setQuality(QtMultimedia.QMultimedia.NormalQuality)
video.setResolution(1920, 1080)
video.setFrameRate(30.0)
# self.recorder.setAudioSettings(audio)
self.recorder.setVideoSettings(video)
self.recorder.setContainerFormat("mp4")
def startRecording(self, filename):
directory = os.path.abspath(str(os.getcwd()))
abs_path = os.path.join(directory, filename)
self.recorder.setOutputLocation(QUrl(abs_path))
self.recorder.record()
def stopRecording(self):
self.recorder.stop()
def getViewFinder(self):
return self.camvfind