meema / laravel-media-converter
轻松快速地将您的应用程序与 AWS MediaConvert 集成。
Requires
- php: ^7.3|^8.0
- ext-json: *
- aws/aws-php-sns-message-validator: ^1.6
- aws/aws-sdk-php: ^3.173
Requires (Dev)
- orchestra/testbench: ^5.0|^6.0
- pestphp/pest: ^1.0
- pestphp/pest-plugin-laravel: ^1.0
- phpunit/phpunit: ^8.0|^9.3
- vlucas/phpdotenv: ^4.2|^5.3
- dev-main
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.2
- 1.0.1
- 1.0.0
- 0.8.0
- 0.7.0
- 0.6.1
- 0.6.0
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-renovate/pestphp-pest-3.x
- dev-analysis-rrkvL9
- dev-renovate/pestphp-pest-plugin-laravel-3.x
- dev-renovate/orchestra-testbench-9.x
- dev-renovate/phpunit-phpunit-11.x
- dev-renovate/actions-cache-4.x
- dev-renovate/actions-checkout-4.x
- dev-renovate/pestphp-pest-plugin-laravel-2.x
- dev-renovate/pestphp-pest-2.x
- dev-renovate/orchestra-testbench-8.x
- dev-renovate/php-8.x
- dev-renovate/vlucas-phpdotenv-5.x
- dev-renovate/phpunit-phpunit-10.x
- dev-renovate/all-minor-patch
- dev-renovate/actions-checkout-3.x
- dev-renovate/actions-cache-3.x
- dev-fix-test-cases
- dev-github-actions
This package is auto-updated.
Last update: 2024-09-10 20:45:24 UTC
README
这是一个 AWS MediaConvert 的包装包。可能会添加更多驱动程序。
💡 使用方法
use Meema\MediaConverter\Facades\MediaConvert; use Meema\MediaConverter\Jobs\CreateVideoConversion; # simple usage MediaConvert::path('video.mkv') // the s3 path to the file inside the bucket defined in your config (filesystems.disks.s3.bucket) ->optimizeForWeb() // will generate an optimized MP4 for you ->withThumbnails(int $framerateNumerator, int $framerateDenominator, int $maxCaptures, $width = null, $nameModifier = null, $imageQuality = 80) // will generate thumbnails from the video for you, e.g. poster images ->saveTo('my-optimized-video.mp4') // output file name ->createJob(); # advanced usage $result = MediaConvert::cancelJob(string $id); $result = MediaConvert::createJob(array $settings, array $metaData = [], int $priority = 0); $result = MediaConvert::getJob(string $id); $result = MediaConvert::listJobs(array $options); # you may also dispatch a job to convert a video dispatch(new CreateVideoConversion($jobSettings, $mediaId)); // $mediaId is optional & refers to the relating model's id
🐙 安装
您可以通过 composer 安装此包
composer require meema/laravel-media-converter
该包将自动注册自己。
然后,使用以下命令发布配置文件
php artisan vendor:publish --provider="Meema\MediaConverter\Providers\MediaConverterServiceProvider" --tag="config"
然后,请将以下键及其值添加到您的 .env
文件中。
AWS_ACCESS_KEY_ID=xxxxxxx AWS_SECRET_ACCESS_KEY=xxxxxxx AWS_DEFAULT_REGION=us-east-1 AWS_MEDIACONVERT_ACCOUNT_URL=https://xxxxxxxxx.mediaconvert.us-east-1.amazonaws.com AWS_IAM_ARN=arn:aws:iam::xxxxxxx:role/MediaConvert_Default_Role AWS_QUEUE_ARN=arn:aws:mediaconvert:us-east-1:xxxxxxx:queues/Default
以下是已发布配置文件的内容
return [ /* * The fully qualified class name of the "media" model. */ 'media_model' => \App\Models\Media::class, /** * IAM Credentials from AWS. */ 'credentials' => [ 'key' => env('AWS_ACCESS_KEY_ID'), 'secret' => env('AWS_SECRET_ACCESS_KEY'), ], 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 'version' => 'latest', 'url' => env('AWS_MEDIACONVERT_ACCOUNT_URL'), /** * Specify the IAM Role ARN. * * You can find the Role ARN visiting the following URL: * https://console.aws.amazon.com/iam/home?region=us-east-1#/roles * Please note to adjust the "region" in the URL above. * Tip: in case you need to create a new Role, you may name it `MediaConvert_Default_Role` * by making use of this name, AWS MediaConvert will default to using this IAM Role. */ 'iam_arn' => env('AWS_IAM_ARN'), /** * Specify the queue you would like use. * * It can be found by visiting the following URL: * https://us-east-1.console.aws.amazon.com/mediaconvert/home?region=us-east-1#/queues/details/Default * Please note to adjust the "region" in the URL above. */ 'queue_arn' => env('AWS_QUEUE_ARN'), /** * Specify how often MediaConvert sends STATUS_UPDATE events to Amazon CloudWatch Events. * Set the interval, in seconds, between status updates. * * MediaConvert sends an update at this interval from the time the service begins processing * your job to the time it completes the transcode or encounters an error. * * Accepted values: 10, 12, 15, 20, 30, 60, 120, 180, 240, 300, 360, 420, 480, 540, 600 */ 'webhook_interval' => 60, /** * This value indicates whether to track media conversions in your database. * * Note: in case you *do* want to track media conversions, you will need to execute the * migration included as part of the package. */ 'track_media_conversions' => true, /** * If track_media_conversions is set to true, you may specify the events you would like to fire/track. * By default, it will track all status updates. * * Read more about MediaConvert conversion statuses here: * https://docs.aws.amazon.com/mediaconvert/latest/ug/mediaconvert_cwe_events.html */ 'statuses_to_track' => ['complete', 'error', 'new_warning', 'progressing', 'input_information', 'queue_hop'], ];
准备您的媒体模型(可选)
此包包括一个特质,您可以使用它来定义您的“媒体模型”与跟踪转换之间的关系。
只需按照以下方式使用它
namespace App\Models; use Illuminate\Database\Eloquent\Model; use Meema\MediaConverter\Traits\Convertable; class Media extends Model { use Convertable; // ... }
设置 Webhooks(可选)
此包使用 Webhooks 来通信 MediaConvert 作业的状态/进度。请按照以下步骤为您启用 Webhooks。
请注意,这仅是可选的,您只有在想跟踪 MediaConvert 作业的进度时才应启用此功能。
设置 Expose
首先,让我们使用 Expose 来“暴露”/生成我们本地 API 的 URL。请遵循 Expose 文档了解如何开始,并在您的开发环境中生成一个“实时”且可共享的 URL。
这应该像 cd my-laravel-api && expose
一样简单。
设置 AWS SNS 主题和订阅
其次,让我们创建一个 AWS SNS 主题,它将通知我们的“暴露”API端点
- 在 https://console.aws.amazon.com/sns/v3/home 上打开 Amazon SNS 控制台
- 在导航面板中,选择“主题”,然后选择“创建新主题”。
- 对于主题名称,输入
MediaConvertJobUpdate
,然后选择“创建主题”。
- 选择您刚刚创建的主题的 ARN 链接。它看起来像这样:
arn:aws:sns:region:123456789012:MediaConvertJobUpdate
。 - 在“主题详情:MediaConvertJobUpdate”页面的“订阅”部分中,选择“创建订阅”。
- 对于协议,选择“HTTPS”。对于端点,输入您在之前步骤中生成的“暴露”API URL。
例如,
https://meema-api.sharedwithexpose.com/api/webhooks/media-converter
- 选择“创建订阅”。
确认您的订阅
最后,我们需要确认订阅,这很容易在导航到“MediaConvertJobUpdate”主题页面时完成。在那里,您应该看到以下部分
默认情况下,AWS 将向您在“订阅”设置中定义的 URL 发送 POST 请求。此包自动处理“确认”部分。如果在确认之前出现问题,请点击截图上所示的“请求确认”按钮。
您还可以在 Expose 界面中查看请求,通过访问“仪表板 URL”,它应该是类似于:http://127.0.0.1:4040
一旦状态反映为“已确认”,您的 API 将接收 AWS 提供的更新作为 Webhooks。
创建 CloudWatch 事件
- 在 https://console.aws.amazon.com/cloudwatch/ 上打开 CloudWatch 控制台。
- 在导航面板中,选择“事件”,然后选择“创建规则”。
- 确保输入与以下截图匹配
如图所示,我们需要选择“服务名称”、“事件类型”以及引用我们之前创建的SNS主题的“目标”。
最后,“创建规则”的第二步和最后一步会提示您输入一个名称和可选的描述。您可以使用任何名称,例如 mediaconvert-job-updates
。
现在,您的API将接收webhooks!
部署到Laravel Vapor
请注意,截至目前,您不能重用存储在“环境文件”中的AWS凭证。为此,您需要通过重命名来调整media-converter.php
-配置文件:
从:AWS_ACCESS_KEY_ID
- 到:例如 VAPOR_ACCESS_KEY_ID
从:AWS_SECRET_ACCESS_KEY
- 到:例如 VAPOR_SECRET_ACCESS_KEY
最后,请确保您的Vapor环境已定义这些值。
🧪 测试
composer test
📈 更新日志
有关最近更改的更多信息,请参阅我们的发布页面。
💪🏼 贡献
有关详细信息,请参阅贡献指南。
🏝 社区
如有帮助、讨论最佳实践或任何其他有价值的可搜索对话,请
与其他使用此包的人进行轻松闲聊
🚨 安全性
请查看我们的安全策略以了解如何报告安全漏洞。
🙏🏼 致谢
📄 许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证。
由Meema Inc.用❤️制作。