5
5
from pathlib import Path
6
6
from typing import TYPE_CHECKING , override
7
7
8
- import cv2
9
8
import structlog
10
- from PIL import Image
11
9
from PySide6 .QtCore import QBuffer , QByteArray , QSize , Qt
12
10
from PySide6 .QtGui import QAction , QMovie , QPixmap , QResizeEvent
13
11
from PySide6 .QtWidgets import QHBoxLayout , QLabel , QPushButton , QStackedLayout , QWidget
25
23
from tagstudio .qt .ts_qt import QtDriver
26
24
27
25
logger = structlog .get_logger (__name__ )
28
- Image .MAX_IMAGE_PIXELS = None
29
26
30
27
31
28
class PreviewThumbView (QWidget ):
@@ -234,13 +231,6 @@ def __render_thumb(self, filepath: Path) -> None:
234
231
update_on_ratio_change = True ,
235
232
)
236
233
237
- def __get_video_res (self , filepath : str ) -> tuple [bool , QSize ]:
238
- video = cv2 .VideoCapture (filepath , cv2 .CAP_FFMPEG )
239
- success , frame = video .read ()
240
- frame = cv2 .cvtColor (frame , cv2 .COLOR_BGR2RGB )
241
- image = Image .fromarray (frame )
242
- return (success , QSize (image .width , image .height ))
243
-
244
234
def __update_media_player (self , filepath : Path ) -> int :
245
235
"""Display either audio or video.
246
236
@@ -249,25 +239,21 @@ def __update_media_player(self, filepath: Path) -> int:
249
239
self .__media_player .play (filepath )
250
240
return self .__media_player .player .duration () * 1000
251
241
252
- def _display_video (self , filepath : Path ) -> FileAttributeData :
242
+ def _display_video (self , filepath : Path , size : QSize | None ) -> FileAttributeData :
253
243
self .__switch_preview (MediaType .VIDEO )
254
244
stats = FileAttributeData (duration = self .__update_media_player (filepath ))
255
245
256
- try :
257
- success , size = self .__get_video_res (str (filepath ))
258
- if success :
259
- stats .width = size .width ()
260
- stats .height = size .height ()
261
-
262
- self .__image_ratio = stats .width / stats .height
263
- self .resizeEvent (
264
- QResizeEvent (
265
- QSize (stats .width , stats .height ),
266
- QSize (stats .width , stats .height ),
267
- )
246
+ if size is not None :
247
+ stats .width = size .width ()
248
+ stats .height = size .height ()
249
+
250
+ self .__image_ratio = stats .width / stats .height
251
+ self .resizeEvent (
252
+ QResizeEvent (
253
+ QSize (stats .width , stats .height ),
254
+ QSize (stats .width , stats .height ),
268
255
)
269
- except cv2 .error as e :
270
- logger .error ("[PreviewThumb] Could not play video" , filepath = filepath , error = e )
256
+ )
271
257
272
258
return stats
273
259
0 commit comments