Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reader bug #310

Open
EnzoWuu opened this issue Jul 19, 2024 · 0 comments
Open

reader bug #310

EnzoWuu opened this issue Jul 19, 2024 · 0 comments

Comments

@EnzoWuu
Copy link

EnzoWuu commented Jul 19, 2024

There seems to be a bug in the videoreader module. When I use the following two pieces of code to read image content, the results are different. The only difference between the two code snippets is whether the frame image is read within an if statement.Can you help me understand what the issue is? Which code is correct?

from decord import VideoReader, cpu
import os
from PIL import Image
save_dir = 'data/'
video_path = 'test.asf'
vr = VideoReader(video_path, ctx=cpu(0))

# 获取视频的总帧数和帧率
total_frames = len(vr)
fps = vr.get_avg_fps()
frames_to_save_per_second = 1
# 保存帧
saved_frame_count = 0
for i in range(total_frames):
    # 判断是否需要保存当前帧
    print(frames_to_save_per_second, fps, total_frames)
    frame = vr[i].asnumpy()
    img = Image.fromarray(frame)
    if (i % int(fps // frames_to_save_per_second)) == 0:

        # 计算时间戳
        timestamp = i / fps
        timestamp_str = f"{timestamp:.5f}"  # 5位小数

        file_path = os.path.join(save_dir, f"{timestamp_str}.jpg")
        #log.debug(f"file_path: {file_path}")

        img.save(file_path)

        # timestamps_fact.append(timestamp_str)
        saved_frame_count += 1
from decord import VideoReader, cpu
import os
from PIL import Image
save_dir = 'data/'
video_path = 'test.asf'
vr = VideoReader(video_path, ctx=cpu(0))

# 获取视频的总帧数和帧率
total_frames = len(vr)
fps = vr.get_avg_fps()
frames_to_save_per_second = 1
# 保存帧
saved_frame_count = 0
for i in range(total_frames):
    # 判断是否需要保存当前帧
    print(frames_to_save_per_second, fps, total_frames)
    if (i % int(fps // frames_to_save_per_second)) == 0:
        frame = vr[i].asnumpy()
        img = Image.fromarray(frame)

        # 计算时间戳
        timestamp = i / fps
        timestamp_str = f"{timestamp:.5f}"  # 5位小数

        file_path = os.path.join(save_dir, f"{timestamp_str}.jpg")
        #log.debug(f"file_path: {file_path}")

        img.save(file_path)

        # timestamps_fact.append(timestamp_str)
        saved_frame_count += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant