Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ dependencies = [
"python-dotenv>=1.1.1",
"ruff>=0.9.7",
"timm>=1.0.22",
"torch>=2.8.0",
"torchaudio>=2.8.0",
"torch>=2.9.1",
"torchaudio>=2.9.1",
"torchcodec>=0.9.1",
"torchvision>=0.23.0",
"torchvision>=0.24.1",
"transformers>=4.57.3",
"wandb>=0.22.2",
]
Expand Down
24 changes: 22 additions & 2 deletions src/syncnet/datasets/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pathlib import Path

from torch.utils.data import Dataset
from torchvision.io import read_video
from torchcodec.decoders import AudioDecoder, VideoDecoder

os.environ["TOKENIZERS_PARALLELISM"] = "false"

Expand Down Expand Up @@ -80,5 +80,25 @@ def __getitem__(self, idx: int) -> tuple:
IndexError: If idx is out of bounds.
RuntimeError: If the video file cannot be read or is corrupted.
"""
video, audio, metadata = read_video(str(self.sample_paths[idx]), pts_unit="sec")
video_path = str(self.sample_paths[idx])

# Load video frames
video_decoder = VideoDecoder(video_path)
frame_batch = video_decoder.get_frames_in_range(
0, video_decoder.metadata.num_frames
)
# Convert from (T, C, H, W) to (T, H, W, C) to match torchvision format
video = frame_batch.data.permute(0, 2, 3, 1)

# Load audio from the same video file
audio_decoder = AudioDecoder(video_path)
audio_samples = audio_decoder.get_all_samples()
audio = audio_samples.data # Shape: (C, N), already normalized to [-1, 1]

# Build metadata dict to match torchvision format
metadata = {
"video_fps": video_decoder.metadata.average_fps,
"audio_fps": audio_samples.sample_rate,
}

return video, audio, metadata
Loading