Fix lazy audio path resolution for GPU streaming
Audio playback path was being resolved during parsing when database may not be ready, causing fallback to non-existent path. Now resolves lazily when stream starts, matching how audio analyzer works. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -65,11 +65,20 @@ class VideoSource:
|
||||
self._last_read_time = -1
|
||||
self._cached_frame = None
|
||||
|
||||
# Check if file exists
|
||||
if not self.path.exists():
|
||||
raise FileNotFoundError(f"Video file not found: {self.path}")
|
||||
|
||||
# Get video info
|
||||
cmd = ["ffprobe", "-v", "quiet", "-print_format", "json",
|
||||
"-show_streams", str(self.path)]
|
||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||
info = json.loads(result.stdout)
|
||||
if result.returncode != 0:
|
||||
raise RuntimeError(f"Failed to probe video '{self.path}': {result.stderr}")
|
||||
try:
|
||||
info = json.loads(result.stdout)
|
||||
except json.JSONDecodeError:
|
||||
raise RuntimeError(f"Invalid video file or ffprobe failed: {self.path}")
|
||||
|
||||
for stream in info.get("streams", []):
|
||||
if stream.get("codec_type") == "video":
|
||||
@@ -281,16 +290,27 @@ class AudioAnalyzer:
|
||||
self.path = Path(path)
|
||||
self.sample_rate = sample_rate
|
||||
|
||||
# Check if file exists
|
||||
if not self.path.exists():
|
||||
raise FileNotFoundError(f"Audio file not found: {self.path}")
|
||||
|
||||
# Load audio via ffmpeg
|
||||
cmd = ["ffmpeg", "-v", "quiet", "-i", str(self.path),
|
||||
cmd = ["ffmpeg", "-v", "error", "-i", str(self.path),
|
||||
"-f", "f32le", "-ac", "1", "-ar", str(sample_rate), "-"]
|
||||
result = subprocess.run(cmd, capture_output=True)
|
||||
if result.returncode != 0:
|
||||
raise RuntimeError(f"Failed to load audio '{self.path}': {result.stderr.decode()}")
|
||||
self._audio = np.frombuffer(result.stdout, dtype=np.float32)
|
||||
if len(self._audio) == 0:
|
||||
raise RuntimeError(f"Audio file is empty or invalid: {self.path}")
|
||||
|
||||
# Get duration
|
||||
cmd = ["ffprobe", "-v", "quiet", "-print_format", "json",
|
||||
"-show_format", str(self.path)]
|
||||
info = json.loads(subprocess.run(cmd, capture_output=True, text=True).stdout)
|
||||
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||
if result.returncode != 0:
|
||||
raise RuntimeError(f"Failed to probe audio '{self.path}': {result.stderr}")
|
||||
info = json.loads(result.stdout)
|
||||
self.duration = float(info.get("format", {}).get("duration", 60))
|
||||
|
||||
# Beat detection state
|
||||
|
||||
Reference in New Issue
Block a user