Skip to main content

Searching through video data by asking the right questions

Project description

VideoQL

codecov CI GitHub License PyPI - Version PyPI - Downloads

Searching through video data by asking the right questions.

Install it from PyPI

pip install video_ql

Usage

video_ql provides both a Python API and a CLI interface for video analysis and querying.

Python API

from video_ql import VideoQL
from video_ql.models import Query, QueryCondition, OrCondition, QueryConfig

# Define your queries
queries = [
    Query(
        query="Is the driver present in the forklift?",
        options=["yes", "no"]
    ),
    Query(
        query="Where is the forklift currently at?",
        options=["Truck", "Warehouse", "Charging"]
    ),
    Query(
        query="Is the forklift currently carrying cargo?",
        options=["yes", "no"]
    )
]

# Initialize VideoQL
video_ql = VideoQL(
    video_path="path/to/your/video.mp4",
    queries=queries,
    context="You are viewing the POV from inside a forklift"
)

# Analyze entire video
results = video_ql.analyze_video(display=True)

# Query specific conditions using our Pydantic models
query_config = QueryConfig(
    queries=[
        QueryCondition(
            query="Is the driver present in the forklift?",
            options=["yes"]
        )
    ]
)

# Query the video
matching_frames = video_ql.query_video(query_config)

You can also have VideoQL automatically generate the queries and query config as shown below:

from video_ql import VideoQL
from video_ql.query_proposer import generate_queries_from_context

# Define the context for your video analysis
context = "You are watching a construction site for safety compliance monitoring."

# Automatically generate queries based on the context using the selected model
queries = generate_queries_from_context(
    context=context,
    model_name="gpt-4o-mini",  # Model can be substituted as desired
    num_queries=5
)

# Initialize VideoQL with generated queries
video_ql = VideoQL(
    video_path="path/to/your/video.mp4",
    queries=queries,
    context=context
)

# Proceed with video analysis as usual
results = video_ql.analyze_video(display=True)

Command Line Interface

Natural Language Analysis

Use the CLI tool to analyze your video

$video_ql --video path/to/video.mp4
=====================================
   Welcome to Interactive VideoQL   
=====================================

First, let's create a context for your video analysis.
Describe the video content and what you're interested in tracking or analyzing.
Video context:  ... your context here

Generating queries based on your description...

Generated queries:
1. Query 1?
   Options: Yes, No
2. Another generated query?
   Options: ...

... enjoy your video analysis

YAML Analysis

  1. Create a config file (config.yaml):
queries:
  - query: "Is the driver present in the forklift?"
    options: ["yes", "no"]
  - query: "Where is the forklift currently at?"
    options: ["Truck", "Warehouse", "Charging"]
  - query: "Is the forklift currently carrying cargo?"
    options: ["yes", "no"]
context: "You are viewing the POV from inside a forklift"
fps: 1.0
tile_frames: [3, 3]
frame_stride: 9
max_resolution: [640, 360]
  1. Create a query file (query.yaml):
queries:
  - OR:
    - query: "Is the driver present in the forklift?"
      options: ["yes"]
  1. Run the CLI:
python3 -m video_ql.yaml_analysis --video path/to/video.mp4 \
         --config config.yaml \
         --query query.yaml \
         --output results/query_results \
         --threads 100 \
         --display

You may also process a single frame using the following

python3 -m video_ql.single_frame \
         --image path/to/image.png \
         --config config.yaml \
         --output results/query_results.json \
         --display

The query proposer helps you automatically generate relevant queries for your video content based on a provided context.

from video_ql.query_proposer import generate_queries_from_context, save_queries_to_yaml

# Generate queries based on context
context = "Security camera footage of a parking lot at night"
queries = generate_queries_from_context(
    context=context,
    model_name="gpt-4o-mini",  # or "claude-3-haiku-20240307" 
    num_queries=5
)

# Save queries to a YAML file
save_queries_to_yaml(queries, "generated_queries.yaml")

You can use the query proposer from the command line:

python -m video_ql.query_proposer \
    --context "Dashcam footage of urban driving in rainy conditions" \
    --model "gpt-4o-mini" \
    --num-queries 7 \
    --output "dashcam_queries.yaml"

Development

Read the CONTRIBUTING.md file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

video_ql-1.4.0.tar.gz (4.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

video_ql-1.4.0-py3-none-any.whl (40.7 kB view details)

Uploaded Python 3

File details

Details for the file video_ql-1.4.0.tar.gz.

File metadata

  • Download URL: video_ql-1.4.0.tar.gz
  • Upload date:
  • Size: 4.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for video_ql-1.4.0.tar.gz
Algorithm Hash digest
SHA256 9775c04f807b7aef206b4f579210f16f2e702401e8c40107c4f7dac4cdeccd67
MD5 3eb50c247e89d78c34b50b0b710bc6e7
BLAKE2b-256 e7a2f6cfb2738fb5364ebd78c16fe6e09948c4da9ff558110c4dfbe27699c046

See more details on using hashes here.

File details

Details for the file video_ql-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: video_ql-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 40.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for video_ql-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df5b5d2be01e189c3e7f4fdbf2303780e4f188486f3b334dc1773c45ce3a2d58
MD5 9d77224710699e187bc295c079de1c1a
BLAKE2b-256 cbfbe12011acb262a8c57e1b36385e939a9b0ea1295d979aa1ece5becec37ad3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page