Compare commits

...

4 Commits

Author SHA1 Message Date
0ec8b77554 pve 2025-10-24 05:26:42 +02:00
b6196c1d46 pve, pygl 2025-10-21 13:18:23 +02:00
fff635f5c2 pve, pygl 2025-10-21 11:08:13 +02:00
be3b56856d pyui 2025-10-18 05:47:01 +02:00
15 changed files with 629 additions and 58 deletions

53
pve.py
View File

@ -1,53 +0,0 @@
# People's Video Editor: high quality, GPU accelerated mp4 editor
# Copyright (C) 2025 Roz K <roz@rozk.net>
#
# This file is part of People's Video Editor.
#
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with People's Video Editor.
# If not, see <https://www.gnu.org/licenses/>.
import multiprocessing
import cProfile
from pyav.demuxer import Demuxer
from pyav.decoder import Decoder
demuxer = Demuxer('test.mp4')
print(f"nb_streams = {demuxer.nb_streams}")
print(f"video codec = {demuxer.video_stream.codec.description()}")
print(f"audio codec = {demuxer.audio_stream.codec.description()}")
cpu_count = multiprocessing.cpu_count()
print(f"using {cpu_count} threads for video decoding")
video_decoder = Decoder(demuxer.video_stream, cpu_count)
audio_decoder = Decoder(demuxer.audio_stream, 1)
num_video_frames = 0
num_audio_frames = 0
with cProfile.Profile() as pr:
while True:
packet = demuxer.read_packet()
eof = (packet is None)
if eof or demuxer.video_stream.contains(packet):
video_frames = video_decoder.decode(packet)
num_video_frames += len(video_frames)
if eof or demuxer.audio_stream.contains(packet):
audio_frames = audio_decoder.decode(packet)
num_audio_frames += len(audio_frames)
if eof:
break
print(f"num video frames: {num_video_frames}, audio frames: {num_audio_frames}")
pr.print_stats()

15
pve/__init__.py Normal file
View File

@ -0,0 +1,15 @@
# People's Video Editor: high quality, GPU accelerated mp4 editor
# Copyright (C) 2025 Roz K <roz@rozk.net>
#
# This file is part of People's Video Editor.
#
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with People's Video Editor.
# If not, see <https://www.gnu.org/licenses/>.

100
pve/node.py Normal file
View File

@ -0,0 +1,100 @@
# People's Video Editor: high quality, GPU accelerated mp4 editor
# Copyright (C) 2025 Roz K <roz@rozk.net>
#
# This file is part of People's Video Editor.
#
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with People's Video Editor.
# If not, see <https://www.gnu.org/licenses/>.
from weakref import ref
class Node:
__slots__ = 'parent', 'children', 'state', '__weakref__'
STATE_NEW = 0
STATE_MODIFIED = 1
STATE_BUILT = 2
def __init__(self, parent = None, children = None):
self.parent = None
self.children = None
self.state = Node.STATE_NEW
if children is not None:
self.add_children(children)
if parent is not None:
parent.add_child(self)
def __del__(self):
if self.parent is not None:
self.parent().remove_child(self)
def add_child(self, child: Node):
assert child.parent is None
child.parent = ref(self)
if self.children is None:
self.children = [child]
else:
self.children.append(child)
child.state = Node.STATE_NEW
self.set_modified()
def add_children(self, children):
for child in children:
self.add_child(child)
def remove_child(self, child: Node):
assert child.parent is self
child.parent = None
self.children.remove(child)
self.set_modified()
def remove_children(self, children):
for child in children:
self.remove_child(child)
def is_new(self):
return self.state == Node.STATE_NEW
def needs_rebuilding(self):
return self.state != Node.STATE_BUILT
def set_modified(self):
if self.needs_rebuilding():
return
self.state = Node.STATE_MODIFIED
if self.parent is not None:
self.set_parent_modified(self.parent())
def set_parent_modified(self, parent):
parent.set_modified()
def rebuild(self):
if not self.needs_rebuilding():
return True
if self.children is not None:
if not self.rebuild_children(self.children):
return False
if not self.build():
return False
self.state = Node.STATE_BUILT
return True
def rebuild_children(self, children):
for child in children:
if not self.rebuild_child(child):
return False
return True
def rebuild_child(self, child):
return child.rebuild()
def build(self):
return True

131
pve/pixmap.py Normal file
View File

