Skip to content

A library for processing and analyzing media content, providing tools for audio, video and text analysis.

License

Notifications You must be signed in to change notification settings

Invis1ble/media-intelligence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Media Intelligence

This repository contains PSR-compatible code for media analysis and processing.

Dependencies

In order to use this package you need to install the following utilities:

  • yt-dlp is a command-line program to download videos from YouTube.com and a few more sites.
  • ffmpeg required by yt-dlp for post-processing tasks.

Installation

To install this package, you can use Composer:

composer require invis1ble/media-intelligence

or just add it as a dependency in your composer.json file:

{
    "require": {
        "invis1ble/media-intelligence": "^2.0"
    }
}

After adding the above line, run the following command to install the package:

composer install

Usage

To use most of the tools you need to set OpenAI API Key

<?php // ./public/index.php

declare(strict_types=1);

require __DIR__ . '/../vendor/autoload.php';

use Invis1ble\MediaIntelligence\VideoToFacts\Application;

// Set here your own OpenAI API Key.
// Visit https://platform.openai.com/account/api-keys for more details.
$openAiApiKey = '';
$audioTargetDirectoryPath = sys_get_temp_dir();

$application = new Application(
    apiKey: $openAiApiKey,
    audioTargetDirectory: new SplFileInfo($audioTargetDirectoryPath),
);

$facts = $application->run('https://www.youtube.com/watch?v=JdMw9lQTNnc');
/** @var iterable<string> $facts List of the extracted facts */

foreach ($facts as $fact) {
    echo "- $fact\n";
}

Logging setup

To set up logging, you need to set a PSR-3-compatible logger for the services that you want to log. Monolog is recommended as implementation.

// ...

use Monolog\Handler\StreamHandler;
use Monolog\Level;
use Monolog\Logger;

// ...

$logger = new Logger(
    name: 'video_to_facts_logger',
    handlers: [
        // write all staff to the file
        new StreamHandler(__DIR__ . '/../logs/video_to_facts.log', Level::Debug),
        // write info and higher to console
        new StreamHandler(STDOUT, Level::Info),
    ],
);

$application = new Application(
    apiKey: $openAiApiKey,
    audioTargetDirectory: new SplFileInfo($audioTargetDirectoryPath),
    debug: true,
);

$application->setLogger($logger);

$facts = $application->run('https://www.youtube.com/watch?v=JdMw9lQTNnc');
/** @var iterable<string> $facts List of the extracted facts */

Output of the above code:

VideoToFacts Application output

Translation

You can translate the facts to many languages, just pass the language name to the FactsExtractor through application:

$application->run('https://www.youtube.com/watch?v=1sRLDDIRL4U', 'Ukrainian');

Known issues and limitations

  • At the moment, we are forced to split long videos into shorter segments due to OpenAI API limitations, which reduces the efficiency and accuracy of content analysis. If you have any suggestions on how to solve this problem, please do not hesitate to write about it in the Issues, and I will gladly consider your idea.

Stay tuned!

License

The MIT License