from videodb import IndexType# Create two indexes with different focuscar_index = video.index_scenes( prompt="Identify the color and model of each vehicle", name="vehicle_identification")motion_index = video.index_scenes( prompt="Describe the movement pattern - speeding, stopping, turning", name="motion_analysis")# Search each index separatelycar_results = video.search( query="red sedan", index_type=IndexType.scene, index_id=car_index)motion_results = video.search( query="driving recklessly", index_type=IndexType.scene, index_id=motion_index)
from videodb import SceneExtractionType# Environment indexenv_index = video.index_scenes( prompt="Describe the environment - indoor/outdoor, lighting, weather", name="environment")# People indexpeople_index = video.index_scenes( prompt="Describe the people - count, clothing, actions", name="people")# Object indexobject_index = video.index_scenes( prompt="List all visible objects and their positions", name="objects")
Find segments that match criteria in both indexes:
def get_intersection(results1, results2): """Find overlapping timestamps from two search results""" shots1 = [(s.start, s.end) for s in results1.get_shots()] shots2 = [(s.start, s.end) for s in results2.get_shots()] intersection = [] for s1 in shots1: for s2 in shots2: start = max(s1[0], s2[0]) end = min(s1[1], s2[1]) if start < end: intersection.append((start, end)) return intersection# Find "red sedan" that is "driving recklessly"car_results = video.search("red sedan", index_type=IndexType.scene, index_id=car_index)motion_results = video.search("reckless driving", index_type=IndexType.scene, index_id=motion_index)combined = get_intersection(car_results, motion_results)stream_url = video.generate_stream(combined)
Find segments that match criteria in either index:
def get_union(results1, results2): """Merge timestamps from two search results""" all_shots = [(s.start, s.end) for s in results1.get_shots()] all_shots += [(s.start, s.end) for s in results2.get_shots()] # Sort and merge overlapping intervals all_shots.sort() merged = [] for start, end in all_shots: if merged and start <= merged[-1][1]: merged[-1] = (merged[-1][0], max(merged[-1][1], end)) else: merged.append((start, end)) return merged# Find any scene with "red sedan" OR "motorcycle"car_results = video.search("red sedan", index_type=IndexType.scene, index_id=car_index)bike_results = video.search("motorcycle", index_type=IndexType.scene, index_id=car_index)combined = get_union(car_results, bike_results)
# Extract scenesscene_collection = video.extract_scenes( extraction_type=SceneExtractionType.time_based, extraction_config={"time": 10, "select_frames": ["middle"]})# Process with your own modelfor scene in scene_collection.scenes: for frame in scene.frames: # Call your custom vision model frame.description = your_model.describe(frame.url) # Aggregate frame descriptions into scene description scene.description = aggregate_descriptions(scene.frames)# Index the processed scenescustom_index = video.index_scenes( scenes=scene_collection.scenes, name="custom_model_index")