Skip to content

Commit

Permalink
version 1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaokang2022 committed Sep 16, 2024
1 parent 82f8cda commit e44685c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ Changelog / 更新日志
> * 🟠 **Deprecated / 弃用**
> * 🟤 **Refactored / 重构**
🔖 `1.0.6`
-----------

🕓 *Release Date / 发布日期 : 2024-09-16*

🟣 **Fixed / 修复**

- Fixed a bug where the video playback speed was abnormal
修复了视频播放速度异常的 bug

🔴 **Removed / 移除**

- Removed the `interval` parameter for `VideoCanvas`
移除了 `VideoCanvas``interval` 参数

🔖 `1.0.5`
-----------

Expand Down
2 changes: 1 addition & 1 deletion tkintertools/media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@

from .main import *

__version__ = "1.0.5"
__version__ = "1.0.6"
__author__ = "Xiaokang2022 <2951256653@qq.com>"
16 changes: 10 additions & 6 deletions tkintertools/media/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""APIs for playing videos"""

import time
import typing

import ffpyplayer.player
Expand All @@ -24,7 +25,6 @@ def __init__(
| tkintertools.core.containers.Canvas",
*,
control: bool = False,
interval: int = 10,
auto_play: bool = False,
click_pause: bool = True,
expand: typing.Literal["", "x", "y", "xy"] = "xy",
Expand All @@ -37,9 +37,6 @@ def __init__(
"""
* `master`: parent widget
* `control`: whether to enable the built-in UI
* `interval`: time interval(ms) at which frame information is queried,
the minimum requirement is 1, and too small may cause the window to lag
when dragging it
* `auto_play`: whether to start playing the video automatically
* `click_pause`: whether to pause when clicked
* `expand`: the mode of expand, `x` is horizontal, and `y` is vertical
Expand All @@ -52,7 +49,6 @@ def __init__(
tkintertools.core.containers.Canvas.__init__(
self, master, expand=expand, zoom_item=zoom_item,
keep_ratio=keep_ratio, free_anchor=free_anchor, name=name, **kwargs)
self.interval = interval
self._control = control
self._auto_play = auto_play
self._video = self.create_image(0, 0, anchor="nw")
Expand All @@ -78,6 +74,7 @@ def _re_place(self) -> None:

def _refresh(self) -> None:
"""Refresh the canvas"""
start = time.time()
frame, val = self.media.get_frame()
if val != 'eof' and frame is not None:
img, pts = frame
Expand All @@ -89,10 +86,17 @@ def _refresh(self) -> None:
self.p.set(pts / self.metadata["duration"])
self.t.set("%s / %s" % (self._tiem_convert(pts),
self._tiem_convert(self.metadata["duration"])))
fps = self.metadata["frame_rate"][0]/self.metadata["frame_rate"][1]
interval = round(1000/fps - (time.time()-start) * 1000)
elif val == 'eof' and self._control:
self.media.set_pause(True)
self.p.set(1)
self.schedule = self.after(self.interval, self._refresh)
interval = 0
else:
interval = 0
if interval <= 0:
interval = 1
self.schedule = self.after(interval, self._refresh)

def _tiem_convert(self, t: float) -> str:
"""Convert seconds to a special format"""
Expand Down

0 comments on commit e44685c

Please sign in to comment.