Skip to content

Open-Sora: Democratizing Efficient Video Production for All

Python

[fix] correct video info

zhengzangwd71ae85467ae
diff --git a/opensora/datasets/datasets.py b/opensora/datasets/datasets.py
index 43ee214..a8e48f8 100644
--- a/opensora/datasets/datasets.py
+++ b/opensora/datasets/datasets.py
@@ -4,13 +4,15 @@ from glob import glob
import numpy as np
import torch
import torchvision
+from PIL import ImageFile
from torchvision.datasets.folder import IMG_EXTENSIONS, pil_loader
from opensora.registry import DATASETS
-from .utils import VID_EXTENSIONS, get_transforms_image, get_transforms_video, read_file, temporal_random_crop
from .read_video import read_video
+from .utils import VID_EXTENSIONS, get_transforms_image, get_transforms_video, read_file, temporal_random_crop
+ImageFile.LOAD_TRUNCATED_IMAGES = True
IMG_FPS = 120
@@ -68,8 +70,8 @@ class VideoTextDataset(torch.utils.data.Dataset):
if file_type == "video":
# loading
- vframes, vinfo = read_video(path, backend='av')
- video_fps = vinfo["video_fps"] if 'video_fps' in vinfo else 24
+ vframes, vinfo = read_video(path, backend="av")
+ video_fps = vinfo["video_fps"] if "video_fps" in vinfo else 24
# Sampling video frames
video = temporal_random_crop(vframes, self.num_frames, self.frame_interval)
@@ -145,8 +147,8 @@ class VariableVideoTextDataset(VideoTextDataset):
video_fps = 24 # default fps
if file_type == "video":
# loading
- vframes, vinfo = read_video(path, backend='av')
- video_fps = vinfo["video_fps"] if 'video_fps' in vinfo else 24
+ vframes, vinfo = read_video(path, backend="av")
+ video_fps = vinfo["video_fps"] if "video_fps" in vinfo else 24
# Sampling video frames
video = temporal_random_crop(vframes, num_frames, self.frame_interval)
diff --git a/tools/datasets/datautil.py b/tools/datasets/datautil.py
index a889a35..9674f00 100644
--- a/tools/datasets/datautil.py
+++ b/tools/datasets/datautil.py
@@ -117,8 +117,7 @@ def get_image_info(path, backend="pillow"):
def get_video_info(path, backend="torchvision"):
if backend == "torchvision":
try:
- # vframes, infos = read_video(path)
- vframes, _, infos = torchvision.io.read_video(filename=path, pts_unit="sec", output_format="THWC")
+ vframes, infos = read_video(path)
num_frames, height, width = vframes.shape[0], vframes.shape[2], vframes.shape[3]
if "video_fps" in infos:
fps = infos["video_fps"]