From 4d844df3723cce0a9e461f63889d659ab066d2c5 Mon Sep 17 00:00:00 2001 From: Zhou Yingjie <87629216+zyj-2000@users.noreply.github.com> Date: Tue, 12 Mar 2024 15:58:24 +0800 Subject: [PATCH 1/2] Add files via upload --- q_align/__init__.py | 3 ++- q_align/load_video.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 q_align/load_video.py diff --git a/q_align/__init__.py b/q_align/__init__.py index 77f0e50..f91a4a6 100644 --- a/q_align/__init__.py +++ b/q_align/__init__.py @@ -1,2 +1,3 @@ from .model import MPLUGOwl2LlamaForCausalLM -from .evaluate import QAlignScorer, QAlignAestheticScorer, QAlignVideoScorer \ No newline at end of file +from .evaluate import QAlignScorer, QAlignAestheticScorer, QAlignVideoScorer +from .load_video import load_video \ No newline at end of file diff --git a/q_align/load_video.py b/q_align/load_video.py new file mode 100644 index 0000000..694ba79 --- /dev/null +++ b/q_align/load_video.py @@ -0,0 +1,13 @@ +from PIL import Image + +def load_video(video_file): + from decord import VideoReader + vr = VideoReader(video_file) + + # Get video frame rate + fps = vr.get_avg_fps() + + # Calculate frame indices for 1fps + frame_indices = [int(fps * i) for i in range(int(len(vr) / fps))] + frames = vr.get_batch(frame_indices).asnumpy() + return [Image.fromarray(frames[i]) for i in range(int(len(vr) / fps))] \ No newline at end of file From 5e1a80ef001089df0966c75cbc672e2464bbc77b Mon Sep 17 00:00:00 2001 From: Zhou Yingjie <87629216+zyj-2000@users.noreply.github.com> Date: Tue, 12 Mar 2024 15:59:57 +0800 Subject: [PATCH 2/2] Add files via upload fix the missing function: load_video