madbob/silly-videos

Generates videos with texts from a custom configuration

Fund package maintenance!
Other

0.1.1 2024-11-10 22:04 UTC

This package is auto-updated.

Last update: 2024-12-10 21:16:40 UTC


README

Silly Videos is a PHP library used to obtain videos starting from a JSON configuration describing simple elements like texts and images.

It generates the required frames, one by one, and collect them into a video using ffmpeg.

This project has been initially implemented to generate social contents (like: YouTube and Instagram) for TrendingOnWiki.

Install

composer require madbob/silly-videos

It is required the PHP gd extension and, of course, ffmpeg.

Usage

use MadBob\SillyVideos\SillyVideos;

// Use by JSON configuration file
SillyVideos::runFromFile($file, '/tmp/out.mp4');

// Use by in memory (eventually, dynamically generated) configuration
SillyVideos::run($config, '/tmp/out.mp4');

// Multi-process modes: forks multiple times to parallelize frames generation
SillyVideos::runFromFile($file, '/tmp/out.mp4', 4);
SillyVideos::run($config, '/tmp/out.mp4', 4);

Configuration

{
    "width": "300",
    "height": "300",
    "framerate": 30,
    "duration": 10,
    "background": "FFF",

    "elements": [
        {
            "type": "text",
            "text": "Test Text",
            "fontfile": "/path/to/your/font.ttf"

            "actions": [
                {
                    "duration": 3,
                    "delay": 0,

                    "start": {
                        "size": 30,
                        "x": 150,
                        "y": 400
                    },
                    "end": {
                        "y": 150
                    }
                },
                {
                    "duration": 3,
                    "delay": 3,

                    "start": {
                        "size": 30,
                        "x": 150,
                        "y": 150
                    },
                    "end": {
                        "size": 50,
                    }
                },
                {
                    "duration": 3,
                    "delay": 6,

                    "start": {
                        "rotate": 0,
                        "x": 150,
                        "y": 150
                    },
                    "end": {
                        "rotate": 360
                    }
                }
            ]
        }
    ]
}

License

This code is free software, licensed under the MIT License. See the LICENSE.txt file for more details.

Copyright (C) 2024 Roberto Guido info@madbob.org