The issue is likely that your subprocess is hanging or failing silently. Here are several potential causes and solutions:
1. Add timeout and better error handling:
import subprocess
import os
import logging
def extract_audio(video_path, timeout=300): # 5 minute timeout
audio_path = video_path.replace(".mp4", ".wav")
env = os.environ.copy()
env["OBJC_DISABLE_INITIALIZE_FORK_SAFETY"] = "YES"
try:
result = subprocess.run(
["ffmpeg", "-y", "-i", video_path, "-ar", "16000", "-ac", "1", audio_path],
env=env,
capture_output=True,
text=True,
check=True,
timeout=timeout
)
logging.info(f"FFmpeg completed successfully: {result.stderr}")
return audio_path
except subprocess.TimeoutExpired:
logging.error(f"FFmpeg timed out after {timeout} seconds")
raise
except subprocess.CalledProcessError as e:
logging.error(f"FFmpeg failed: {e.stderr}")
raise
except Exception as e:
logging.error(f"Unexpected error: {e}")
raise
2. Check if files exist and are accessible:
def extract_audio(video_path, timeout=300):
if not os.path.exists(video_path):
raise FileNotFoundError(f"Video file not found: {video_path}")
if not os.access(video_path, os.R_OK):
raise PermissionError(f"Cannot read video file: {video_path}")
audio_path = video_path.replace(".mp4", ".wav")
# Ensure output directory exists and is writable
output_dir = os.path.dirname(audio_path)
if not os.access(output_dir, os.W_OK):
raise PermissionError(f"Cannot write to directory: {output_dir}")
# ... rest of function
3. For queue jobs, consider using absolute paths:
def extract_audio(video_path, timeout=300):
# Convert to absolute paths
video_path = os.path.abspath(video_path)
audio_path = os.path.abspath(video_path.replace(".mp4", ".wav"))
# ... rest of function
4. Alternative approach using ffmpeg-python library:
import ffmpeg
def extract_audio(video_path):
audio_path = video_path.replace(".mp4", ".wav")
try:
(
ffmpeg
.input(video_path)
.output(audio_path, ar=16000, ac=1)
.overwrite_output()
.run(quiet=True, timeout=300)
)
return audio_path
except ffmpeg.Error as e:
logging.error(f"FFmpeg error: {e}")
raise
The most likely culprits are:
- FFmpeg hanging without a timeout
- Permission issues in the job queue environment
- Working directory differences in queue jobs
- Missing error output making debugging impossible
Start with adding the timeout and error capturing to see what's actually happening.