添加屏幕录制分辨率自适应选项
parent
eb3de04d67
commit
7f83800296
|
@ -38,6 +38,7 @@ class RecordConfig():
|
|||
record_section_name = 'record'
|
||||
conf.add_section(record_section_name)
|
||||
conf.set(record_section_name,'resolution','1920x1080')
|
||||
conf.set(record_section_name,'adaptive_screen_resolution','1')
|
||||
conf.set(record_section_name,'vcodec','libx264')
|
||||
conf.set(record_section_name,'frame_rate','7.0')
|
||||
conf.set(record_section_name,'file_dir','.')
|
||||
|
|
|
@ -72,6 +72,8 @@ class RecordVideo():
|
|||
self.video_codec=rc.config.get('record','vcodec')
|
||||
#分辨率
|
||||
self.resolution=rc.config.get('record','resolution')
|
||||
#是否自适应屏幕录制分辨率
|
||||
self.adaptive_screen_resolution = rc.config.getboolean('record', 'adaptive_screen_resolution')
|
||||
#帧率
|
||||
self.brate=rc.config.getfloat('record','frame_rate')
|
||||
#文件目录
|
||||
|
@ -213,15 +215,17 @@ class RecordVideo():
|
|||
# print(record_cmd)
|
||||
self.record(record_cmd, self.start_ffmpeg)
|
||||
|
||||
def record_screen(self):
|
||||
def record_screen(self, resolution='1024x768'):
|
||||
if self.screen_name and self.system_voice_device_name:
|
||||
self.record_type=RecordType.Screen
|
||||
if self.adaptive_screen_resolution is not True:
|
||||
resolution = self.resolution
|
||||
record_cmd='ffmpeg -f dshow -i video="{}":audio="{}" -acodec libmp3lame -vcodec {} -preset:v ultrafast -tune:v zerolatency -s {} -r {} -threads {} -y {}'.format(
|
||||
self.deal_with_device_name(self.screen_name),
|
||||
self.deal_with_device_name(self.system_voice_device_name),
|
||||
self.video_codec,
|
||||
# '1024x768', #屏幕录制分辨率固定
|
||||
self.resolution,
|
||||
resolution,
|
||||
self.brate,
|
||||
self.threads,
|
||||
self.get_file_name()
|
||||
|
|
|
@ -19,12 +19,13 @@ from RecordHelp import *
|
|||
|
||||
class RecordWindow(QtWidgets.QWidget):
|
||||
|
||||
def __init__(self, parent = None):
|
||||
def __init__(self, parent = None, screen_resolution=None):
|
||||
super(RecordWindow,self).__init__(parent)
|
||||
self.setupUi()
|
||||
self.load_modules()
|
||||
#更新设置
|
||||
self.need_update_config = False
|
||||
self.screen_resolution = screen_resolution
|
||||
# self.need_hide = True
|
||||
#初始化状态
|
||||
print('初始化状态...')
|
||||
|
@ -39,7 +40,6 @@ class RecordWindow(QtWidgets.QWidget):
|
|||
self.rti = RecordTrayIcon(self)
|
||||
self.rti.update_state(self.recording, self.record_type)
|
||||
|
||||
|
||||
self.sc = Shortcut()
|
||||
|
||||
self.update_setting(True)
|
||||
|
@ -320,7 +320,7 @@ class RecordWindow(QtWidgets.QWidget):
|
|||
self.rv.record_camera()
|
||||
elif rtype == RecordType.Screen:
|
||||
print('开始录制屏幕...')
|
||||
self.rv.record_screen()
|
||||
self.rv.record_screen(resolution=self.screen_resolution)
|
||||
|
||||
self.start_timer()
|
||||
self.update_state()
|
||||
|
@ -491,7 +491,9 @@ if __name__ == '__main__':
|
|||
app = QtWidgets.QApplication(sys.argv)
|
||||
#当这个属性为True,应用程序会在最后一个可见窗口关闭时退出。
|
||||
app.setQuitOnLastWindowClosed(False)
|
||||
rw = RecordWindow()
|
||||
screen = app.desktop().screenGeometry()
|
||||
resolution = '{}x{}'.format(screen.width(), screen.height())
|
||||
rw = RecordWindow(screen_resolution=resolution)
|
||||
rw.monitor_shortcut()
|
||||
rw.rti.show()
|
||||
rw.show()
|
||||
|
|
|
@ -187,6 +187,10 @@ class SettingWindow(QDialog):
|
|||
self.threads_spinBox.setSizePolicy(sizePolicy)
|
||||
self.threads_spinBox.setObjectName("record.threads")
|
||||
self.gridLayout.addWidget(self.threads_spinBox, 5, 1, 1, 1)
|
||||
self.ckb_adaptive_screen_resolution = QtWidgets.QCheckBox(self.gridLayoutWidget)
|
||||
self.ckb_adaptive_screen_resolution.setObjectName("ckb_adaptive_screen_resolution")
|
||||
self.ckb_adaptive_screen_resolution.setStyleSheet("padding-left:10")
|
||||
self.gridLayout.addWidget(self.ckb_adaptive_screen_resolution, 0, 2, 1, 1)
|
||||
self.tabWidget.addTab(self.tab_record, "")
|
||||
|
||||
self.save_button = QtWidgets.QPushButton(self)
|
||||
|
@ -218,6 +222,7 @@ class SettingWindow(QDialog):
|
|||
self.label_12.setText(_translate("Form", "分辨率:"))
|
||||
self.btn_file_dir.setText(_translate("Form", "选择文件目录"))
|
||||
self.threads_label.setText(_translate("Form", "CPU线程:"))
|
||||
self.ckb_adaptive_screen_resolution.setText(_translate("Form", "屏幕录制自适应"))
|
||||
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_record), _translate("Form", "录制参数"))
|
||||
self.save_button.setText(_translate("Form", "保存"))
|
||||
self.cancel_button.setText(_translate("Form", "取消"))
|
||||
|
@ -273,12 +278,13 @@ class SettingWindow(QDialog):
|
|||
record_file_dir = self.rc.config.get('record','file_dir')
|
||||
record_file_dir = os.path.abspath(record_file_dir)
|
||||
record_threads = int(self.rc.config.get('record','threads'))
|
||||
record_adaptive_resolution = self.rc.config.getboolean('record', 'adaptive_screen_resolution')
|
||||
|
||||
self.cb_resolution.setCurrentIndex(self.cb_resolution.findData(record_resolution))
|
||||
self.ckb_adaptive_screen_resolution.setChecked(record_adaptive_resolution)
|
||||
self.cb_vcodec.setCurrentIndex(self.cb_vcodec.findData(record_vcodec))
|
||||
self.dsb_frame_rate.setValue(record_frame_rate)
|
||||
self.le_file_path.setText(record_file_dir)
|
||||
|
||||
self.threads_spinBox.setValue(record_threads)
|
||||
|
||||
def load(self):
|
||||
|
@ -341,7 +347,7 @@ class SettingWindow(QDialog):
|
|||
self.dsb_frame_rate.valueChanged.connect(self.stateChangedEvent)
|
||||
self.le_file_path.textChanged.connect(self.stateChangedEvent)
|
||||
self.threads_spinBox.valueChanged.connect(self.stateChangedEvent)
|
||||
|
||||
self.ckb_adaptive_screen_resolution.stateChanged.connect(self.stateChangedEvent)
|
||||
# self.le_start_record_camera_shortcut.keyPressEvent = self.record_keypress
|
||||
# print(dir(self.le_start_record_camera_shortcut.keyPressEvent))
|
||||
|
||||
|
@ -410,6 +416,7 @@ class SettingWindow(QDialog):
|
|||
|
||||
#录制
|
||||
resolution = self.cb_resolution.currentData()
|
||||
adaptive_screen_resolution = str(self.ckb_adaptive_screen_resolution.isChecked())
|
||||
video_codec = self.cb_vcodec.currentData()
|
||||
frame_rate = self.dsb_frame_rate.value()
|
||||
file_dir = self.le_file_path.text()
|
||||
|
@ -432,6 +439,7 @@ class SettingWindow(QDialog):
|
|||
|
||||
record_section_name = 'record'
|
||||
conf.set(record_section_name,'resolution', resolution)
|
||||
conf.set(record_section_name,'adaptive_screen_resolution', adaptive_screen_resolution)
|
||||
conf.set(record_section_name,'vcodec', video_codec)
|
||||
conf.set(record_section_name,'frame_rate', str(frame_rate))
|
||||
conf.set(record_section_name,'file_dir', file_dir)
|
||||
|
@ -474,48 +482,9 @@ class SettingWindow(QDialog):
|
|||
else:
|
||||
pass
|
||||
print('not found this section or name.')
|
||||
|
||||
# def indexChangedEvent(self, index, obj):
|
||||
|
||||
# print('in data changed event.')
|
||||
# print(index)
|
||||
# print('event obj:%s' % type(obj))
|
||||
# print('obj name:%s' % obj.objectName())
|
||||
|
||||
# value = obj.currentData()
|
||||
# obj_name = obj.objectName()
|
||||
# self.setting(obj_name, value)
|
||||
|
||||
def stateChangedEvent(self, new_value):
|
||||
print('changed value is :%s' % new_value)
|
||||
self.changed = True
|
||||
self.update_state()
|
||||
|
||||
# def textChangedEvent(self, obj):
|
||||
|
||||
# print('type of self:%s' % type(self))
|
||||
# print('type of text:%s' % type(text))
|
||||
# print('type of obj:%s' % type(obj))
|
||||
# value = obj.text()
|
||||
# obj_name = obj.objectName()
|
||||
# self.setting(obj_name, value)
|
||||
|
||||
# def valueChangedEvent(self, new_value):
|
||||
# print('changed value is :%s.' % new_value)
|
||||
|
||||
# self.changed = True
|
||||
# self.update_state()
|
||||
# obj = self.dsb_frame_rate
|
||||
# value = obj.value()
|
||||
# print('value:%1.f' % value)
|
||||
# obj_name = obj.objectName()
|
||||
# self.setting(obj_name, str(value))
|
||||
|
||||
# def valueChangedEvent_spinBox(self):
|
||||
# print('in value changed event.')
|
||||
# obj = self.threads_spinBox
|
||||
# value = obj.value()
|
||||
# print('value:%1.f' % value)
|
||||
# obj_name = obj.objectName()
|
||||
# self.setting(obj_name, str(value))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue