Here's a plan and implementation for a video editor similar to Premiere Pro using PyQt. This code includes essential features and a modern interface:
import sys
import os
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
QHBoxLayout, QLabel, QPushButton, QFileDialog,
QScrollArea, QFrame, QSplitter, QMenuBar, QMenu,
QAction, QDockWidget, QListWidget, QSlider,
QListWidgetItem, QProgressBar)
from PyQt5.QtCore import Qt, QMimeData, QPoint, QTimer, QSize
from PyQt5.QtGui import (QDragEnterEvent, QDropEvent, QPainter, QColor,
QIcon, QPixmap, QPalette, QLinearGradient)
import cv2
from datetime import timedelta
class TimelineClip(QWidget):
def __init__(self, file_path, parent=None):
super().__init__(parent)
self.file_path = file_path
self.setMinimumHeight(50)
self.setMinimumWidth(100)
self.setAcceptDrops(True)
self.setStyleSheet("""
QWidget {
background-color: #4a90e2;
border-radius: 3px;
color: white;
}
""")
layout = QVBoxLayout()
self.name_label = QLabel(os.path.basename(file_path))
layout.addWidget(self.name_label)
self.setLayout(layout)
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.drag_start_position = event.pos()
def mouseMoveEvent(self, event):
if not (event.buttons() & Qt.LeftButton):
return
if (event.pos() - self.drag_start_position).manhattanLength() < QApplication.startDragDistance():
return
drag = QDrag(self)
mime_data = QMimeData()
mime_data.setText(self.file_path)
drag.setMimeData(mime_data)
drag.exec_(Qt.MoveAction)
class Timeline(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.clips = []
self.current_position = 0
self.scale_factor = 1.0
self.setAcceptDrops(True)
self.setMinimumHeight(200)
self.setStyleSheet("""
QWidget {
background-color: #2b2b2b;
border: 1px solid #1e1e1e;
}
""")
def dragEnterEvent(self, event: QDragEnterEvent):
if event.mimeData().hasText():
event.acceptProposedAction()
def dropEvent(self, event: QDropEvent):
file_path = event.mimeData().text()
pos = event.pos()
clip = TimelineClip(file_path)
clip.move(pos)
clip.show()
self.clips.append(clip)
def paintEvent(self, event):
painter = QPainter(self)
painter.setPen(QColor("#666666"))
# Draw time markers
for x in range(0, self.width(), 100):
painter.drawLine(x, 0, x, 10)
time = x * self.scale_factor
painter.drawText(x - 20, 25, str(timedelta(seconds=int(time))))
# Draw playhead
painter.setPen(QColor("#ff0000"))
painter.drawLine(self.current_position, 0, self.current_position, self.height())
class MediaBrowser(QListWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setAcceptDrops(True)
self.setDragEnabled(True)
self.setViewMode(QListWidget.IconMode)
self.setIconSize(QSize(64, 64))
self.setSpacing(10)
self.setStyleSheet("""
QListWidget {
background-color: #2b2b2b;
border: none;
}
QListWidget::item {
background-color: #3b3b3b;
border-radius: 5px;
color: white;
}
QListWidget::item:selected {
background-color: #4a90e2;
}
""")
def dragEnterEvent(self, event: QDragEnterEvent):
if event.mimeData().hasUrls():
event.acceptProposedAction()
def dropEvent(self, event: QDropEvent):
for url in event.mimeData().urls():
file_path = url.toLocalFile()
if file_path.lower().endswith(('.mp4', '.avi', '.mov', '.wmv')):
item = QListWidgetItem(os.path.basename(file_path))
item.setData(Qt.UserRole, file_path)
self.addItem(item)
class PreviewWindow(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setMinimumSize(640, 360)
self.video_frame = QLabel()
self.video_frame.setStyleSheet("background-color: black;")
layout = QVBoxLayout()
layout.addWidget(self.video_frame)
# Transport controls
controls_layout = QHBoxLayout()
self.play_button = QPushButton("Play")
self.stop_button = QPushButton("Stop")
self.prev_frame_button = QPushButton("<<")
self.next_frame_button = QPushButton(">>")
controls_layout.addWidget(self.prev_frame_button)
controls_layout.addWidget(self.play_button)
controls_layout.addWidget(self.stop_button)
controls_layout.addWidget(self.next_frame_button)
layout.addLayout(controls_layout)
self.setLayout(layout)
class EffectsPanel(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
layout = QVBoxLayout()
# Effects categories
categories = ["Video Effects", "Audio Effects", "Transitions"]
for category in categories:
label = QLabel(category)
label.setStyleSheet("color: white; font-weight: bold;")
layout.addWidget(label)
effects_list = QListWidget()
effects_list.setStyleSheet("""
QListWidget {
background-color: #2b2b2b;
border: none;
}
QListWidget::item {
color: white;
}
""")
# Add sample effects
if category == "Video Effects":
effects = ["Blur", "Color Correction", "Sharpen", "Vignette"]
elif category == "Audio Effects":
effects = ["EQ", "Compression", "Reverb", "Delay"]
else:
effects = ["Cross Dissolve", "Fade", "Wipe", "Slide"]
effects_list.addItems(effects)
layout.addWidget(effects_list)
self.setLayout(layout)
class VideoEditor(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("PyQt Video Editor")
self.setStyleSheet("""
QMainWindow {
background-color: #1e1e1e;
}
QMenuBar {
background-color: #2b2b2b;
color: white;
}
QMenuBar::item:selected {
background-color: #3b3b3b;
}
QPushButton {
background-color: #4a90e2;
color: white;
border: none;
padding: 5px 10px;
border-radius: 3px;
}
QPushButton:hover {
background-color: #357abd;
}
""")
# Create main widget and layout
main_widget = QWidget()
self.setCentralWidget(main_widget)
layout = QVBoxLayout(main_widget)
# Create menu bar
self.create_menu_bar()
# Create main splitter
main_splitter = QSplitter(Qt.Vertical)
# Upper section (preview and effects)
upper_splitter = QSplitter(Qt.Horizontal)
# Preview window
self.preview = PreviewWindow()
upper_splitter.addWidget(self.preview)
# Effects panel
self.effects_panel = EffectsPanel()
upper_splitter.addWidget(self.effects_panel)
upper_splitter.setStretchFactor(0, 2)
upper_splitter.setStretchFactor(1, 1)
main_splitter.addWidget(upper_splitter)
# Lower section (media browser and timeline)
lower_section = QWidget()
lower_layout = QVBoxLayout(lower_section)
# Media browser
self.media_browser = MediaBrowser()
lower_layout.addWidget(QLabel("Media Browser"))
lower_layout.addWidget(self.media_browser)
# Timeline
self.timeline = Timeline()
lower_layout.addWidget(QLabel("Timeline"))
lower_layout.addWidget(self.timeline)
main_splitter.addWidget(lower_section)
layout.addWidget(main_splitter)
# Set up status bar
self.statusBar().showMessage("Ready")
self.statusBar().setStyleSheet("color: white;")
# Window settings
self.setMinimumSize(1200, 800)
self.show()
def create_menu_bar(self):
menubar = self.menuBar()
# File menu
file_menu = menubar.addMenu("File")
new_project = QAction("New Project", self)
new_project.setShortcut("Ctrl+N")
file_menu.addAction(new_project)
open_project = QAction("Open Project", self)
open_project.setShortcut("Ctrl+O")
file_menu.addAction(open_project)
save_project = QAction("Save Project", self)
save_project.setShortcut("Ctrl+S")
file_menu.addAction(save_project)
file_menu.addSeparator()
import_media = QAction("Import Media", self)
import_media.setShortcut("Ctrl+I")
import_media.triggered.connect(self.import_media)
file_menu.addAction(import_media)
file_menu.addSeparator()
exit_action = QAction("Exit", self)
exit_action.setShortcut("Ctrl+Q")
exit_action.triggered.connect(self.close)
file_menu.addAction(exit_action)
# Edit menu
edit_menu = menubar.addMenu("Edit")
undo = QAction("Undo", self)
undo.setShortcut("Ctrl+Z")
edit_menu.addAction(undo)
redo = QAction("Redo", self)
redo.setShortcut("Ctrl+Y")
edit_menu.addAction(redo)
edit_menu.addSeparator()
cut = QAction("Cut", self)
cut.setShortcut("Ctrl+X")
edit_menu.addAction(cut)
copy = QAction("Copy", self)
copy.setShortcut("Ctrl+C")
edit_menu.addAction(copy)
paste = QAction("Paste", self)
paste.setShortcut("Ctrl+V")
edit_menu.addAction(paste)
def import_media(self):
files, _ = QFileDialog.getOpenFileNames(
self,
"Import Media",
"",
"Video Files (*.mp4 *.avi *.mov *.wmv);;All Files (*.*)"
)
for file_path in files:
item = QListWidgetItem(os.path.basename(file_path))
item.setData(Qt.UserRole, file_path)
self.media_browser.addItem(item)
def main():
app = QApplication(sys.argv)
# Set application-wide style
app.setStyle("Fusion")
# Set dark palette
palette = QPalette()
palette.setColor(QPalette.Window, QColor(53, 53, 53))
palette.setColor(QPalette.WindowText, Qt.white)
palette.setColor(QPalette.Base, QColor(25, 25, 25))
palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
palette.setColor(QPalette.ToolTipBase, Qt.white)
palette.setColor(QPalette.ToolTipText, Qt.white)
palette.setColor(QPalette.Text, Qt.white)
palette.setColor(QPalette.Button, QColor(53, 53, 53))
palette.setColor(QPalette.ButtonText, Qt.white)
palette.setColor(QPalette.BrightText, Qt.red)
palette.setColor(QPalette.Link, QColor(42, 130, 218))
palette.setColor(QPalette.Highlight, QColor(42, 130, 218))
palette.setColor(QPalette.HighlightedText, Qt.black)
app.setPalette(palette)
editor = VideoEditor()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
This implementation includes:
- Modern dark theme UI similar to Premiere Pro
- Media browser with drag-and-drop support
- Timeline with clips and playhead
- Preview window with transport controls
- Effects panel with categories
- Menu bar with common actions
- Status bar
- Proper layouts and splitters for resizable panels
Key features:
- Drag and drop media files into the media browser
- Drag clips from media browser to timeline
- Timeline with time markers and playhead
- Video preview window with basic transport controls
- Effects panel with categorized effects
- Modern dark theme with custom styling
- Professional-looking interface with proper spacing and organization
To make it fully functional, you would need to add:
- Video playback implementation
- Effect processing
- Timeline clip trimming
- Project save/load functionality
- Rendering capabilities
- Audio waveform display
- More advanced timeline features
The code is structured to make it easy to add these features. The basic infrastructure for a video editor is in place, and you can build upon this foundation to add more functionality.
To run this code, you'll need:
pip install PyQt5 opencv-python
This implementation provides a solid foundation for a video editor and can be extended with more features as needed.