Tutorial

How to Detect Labels (Objects) in Videos Using JavaScript

This article shows how to use Eden AI’s label detection API with JavaScript to analyze videos. It covers the two-step process of launching and retrieving job results, as well as managing tasks like listing and deleting jobs.

How to Detect Labels (Objects) in Videos Using JavaScript
TABLE OF CONTENTS

Label detection, or Object Detection plays a crucial role in video and image analysis by identifying and classifying elements within each frame like objects, people, animals, or landmarks.

This process enhances content tagging, indexing, and searchability. In this tutorial, we’ll guide you through implementing label detection using JavaScript and the Eden AI API.

With just a few lines of code, you’ll be able to analyze visual content and extract valuable insights effortlessly.

What is Label Detection?

Label detection automatically identifies and categorizes objects, people, and scenes in videos or images. It assigns labels like animals, buildings, or landmarks to visual elements, making content easier to search, organize, and analyze.

How to Detect Labels in Videos

Get Access to Eden AI API

1. Sign up: Visit Eden AI and create an account for free to get started. Once registered, go to the API section to find your personal API key which gives you access to AI services, including Label Detection.

2. Navigate to Video Technologies – Log in and head to the Video Technologies section.

3. Select Label Detection– From there, select the Label Detection option.

Live Test Models on Eden AI

Eden AI lets you experiment with various AI models before integration, making it easy to compare and choose the provider that best fits your needs.

Implementing Label Detection in JavaScript

Step 1: Install JavaScript's Requests Module

To get started, you'll need to install Axios. Axios is a promise-based HTTP client for the browser and Node.js, which makes it easy to send asynchronous HTTP requests.


npm install axios

Code Breakdown

The label detection API in Eden AI is asynchronous, meaning it works in two stages:

  1. POST request – Launching the Job: This initiates the label detection process by sending the video URL and provider(s) to Eden AI.
  2. GET request – Retrieving the Results: Once the job is processed, you can fetch the detection results using a unique public_id received from the first request.

This two-phase system is essential for processing larger media files, which can take time to analyze. Instead of waiting for the process to finish in a single request, the async model allows you to start the job and check back later.

Launching the Label Detection Job

This POST part of the code sends a request to Eden AI to start the label detection job.


const API_TOKEN = 'your_api_token_here';
const videoUrl = '🔗 URL of your video'; // Replace with the actual video URL

const headers = {
    "Authorization": `Bearer ${API_TOKEN}`,
    "Content-Type": "application/json"
};

const body = JSON.stringify({
    providers: ["google"],
    file_url: videoUrl
});

fetch("https://api.edenai.run/v2/video/label_detection_async", {
    method: "POST",
    headers: headers,
    body: body
})
    .then(response => response.json())
    .then(result => {
        console.log(result); // Contains public_id and job status
    })
    .catch(error => {
        console.error('Error:', error);
    });

What This Does:

  • providers: Choose the AI provider (e.g., Google).
  • file_url: Publicly accessible video URL.
  • fetch(): Sends the request to Eden AI.
  • public_id: Use this ID to fetch the results later.

Retrieving the Job Results

Once your job is submitted and processed, retrieve the results using the public_id.


const API_TOKEN = 'your_api_token_here';
const publicId = 'your_public_id_here'; // Replace with the actual public ID

const headers = {
    "Authorization": `Bearer ${API_TOKEN}`,
    "Content-Type": "application/json"
};

fetch(`https://api.edenai.run/v2/video/label_detection_async/${publicId}/`, {
    method: "POST",
    headers: headers
})
    .then(response => response.json())
    .then(result => {
        console.log(result); // Contains label detection results
    })
    .catch(error => {
        console.error('Error:', error);
    });

Code Explanation

  • The first request sends your video to Eden AI for processing.
  • The second request checks back later to retrieve the result.
  • Both requests use Authorization headers to authenticate.
  • The public_id links both stages.

Example Output & Interpreting Results

Here’s an example of what the response might look like:


{
  "google": {
    "status": "success",
    "label_annotations": [
      {
        "description": "Bicycle",
        "confidence": 0.93,
        "start_time": "00:00:05",
        "end_time": "00:00:07"
      }
    ]
  }
}

What the Fields Mean:

  • description: The detected object or scene.
  • confidence: How certain the AI is (from 0 to 1).
  • start_time / end_time: When the label appears in the video.

Managing Label Detection Jobs

For better management of your label detection tasks, Eden AI provides additional optional steps:

Label Detection - List Jobs

GET Request:
https://api.edenai.run/v2/video/label_detection_async/
This lets you list all jobs submitted for label detection. You can use the public_id of each job to monitor its status or fetch results. You can check the full documentation here.

Label Detection - Delete Jobs

DELETE Request:
https://api.edenai.run/v2/video/label_detection_async/
Use this to delete jobs you no longer need, helping you clean up and organize your task history.. You can check the full documentation here.

Why Eden AI is the Best Tool for Label Detection

Eden AI offers a robust Label Detection solution with several advantages.

Multiple Provider Options

Eden AI allows you to compare and use multiple providers like Google and Amazon at once.

Ease of Integration

Eden AI simplifies the integration of label detection into your applications with clear and straightforward JavaScript code examples.

Security and Trust

The Eden AI platform prioritizes data security and privacy, ensuring that your image data is handled securely.

Conclusion

Using Eden AI with JavaScript gives you fast, flexible access to powerful label detection tools. With an easy-to-use async API and support for top AI providers, you can quickly integrate object recognition into your applications.

By combining real-time video intelligence with job management features like listing and deleting jobs, Eden AI is a reliable and scalable choice for developers and businesses alike.

Start Your AI Journey Today

  • Access 100+ AI APIs in a single platform.
  • Compare and deploy AI models effortlessly.
  • Pay-as-you-go with no upfront fees.
Start building FREE

Related Posts

Try Eden AI for free.

You can directly start building now. If you have any questions, feel free to chat with us!

Get startedContact sales
X

Start Your AI Journey Today

Sign up now with free credits to explore 100+ AI APIs.
Get my FREE credits now