本文整理汇总了Python中video.Video.load方法的典型用法代码示例。如果您正苦于以下问题:Python Video.load方法的具体用法?Python Video.load怎么用?Python Video.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类video.Video
的用法示例。
在下文中一共展示了Video.load方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VideoWidget
# 需要导入模块: from video import Video [as 别名]
# 或者: from video.Video import load [as 别名]
class VideoWidget(QWidget):
signal_play_option = pyqtSignal(int)
signal_video_loaded = pyqtSignal(str)
def __init__(self, parent=None, max_buf_size=500):
super(VideoWidget, self).__init__(parent)
self.video = Video(max_buf_size=max_buf_size)
self.max_buf_size = max_buf_size
self.init_ui()
self.slider.sliderReleased.connect(self.on_slider_released)
self.installEventFilter(self)
def init_ui(self):
self.grid_layout = QGridLayout()
self.grid_layout.setRowStretch(0, 1)
self.grid_layout.setRowStretch(1, 10)
self.grid_layout.setRowStretch(2, 1)
self.set_slider()
self.set_label_filename()
self.set_label_frame()
self.setLayout(self.grid_layout)
self.setFocusPolicy(Qt.StrongFocus)
def set_slider(self):
self.slider = QSlider(Qt.Horizontal)
self.slider.setRange(0, 1000)
self.slider.setTickInterval(1)
self.slider.setValue(0)
self.slider.setEnabled(False)
self.grid_layout.addWidget(self.slider, 2, 0)
def set_label_filename(self):
self.label_filename = QLabel('filename')
self.label_filename.setAlignment(Qt.AlignCenter)
self.grid_layout.addWidget(self.label_filename, 0, 0)
def set_label_frame(self):
self.label_frame = QLabel('video')
self.label_frame.setAlignment(Qt.AlignCenter)
self.label_frame.setStyleSheet('border: 1px solid black')
self.grid_layout.addWidget(self.label_frame, 1, 0)
def eventFilter(self, object, event):
if event.type() == QEvent.KeyPress:
key = event.key()
print('key pressed in video filter ', object, key)
if key == Qt.Key_D:
self.video.next_frame()
return True
elif key == Qt.Key_A:
self.video.last_frame()
return True
elif key == Qt.Key_Left:
if self.video.play_status >= 0:
self.signal_play_option.emit(-1)
else:
self.signal_play_option.emit(0)
return True
elif key == Qt.Key_Right:
if self.video.play_status <= 0:
self.signal_play_option.emit(1)
else:
self.signal_play_option.emit(0)
return True
elif key == Qt.Key_Space:
self.video.play_status = 0
return True
else:
print('send to parent ', self.parent())
print('send to parent\'s parent ', self.parent().parent())
return False
else:
return False
@pyqtSlot()
def open_file(self):
self.filename, _ = QFileDialog.getOpenFileName(
self, 'Load video', './', 'Videos (*.mp4 *.avi *.mkv *.flv *.m4v)')
if not self.filename:
return
disp_name = os.path.basename(self.filename)
self.label_filename.setText(os.path.basename(disp_name))
self.video.load(self.filename)
self.signal_play_option.connect(self.video.play_ctl)
self.video.signal_frame_updated.connect(self.update_frame)
self.video.next_frame()
self.slider.setEnabled(True)
self.signal_video_loaded.emit(self.filename)
@pyqtSlot(QPixmap)
def update_frame(self, pixmap):
frame_cursor = self.video.frame_cursor
frame_num = self.video.frame_num
self.label_frame.setPixmap(
pixmap.scaled(self.label_frame.width() - 2,
self.label_frame.height() - 2,
Qt.KeepAspectRatio))
self.label_frame.update()
self.slider.setValue(int(frame_cursor * self.slider.maximum() / frame_num))
#.........这里部分代码省略.........