Revert "feat: replace Decord with video_reader-rs" (#8077)

This commit is contained in:
Mick
2025-07-16 11:04:56 +08:00
committed by GitHub
parent 69f453e5a4
commit 497efe747d
6 changed files with 21 additions and 16 deletions

View File

@@ -84,7 +84,6 @@ from torch.library import Library
from torch.profiler import ProfilerActivity, profile, record_function
from torch.utils._contextlib import _DecoratorContextManager
from triton.runtime.cache import FileCacheManager
from video_reader import PyVideoReader
logger = logging.getLogger(__name__)
@@ -758,9 +757,16 @@ def load_image(
def load_video(video_file: Union[str, bytes], use_gpu: bool = True):
# We import decord here to avoid a strange Segmentation fault (core dumped) issue.
from video_reader import PyVideoReader
from decord import VideoReader, cpu, gpu
try:
from decord.bridge import decord_bridge
ctx = gpu(0)
_ = decord_bridge.get_ctx_device(ctx)
except Exception:
ctx = cpu(0)
device = "cuda" if use_gpu and torch.cuda.is_available() else None
tmp_file = None
vr = None
try:
@@ -768,7 +774,7 @@ def load_video(video_file: Union[str, bytes], use_gpu: bool = True):
tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
tmp_file.write(video_file)
tmp_file.close()
vr = PyVideoReader(tmp_file.name, device=device, threads=0)
vr = VideoReader(tmp_file.name, ctx=ctx)
elif isinstance(video_file, str):
if video_file.startswith(("http://", "https://")):
timeout = int(os.getenv("REQUEST_TIMEOUT", "10"))
@@ -778,22 +784,22 @@ def load_video(video_file: Union[str, bytes], use_gpu: bool = True):
for chunk in response.iter_content(chunk_size=8192):
tmp_file.write(chunk)
tmp_file.close()
vr = PyVideoReader(tmp_file.name, device=device, threads=0)
vr = VideoReader(tmp_file.name, ctx=ctx)
elif video_file.startswith("data:"):
_, encoded = video_file.split(",", 1)
video_bytes = base64.b64decode(encoded)
tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
tmp_file.write(video_bytes)
tmp_file.close()
vr = PyVideoReader(tmp_file.name, device=device, threads=0)
vr = VideoReader(tmp_file.name, ctx=ctx)
elif os.path.isfile(video_file):
vr = PyVideoReader(video_file, device=device, threads=0)
vr = VideoReader(video_file, ctx=ctx)
else:
video_bytes = base64.b64decode(video_file)
tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
tmp_file.write(video_bytes)
tmp_file.close()
vr = PyVideoReader(tmp_file.name, device=device, threads=0)
vr = VideoReader(tmp_file.name, ctx=ctx)
else:
raise ValueError(f"Unsupported video input type: {type(video_file)}")