madbob/silly-videos

根据自定义配置生成包含文本的视频

支持包维护!
其他

0.1.0 2024-07-21 22:21 UTC

This package is auto-updated.

Last update: 2024-09-21 20:54:06 UTC


README

Silly Videos 是一个 PHP 库,用于根据描述文本和图像等简单元素的 JSON 配置获取视频。

它逐个生成所需的帧,并使用 ffmpeg 将它们收集成视频。

该项目最初是为了为 TrendingOnWiki 生成社交媒体内容(如:YouTube 和 Instagram)而实现的。

安装

composer require madbob/silly-videos

需要 PHP gd 扩展和当然的 ffmpeg

使用方法

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);

配置

{
    "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
                    }
                }
            ]
        }
    ]
}

许可协议

此代码是免费软件,许可协议为 MIT 许可。有关详细信息,请参阅 LICENSE.txt 文件。

版权 (C) 2024 Roberto Guido info@madbob.org