reader bug
- Dominant language
- C++
- Stars
- 2.5k
- Forks
- 232
- PR merge metrics
- No merged PRs in 30d
Description
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
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the two snippets with decord's VideoReader on the supplied test.asf input and compare the saved images and reported values. Start at the VideoReader frame-access path, then determine whether moving vr[i].asnumpy() inside the if statement changes the result; done means identifying a reproducible cause and documenting which behavior is correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- audio-video-rtc
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100