@ -0,0 +1,131 @@
# People's Video Editor: high quality, GPU accelerated mp4 editor
# Copyright (C) 2025 Roz K <roz@rozk.net>
#
# This file is part of People's Video Editor.
#
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with People's Video Editor.
# If not, see <https://www.gnu.org/licenses/>.
from fractions import Fraction
class Geometry:
__slots__ = '_width', '_height', '_ratio', '_size'
def __init__(self, width = 0, height = 0, ratio = None):
if width > 0 and height > 0:
assert ratio is None
self._width = width
self._height = height
self._ratio = Fraction(width, height).limit_denominator()
self._size = width * height
elif width > 0 and ratio:
self._width = width
self._height = round((width * ratio.numerator) / ratio.denominator)
self._ratio = ratio
self._size = width * self._height
elif height > 0 and ratio:
self._width = round((height * ratio.denominator) / ratio.numerator)
self._height = height
self._ratio = ratio
self._size = self._width * height
else:
raise ValueError
def __ge__(self, other):
return (self._width >= other._width and self._height >= other._height)
@property
def width(self):
return self._width
@property
def height(self):
return self._height
@property
def ratio(self):
return self._ratio
class Format:
__slots__ = '_channels', '_depth', '_type', '_size'
def __init__(self, channels, depth):
self._channels = channels
self._depth = depth
if depth == 8:
self._type = 'B'
self._size = channels
elif depth == 16:
self._type = 'H'
self._size = channels * 2
else:
raise ValueError
def __eq__(self, other):
return (self._channels == other._channels and self._depth == other._depth)
@property
def channels(self):
return self._channels
@property
def depth(self):
return self._depth
class Pixmap:
__slots__ = '_geometry', '_format', '_line_size', '_bytes', '_view'
def __init__(self, geometry, format):
self._geometry = geometry
self._format = format
self._line_size = geometry._width * format._size
self._bytes = bytearray(geometry._size * format._size)
self._view = memoryview(self._bytes)
def __del__(self):
del self._view
del self._bytes
@property
def geometry(self):
return self._geometry
@property
def width(self):
return self._geometry._width
@property
def height(self):
return self._geometry._height
@property
def ratio(self):
return self._geometry._ratio
@property
def format(self):
return self._format
@property
def channels(self):
return self._format._channels
@property
def depth(self):
return self._format._depth
@property
def line_size(self):
return self._line_size
@property
def view(self):
return self._view

107
pve/polygon.py Normal file
View File

@ -0,0 +1,107 @@
# People's Video Editor: high quality, GPU accelerated mp4 editor
# Copyright (C) 2025 Roz K <roz@rozk.net>
#
# This file is part of People's Video Editor.
#
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with People's Video Editor.
# If not, see <https://www.gnu.org/licenses/>.
from array import array
from .node import Node
from .vector import Vector2
class Point:
__slots__ = 'position', 'mapping'
def __init__(self, xy = Vector2(), uv = Vector2()):
assert isinstance(xy, Vector2) and isinstance(uv, Vector2)
self.position = xy
self.mapping = uv
class Polygon(Node):
__slots__ = '_positions', '_mappings', '_len'
@classmethod
def rectangle(cls, geometry):
tl = Vector2(0.0, 0.0)
tr = Vector2(geometry._width, 0.0)
br = Vector2(geometry._width, geometry._height)
bl = Vector2(0.0, geometry._height)
return cls(points = (
Point(tl, tl),
Point(tr, tr),
Point(br, br),
Point(bl, bl)))
def __init__(self, parent = None, children = None, size = 0, points = None):
Node.__init__(self, parent, children)
self.clear_points()
self.add_points(size, points)
def __len__(self):
return self._len
def __getitem__(self, index):
begin = index * 2
end = begin + 2
return Point(
Vector2(*self._positions[begin:end]),
Vector2(*self._mappings[begin:end]))
def __setitem__(self, index, point):
begin = index * 2
end = begin + 2
self._positions[begin:end] = array(Vector2.TYPE, point.position)
self._mappings[begin:end] = array(Vector2.TYPE, point.mapping)
def add_child(self, child):
assert isinstance(child, Polygon)
Node.add_child(self, child)
def add_points(self, count = 0, points = None):
assert (count > 0) ^ len(points)
if count:
initializer = bytes(count * Vector2.SIZE)
self._positions.frombytes(initializer)
self._mappings.frombytes(initializer)
self._len += count
else:
for point in points:
self._positions.extend(point.position)
self._mappings.extend(point.mapping)
self._len += len(points)
def insert_points(self, index, count = 0, points = None):
assert (count == 0) ^ (points is None)
index *= 2
if count:
initializer = array(Vector2.TYPE, bytes(count * Vector2.SIZE))
self._positions[index:index] = initializer
self._mappings[index:index] = initializer
self._len += count
else:
polygon = Polygon(points = points)
self._positions[index:index] = polygon._positions
self._mappings[index:index] = polygon._mappings
self._len += polygon._len
def remove_points(self, index, count = 1):
begin = index * 2
end = begin + count * 2
del self._positions[begin:end]
del self._mappings[begin:end]
self._len -= count
def clear_points(self):
self._positions = array(Vector2.TYPE)
self._mappings = array(Vector2.TYPE)
self._len = 0

26
pve/shape.py Normal file
View File

@ -0,0 +1,26 @@
# People's Video Editor: high quality, GPU accelerated mp4 editor
# Copyright (C) 2025 Roz K <roz@rozk.net>
#
# This file is part of People's Video Editor.
#
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with People's Video Editor.
# If not, see <https://www.gnu.org/licenses/>.
from .node import Node
class Shape(Node):
def __init__(self, parent = None, children = None):
Node.__init__(self, parent, children)
def rebuild(self):
#TODO
raise NotImplementedError

29
pve/vector.py Normal file
View File

@ -0,0 +1,29 @@
# People's Video Editor: high quality, GPU accelerated mp4 editor
# Copyright (C) 2025 Roz K <roz@rozk.net>
#
# This file is part of People's Video Editor.
#
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with People's Video Editor.
# If not, see <https://www.gnu.org/licenses/>.
class Vector2:
__slots__ = 'x', 'y'
TYPE = 'f'
SIZE = 8
def __init__(self, x = 0.0, y = 0.0):
assert isinstance(x, float) and isinstance(y, float)
self.x = x
self.y = y
def __iter__(self):
return iter((self.x, self.y))

58
pve_editor.py Normal file
View File

@ -0,0 +1,58 @@
# People's Video Editor: high quality, GPU accelerated mp4 editor
# Copyright (C) 2025 Roz K <roz@rozk.net>
#
# This file is part of People's Video Editor.
#
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with People's Video Editor.
# If not, see <https://www.gnu.org/licenses/>.
from pyui.application import Application
application = Application()
application.MainLoop()
# import multiprocessing
# import cProfile
#
# from pyav.demuxer import Demuxer
# from pyav.decoder import Decoder
#
# demuxer = Demuxer('test.mp4')
#
# print(f"nb_streams = {demuxer.nb_streams}")
# print(f"video codec = {demuxer.video_stream.codec.description()}")
# print(f"audio codec = {demuxer.audio_stream.codec.description()}")
#
# cpu_count = multiprocessing.cpu_count()
#
# print(f"using {cpu_count} threads for video decoding")
#
# video_decoder = Decoder(demuxer.video_stream, cpu_count)
# audio_decoder = Decoder(demuxer.audio_stream, 1)
#
# num_video_frames = 0
# num_audio_frames = 0
#
# with cProfile.Profile() as pr:
# while True:
# packet = demuxer.read_packet()
# eof = (packet is None)
# if eof or demuxer.video_stream.contains(packet):
# video_frames = video_decoder.decode(packet)
# num_video_frames += len(video_frames)
# if eof or demuxer.audio_stream.contains(packet):
# audio_frames = audio_decoder.decode(packet)
# num_audio_frames += len(audio_frames)
# if eof:
# break
#
# print(f"num video frames: {num_video_frames}, audio frames: {num_audio_frames}")
# pr.print_stats()

View File

@ -19,4 +19,4 @@ shared_library_path="./pyav/libav"
absolute_shared_library_path=$(realpath ${shared_library_path}) absolute_shared_library_path=$(realpath ${shared_library_path})
LD_LIBRARY_PATH=${absolute_shared_library_path} \ LD_LIBRARY_PATH=${absolute_shared_library_path} \
python3 pve.py python3 pve_editor.py

15
pygl/__init__.py Normal file
View File

@ -0,0 +1,15 @@
# People's Video Editor: high quality, GPU accelerated mp4 editor
# Copyright (C) 2025 Roz K <roz@rozk.net>
#
# This file is part of People's Video Editor.
#
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with People's Video Editor.
# If not, see <https://www.gnu.org/licenses/>.

41
pygl/libgl/__init__.py Normal file
View File

