Skip to content

Open-Sora: Democratizing Efficient Video Production for All

Python

Merge branch 'dev/v1.0.1' of https://github.com/hpcaitech/Open-Sora-dev into dev/v1.0.1

Zangwei Zhengbd6a3e46e432
diff --cc tools/datasets/csvutil.py
index d1ad6da,45fe550..1bd0a19
--- a/tools/datasets/csvutil.py
+++ b/tools/datasets/csvutil.py
@@@ -34,59 -40,32 +34,62 @@@ IMG_EXTENSIONS =
)
-def get_video_info(path):
+def apply(df, func, **kwargs):
+ if pandas_has_parallel:
+ return df.parallel_apply(func, **kwargs)
+ return df.progress_apply(func, **kwargs)
+
+
+# ======================================================
+# --info
+# ======================================================
+
+
+def get_info(path):
import cv2
- ext = os.path.splitext(path)[1].lower()
- if ext in IMG_EXTENSIONS:
- im = cv2.imread(path)
- if im is None:
- return 0, 0, 0, np.nan, np.nan
- height, width = im.shape[:2]
- num_frames, fps = 1, np.nan
- else:
- cap = cv2.VideoCapture(path)
- num_frames, height, width, fps = (
- int(cap.get(cv2.CAP_PROP_FRAME_COUNT)),
- int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)),
- int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
- float(cap.get(cv2.CAP_PROP_FPS)),
- )
- hw = height * width
- aspect_ratio = height / width if width > 0 else np.nan
- return num_frames, height, width, aspect_ratio, fps, hw
+ try:
+ ext = os.path.splitext(path)[1].lower()
+ if ext in IMG_EXTENSIONS:
+ im = cv2.imread(path)
+ if im is None:
+ return 0, 0, 0, np.nan, np.nan
+ height, width = im.shape[:2]
+ num_frames, fps = 1, np.nan
+ else:
+ cap = cv2.VideoCapture(path)
+ num_frames, height, width, fps = (
+ int(cap.get(cv2.CAP_PROP_FRAME_COUNT)),
+ int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)),
+ int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
+ float(cap.get(cv2.CAP_PROP_FPS)),
+ )
+ hw = height * width
+ aspect_ratio = height / width if width > 0 else np.nan
+ return num_frames, height, width, aspect_ratio, fps, hw
+ except:
+ return 0, 0, 0, np.nan, np.nan, np.nan
+# ======================================================
+# --remove-corrupted
+# ======================================================
+
+
+def is_video_valid(path):
+ import decord
+
+ try:
+ decord.VideoReader(path, num_threads=1)
+ return True
+ except:
+ return False
+
+
+# ======================================================
+# --refine-llm-caption
+# ======================================================
+
LLAVA_PREFIX = [
"The video shows",
"The video captures",