meema/laravel-media-converter
Composer 安装命令:
composer require meema/laravel-media-converter
包简介
Easily & quickly integrate your application with AWS MediaConvert.
关键字:
README 文档
README
This is a wrapper package for AWS MediaConvert. Additional drivers may be added.
💡 Usage
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
🐙 Installation
You can install the package via composer:
composer require meema/laravel-media-converter
The package will automatically register itself.
Next, publish the config file with:
php artisan vendor:publish --provider="Meema\MediaConverter\Providers\MediaConverterServiceProvider" --tag="config"
Next, please add the following keys their values to your .env file.
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
The following is the content of the published config file:
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'], ];
Preparing Your Media Model (optional)
This package includes a trait for your "Media model" that you may use to define the relationship of your media model with the tracked conversions.
Simply use it as follows:
namespace App\Models; use Illuminate\Database\Eloquent\Model; use Meema\MediaConverter\Traits\Convertable; class Media extends Model { use Convertable; // ... }
Set Up Webhooks (optional)
This package makes use of webhooks in order to communicate the status/progress of the MediaConvert job. Please follow the following steps to enable webhooks for yourself.
Please note, this is only optional, and you should only enable this if you want to track the MediaConvert job's progressions.
Setup Expose
First, let's use Expose to "expose" / generate a URL for our local API. Follow the Expose documentation on how you can get started and generate a "live" & sharable URL for within your development environment.
It should be as simple as cd my-laravel-api && expose.
Setup AWS SNS Topic & Subscription
Second, let's create an AWS SNS Topic which will notify our "exposed" API endpoint:
- Open the Amazon SNS console at https://console.aws.amazon.com/sns/v3/home
- In the navigation pane, choose Topics, and then choose "Create new topic".
- For Topic name, enter
MediaConvertJobUpdate, and then choose "Create topic".
- Choose the topic ARN link for the topic that you just created. It looks something like this:
arn:aws:sns:region:123456789012:MediaConvertJobUpdate. - On the Topic details:
MediaConvertJobUpdatepage, in the Subscriptions section, choose "Create subscription". - For Protocol, choose "HTTPS". For Endpoint, enter your "exposed" API URL which you generated in a previous step.
For example,
https://meema-api.sharedwithexpose.com/api/webhooks/media-converter
- Choose "Create subscription".
Confirming Your Subscription
Finally, we need to confirm the subscription which is easily done by navigating to the MediaConvertJobUpdate Topic page. There, you should see the following section:
By default, AWS will have sent a post request to URL you defined in your "Subscription" setup. This package automatically handles the "confirmation" part. In case there is an issue and it is not confirmed yet, please click on the "Request confirmation" button as seen in the screenshot above.
You can also view the request in the Expose interface, by visiting the "Dashboard Url", which should be similar to: http://127.0.0.1:4040
Once the status reflects "Confirmed", your API will receive webhooks as AWS provides updates.
Create CloudWatch Event
- Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.
- In the navigation pane, choose Events, and then choose "Create rule".
- Make sure the inputs match the following screenshots:
As you can see in above screenshot, we needed to select the "Service Name", "Event Type", and the "Target" which is referencing our SNS Topic we earlier created.
Lastly, the second & final step of the "Rule creation" prompts you to enter a name and an optional description. You may use any name, e.g. mediaconvert-job-updates.
Now, your API will receive webhooks!
Deploying to Laravel Vapor
Please note, as of right now, you cannot reuse the AWS credentials stored in your "environment file". The "workaround" for this is to adjust the media-converter.php-config file by renaming
From: AWS_ACCESS_KEY_ID - To: e.g. VAPOR_ACCESS_KEY_ID
From: AWS_SECRET_ACCESS_KEY - To: e.g. VAPOR_SECRET_ACCESS_KEY
and, lastly, please ensure that your Vapor environment has these values defined.
🧪 Testing
composer test
📈 Changelog
Please see our releases page for more information on what has changed recently.
💪🏼 Contributing
Please see CONTRIBUTING for details.
🏝 Community
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
For casual chit-chat with others using this package:
🚨 Security
Please review our security policy on how to report security vulnerabilities.
🙏🏼 Credits
📄 License
The MIT License (MIT). Please see LICENSE for more information.
Made with ❤️ by Meema, Inc.
meema/laravel-media-converter 适用场景与选型建议
meema/laravel-media-converter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 95.86k 次下载、GitHub Stars 达 57, 最近一次更新时间为 2020 年 12 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「aws」 「laravel」 「optimize」 「mp4」 「video conversion」 「Meema」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 meema/laravel-media-converter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 meema/laravel-media-converter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 meema/laravel-media-converter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package includes a script and fail2ban configuration that allows you to use fail2ban when utilizing AWS elastic load balancer (ELB) and an apache webserver.
Elastic Driver for Laravel Scout
simple api library.
A replica of the AWS Elastic Beanstalk worker SQS daemon (sqsd) in PHP
A beautiful, zero-dependency UI for querying and viewing AWS CloudWatch logs directly inside your Laravel application.
Laravel Page Speed
统计信息
- 总下载量: 95.86k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 57
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-12-04