-
Notifications
You must be signed in to change notification settings - Fork 0
Troubleshooting
SpyC0der77 edited this page Nov 23, 2024
·
1 revision
This guide helps you diagnose and fix common issues when using VidKit.
ERROR: Could not find a version that satisfies the requirement vidkit
Solutions:
-
Update pip:
python -m pip install --upgrade pip
-
Check Python version compatibility:
python --version
- VidKit requires Python 3.6 or higher
-
Install from source:
git clone https://github.com/SpyC0der77/vidkit.git cd vidkit pip install -e .
Symptoms:
- MemoryError when processing large videos
- System becomes unresponsive
Solutions:
-
Reduce image resolution:
from PIL import Image def resize_image(image_path, max_size): with Image.open(image_path) as img: # Calculate new size maintaining aspect ratio ratio = min(max_size/max(img.size)) new_size = tuple([int(x*ratio) for x in img.size]) return img.resize(new_size, Image.LANCZOS)
-
Process in batches:
def process_in_batches(frames, batch_size=10): for i in range(0, len(frames), batch_size): batch = frames[i:i+batch_size] # Process batch
Symptoms:
- Audio and video out of sync
- Audio cuts off early
Solutions:
- Match total frame duration to audio:
from moviepy.editor import AudioFileClip def get_audio_duration(audio_path): audio = AudioFileClip(audio_path) duration = audio.duration audio.close() return duration def adjust_frame_durations(config): if "audio" in config: audio_duration = get_audio_duration(config["audio"]) total_duration = sum(frame["duration"] for frame in config["frames"]) if total_duration != audio_duration: ratio = audio_duration / total_duration for frame in config["frames"]: frame["duration"] *= ratio
Symptoms:
- "Unsupported image format" errors
- Black frames in output
Solutions:
- Convert images to supported format:
from PIL import Image def ensure_compatible_format(image_path): with Image.open(image_path) as img: if img.format not in ['JPEG', 'PNG']: new_path = image_path.rsplit('.', 1)[0] + '.jpg' img.convert('RGB').save(new_path, 'JPEG') return new_path return image_path
Symptoms:
- Output video won't play
- Codec errors
Solutions:
- Check codec compatibility:
from moviepy.editor import VideoFileClip def verify_output(video_path): try: clip = VideoFileClip(video_path) clip.close() return True except Exception as e: print(f"Video verification failed: {e}") return False
Symptoms:
- Video generation takes too long
- High CPU usage
Solutions:
-
Profile the code:
import cProfile import pstats def profile_generation(config): profiler = cProfile.Profile() profiler.enable() video_bytes = renderVideo(config) profiler.disable() stats = pstats.Stats(profiler).sort_stats('cumulative') stats.print_stats()
-
Optimize image sizes:
def optimize_images(config): for frame in config["frames"]: with Image.open(frame["image"]) as img: if img.size > config["resolution"]: # Resize if larger than needed resize_image(frame["image"], config["resolution"])
Symptoms:
- ValueError with configuration errors
- Unexpected video output
Solutions:
- Validate configuration:
def validate_config(config): required = ["name", "format", "framerate", "resolution", "frames"] # Check required fields missing = [f for f in required if f not in config] if missing: raise ValueError(f"Missing required fields: {missing}") # Validate resolution if not isinstance(config["resolution"], list) or len(config["resolution"]) != 2: raise ValueError("Resolution must be [width, height]") # Validate framerate if not isinstance(config["framerate"], (int, float)) or config["framerate"] <= 0: raise ValueError("Framerate must be positive number")
import logging
def enable_debug():
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
def system_check():
import psutil
import platform
print(f"Python Version: {platform.python_version()}")
print(f"Available Memory: {psutil.virtual_memory().available / (1024*1024*1024):.2f} GB")
print(f"CPU Cores: {psutil.cpu_count()}")
If you're still experiencing issues:
- Check the GitHub Issues for similar problems
- Include the following when reporting issues:
- VidKit version
- Python version
- Complete error traceback
- Minimal configuration that reproduces the issue
- Use the GitHub Discussions for general questions
- Error Handling for detailed error handling strategies
- Configuration Reference for proper configuration
- API Reference for function specifications