@ -0,0 +1,41 @@
# People's Video Editor: high quality, GPU accelerated mp4 editor
# Copyright (C) 2025 Roz K <roz@rozk.net>
#
# This file is part of People's Video Editor.
#
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with People's Video Editor.
# If not, see <https://www.gnu.org/licenses/>.
import ctypes
Texture_p = ctypes.c_void_p
VertexBuffer_p = ctypes.c_void_p
def create_texture(width, height, channels, depth):
return None
def delete_texture(texture):
pass
def upload_texture(texture, view, line_size):
pass
def dowload_texture(texture, view, line_size):
pass
def create_vertex_buffer(size, channels, elems):
return None
def delete_vertex_buffer(buffer):
pass
def upload_vertex_buffer(buffer, views, size):
pass

66
pygl/texture.py Normal file
View File

@ -0,0 +1,66 @@
# People's Video Editor: high quality, GPU accelerated mp4 editor
# Copyright (C) 2025 Roz K <roz@rozk.net>
#
# This file is part of People's Video Editor.
#
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with People's Video Editor.
# If not, see <https://www.gnu.org/licenses/>.
from . import libgl
class Texture:
__slots__ = '_geometry', '_format', '_texture'
def __init__(self, geometry, format):
self._geometry = geometry
self._format = format
self._texture = libgl.create_texture(geometry.width, geometry.height, format.channels, format.depth)
def __del__(self):
libgl.delete_texture(self._texture)
@property
def geometry(self):
return self._geometry
@property
def width(self):
return self._geometry._width
@property
def height(self):
return self._geometry._height
@property
def ratio(self):
return self._geometry._ratio
@property
def format(self):
return self._format
@property
def channels(self):
return self._format._channels
@property
def depth(self):
return self._format._depth
def upload(self, pixmap):
assert (self._format == pixmap.format)
assert (self._geometry >= pixmap.geometry)
return libgl.upload_texture(self._texture, pixmap.view, pixmap.line_size)
def download(self, pixmap):
assert (self._format == pixmap.format)
assert (self._geometry >= pixmap.geometry)
return libgl.upload_texture(self._texture, pixmap.view, pixmap.line_size)

35
pygl/vertexbuffer.py Normal file
View File

@ -0,0 +1,35 @@
# People's Video Editor: high quality, GPU accelerated mp4 editor
# Copyright (C) 2025 Roz K <roz@rozk.net>
#
# This file is part of People's Video Editor.
#
# People's Video Editor is free software: you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# People's Video Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with People's Video Editor.
# If not, see <https://www.gnu.org/licenses/>.
from . import libgl
class VertexBuffer:
__slots__ = '_buffer', '_size'
def __init__(self, size, channels, elems):
self._buffer = libgl.create_vertex_buffer(size, channels, elems)
self._size = size
def __del__(self):
libgl.delete_vertex_buffer(self._buffer)
@property
def size(self):
return self._size
def upload(self, mesh):
assert (self._size >= mesh.size)
return libgl.upload_vertex_buffer(self._buffer, mesh.views, mesh.size)

View File

@ -17,15 +17,14 @@
from . import preview_generated from . import preview_generated
class PreviewPanel(preview_generated.PreviewPanel): class PreviewPanel(preview_generated.PreviewPanel):
__slots__ = 'canvas', 'context' __slots__ = 'video_canvas'
def __init__(self, parent, id, pos, size, style): def __init__(self, parent, id, pos, size, style):
preview_generated.PreviewPanel.__init__(self, parent, id = id, pos = pos, size = size, style = style) preview_generated.PreviewPanel.__init__(self, parent, id = id, pos = pos, size = size, style = style)
self.canvas = self._video_canvas self.video_canvas = self._video_canvas
self.context = self._video_canvas.context
def initdialog_event_handler(self, event): def initdialog_event_handler(self, event):
self.canvas.SetCurrent(self.context) self.video_canvas.SetCurrent(self.video_canvas.context)
def size_event_handler(self, event): def size_event_handler(self, event):
pass pass

View File

@ -25,3 +25,5 @@ class VideoCanvas(wx.glcanvas.GLCanvas):
wx.glcanvas.GLAttributes().PlatformDefaults().RGBA().FrameBuffersRGB().DoubleBuffer().EndList()) wx.glcanvas.GLAttributes().PlatformDefaults().RGBA().FrameBuffersRGB().DoubleBuffer().EndList())
self.context = wx.glcanvas.GLContext(self, ctxAttrs = self.context = wx.glcanvas.GLContext(self, ctxAttrs =
wx.glcanvas.GLContextAttrs().CoreProfile().OGLVersion(4,6).EndList()) wx.glcanvas.GLContextAttrs().CoreProfile().OGLVersion(4,6).EndList())
if not self.context.IsOK()):
raise RuntimeError("Failed to create GL Context")