亚马逊 AWS 视频转码功能、AWS Elemental MediaConvert 中创建和管理转码作业

本文主要是介绍亚马逊 AWS 视频转码功能、AWS Elemental MediaConvert 中创建和管理转码作业,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

上传的视频需要转码成不同的编码, 可以直接在 AWS Elemental MediaConvert 中创建和管理转码作业

AWS Elemental MediaConvert 中创建和管理转码作业

/*** 视频转码* @return bool* @author wzb* @data 2024/5/30*/function videoTranscode(&$data){$fileId = $data['id'] ?? 0;$fileName = $data['fileName'] ?? '';$FileInput = $data['FileInput'] ?? '';  // s3://s3桶名/src/080dc06642cf814809b61f7f381fa576.mp4if (!$fileId || empty($fileName) || empty($FileInput)) {return true;}$configOss = config('aws_oss');$configOss = $configOss['video_transcode'] ?? [];$accessKeyId = $configOss['accessKeyId'] ?? '';  // 你的AccessKeyId$accessKeySecret = $configOss['accessKeySecret'] ?? '';  // 你的AccessKeySecret$region = $configOss['region'] ?? ''; // 你的Bucket所在地域的域名$bucket = $configOss['bucket'] ?? ''; // 你的Bucket名字$stsClient = new StsClient(['version' => 'latest',//版本'region' => $region,//区域'credentials' => new Credentials($accessKeyId,//Access key ID$accessKeySecret,//Secret access key),]);$result = $stsClient->getSessionToken(['DurationSeconds' => 900, ]);$credentials = $stsClient->createCredentials($result);$data['token_data'] = $result['Credentials']['Expiration'] ?? '';$tokenCredentials = $credentials->toArray();$data['token_expires_date'] = date('Y-m-d H:i:s', $tokenCredentials['expires'] ?? 0);$mediaConvertClient = new MediaConvertClient(['version' => 'latest',//版本'region' => $region,
//            'endpoint' => 'https://mediaconvert.ap-southeast-1.amazonaws.com','credentials' => $credentials
//            'credentials' => [
//                'key' => $result['Credentials']['AccessKeyId'],
//                'secret' => $result['Credentials']['SecretAccessKey'],
//                'token' => $result['Credentials']['SessionToken']
//            ]]);try {$outFileDir = ['oss_path_480' => "s3://{$bucket}/video_test/video480/",'oss_path_720' => "s3://{$bucket}/video_test/video720/",'oss_path_1080' => "s3://{$bucket}/video_test/video1080/",];$result = $mediaConvertClient->createJob(["Role" => "arn:aws:iam::51**284:role/service-role/MediaConvert_Default_Role","Settings" => ['FollowSource' => 1,'Inputs' => [['AudioSelectors' => ['Audio Selector 1' => ['DefaultSelection' => 'DEFAULT']],'VideoSelector' => [],'TimecodeSource' => 'ZEROBASED','FileInput' => $FileInput,]],'OutputGroups' => self::configOutputGroups($outFileDir),],"Queue" => "arn:aws:mediaconvert:ap-southeast-1:515287419284:queues/Default","UserMetadata" => ["Customer" => "Amazon1"],]);$jobId = ($result['Job']['Id'] ?? '');$data['jobId'] = $jobId;if (!empty($jobId)) {$res = FileModel::updateData(['id' => $fileId], ['job_id' => $jobId, 'oss_path_480' => $outFileDir['oss_path_480'] . $fileName,'oss_path_720' => $outFileDir['oss_path_720'] . $fileName, 'oss_path_1080' => $outFileDir['oss_path_1080'] . $fileName,]);send_socket_time_task(['id' => $fileId, 'job_id' => $jobId], 120, 'OssJob');} else {$res = FileModel::updateData(['id' => $fileId], ['is_transcode' => 2]); // 转码失败}SysComService::fileInfo($fileId, 2); // 清理缓存} catch (AwsException $e) {$data['exception'] = $e->getMessage();;send_dingtalk_develop("filed upload oss error:{$fileId}:;\n" . $e->getMessage());return false;}return true;}// 转码输出配置,// 可以直接在AWS Elemental MediaConvert 配置模版/作业,然后复制json对象static function configOutputGroups($outFileDir = []){$video480Path = $outFileDir['oss_path_480'] ?? '';$video720Path = $outFileDir['oss_path_720'] ?? '';$video1080Path = $outFileDir['oss_path_1080'] ?? '';$OutputGroups = '[{"CustomName": "video480", "Name": "File Group","Outputs": [{"ContainerSettings": {  "Container": "MP4", "Mp4Settings": {} },"VideoDescription": {"Width": 480, "Height": 854,"CodecSettings": {"Codec": "H_264","H264Settings": { "MaxBitrate": 1000000, "RateControlMode": "QVBR",   "SceneChangeDetect": "TRANSITION_DETECTION" }}},"AudioDescriptions": [{"CodecSettings": {"Codec": "AAC","AacSettings": { "Bitrate": 96000, "CodingMode": "CODING_MODE_2_0",  "SampleRate": 48000 }}}]}],"OutputGroupSettings": {"Type": "FILE_GROUP_SETTINGS","FileGroupSettings": {"Destination": "' . $video480Path . '","DestinationSettings": {"S3Settings": {  "StorageClass": "STANDARD" }}}}},{"CustomName": "video720", "Name": "File Group","Outputs": [{"ContainerSettings": {  "Container": "MP4",  "Mp4Settings": {}  },"VideoDescription": {"Width": 720,  "Height": 1280,"CodecSettings": {"Codec": "H_264","H264Settings": { "MaxBitrate": 2500000,  "RateControlMode": "QVBR", "SceneChangeDetect": "TRANSITION_DETECTION" }}},"AudioDescriptions": [{"CodecSettings": {"Codec": "AAC","AacSettings": { "Bitrate": 96000,  "CodingMode": "CODING_MODE_2_0",  "SampleRate": 48000 }}}]}],"OutputGroupSettings": {"Type": "FILE_GROUP_SETTINGS","FileGroupSettings": {"Destination": "' . $video720Path . '","DestinationSettings": {"S3Settings": {  "StorageClass": "STANDARD" }}}}},{"CustomName": "video1080", "Name": "File Group","Outputs": [{"ContainerSettings": { "Container": "MP4", "Mp4Settings": {} },"VideoDescription": {"Width": 1080,  "Height": 1920,"CodecSettings": {"Codec": "H_264","H264Settings": { "MaxBitrate": 5000000, "RateControlMode": "QVBR", "SceneChangeDetect": "TRANSITION_DETECTION" }}},"AudioDescriptions": [{"CodecSettings": {"Codec": "AAC","AacSettings": {  "Bitrate": 96000, "CodingMode": "CODING_MODE_2_0",  "SampleRate": 48000 }}}]}],"OutputGroupSettings": {"Type": "FILE_GROUP_SETTINGS","FileGroupSettings": {"Destination": "' . $video1080Path . '"}}}]';return json_decode($OutputGroups, true);}

检测视频转码任务是否完成

function checkVideoTranscode(&$data){$fileId = $data['id'] ?? 0;$jobId = $data['job_id'] ?? '';if (!$fileId || empty($jobId)) {return true;}$configOss = config('aws_oss');$configOss = $configOss['video_transcode'] ?? [];$accessKeyId = $configOss['accessKeyId'] ?? '';  // 你的AccessKeyId$accessKeySecret = $configOss['accessKeySecret'] ?? '';  // 你的AccessKeySecret$region = $configOss['region'] ?? ''; // 你的Bucket所在地域的域名$stsClient = new StsClient(['version' => 'latest',//版本'region' => $region,//区域'credentials' => new Credentials($accessKeyId,//Access key ID$accessKeySecret,//Secret access key),]);$result = $stsClient->getSessionToken(['DurationSeconds' => 900,]);$credentials = $stsClient->createCredentials($result);$data['token_data'] = $result['Credentials']['Expiration'] ?? '';$tokenCredentials = $credentials->toArray();$data['token_expires_date'] = date('Y-m-d H:i:s', $tokenCredentials['expires'] ?? 0);$mediaConvertClient = new MediaConvertClient(['version' => 'latest',//版本'region' => $region,'credentials' => $credentials
//            'credentials' => [
//                'key' => $result['Credentials']['AccessKeyId'],
//                'secret' => $result['Credentials']['SecretAccessKey'],
//                'token' => $result['Credentials']['SessionToken']
//            ]]);try {$result = $mediaConvertClient->getJob(['Id' => $jobId,]);$status = $result['Job']['Status'] ?? ''; // COMPLETE  	ERROR$statusArr = ['COMPLETE' => 1, 'ERROR' => 2,];if (isset($statusArr[$status])) {$res = FileModel::updateData(['id' => $fileId], ['is_transcode' => $statusArr[$status]]);SysComService::fileInfo($fileId, 2); // 清理缓存} else {send_socket_time_task(['id' => $fileId, 'job_id' => $jobId], 120, 'OssJob');}$data['token_data_status'] = $status;} catch (AwsException $e) {$data['token_data_exception'] = $e->getMessage();$data['exception'] = $e->getMessage();send_dingtalk_develop("filed upload oss error:{$fileId}:;\n" . $e->getMessage());return false;}return true;}

这篇关于亚马逊 AWS 视频转码功能、AWS Elemental MediaConvert 中创建和管理转码作业的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1033041

相关文章

JAVA中整型数组、字符串数组、整型数和字符串 的创建与转换的方法

《JAVA中整型数组、字符串数组、整型数和字符串的创建与转换的方法》本文介绍了Java中字符串、字符数组和整型数组的创建方法,以及它们之间的转换方法,还详细讲解了字符串中的一些常用方法,如index... 目录一、字符串、字符数组和整型数组的创建1、字符串的创建方法1.1 通过引用字符数组来创建字符串1.2

最好用的WPF加载动画功能

《最好用的WPF加载动画功能》当开发应用程序时,提供良好的用户体验(UX)是至关重要的,加载动画作为一种有效的沟通工具,它不仅能告知用户系统正在工作,还能够通过视觉上的吸引力来增强整体用户体验,本文给... 目录前言需求分析高级用法综合案例总结最后前言当开发应用程序时,提供良好的用户体验(UX)是至关重要

python实现自动登录12306自动抢票功能

《python实现自动登录12306自动抢票功能》随着互联网技术的发展,越来越多的人选择通过网络平台购票,特别是在中国,12306作为官方火车票预订平台,承担了巨大的访问量,对于热门线路或者节假日出行... 目录一、遇到的问题?二、改进三、进阶–展望总结一、遇到的问题?1.url-正确的表头:就是首先ur

SpringBoot使用minio进行文件管理的流程步骤

《SpringBoot使用minio进行文件管理的流程步骤》MinIO是一个高性能的对象存储系统,兼容AmazonS3API,该软件设计用于处理非结构化数据,如图片、视频、日志文件以及备份数据等,本文... 目录一、拉取minio镜像二、创建配置文件和上传文件的目录三、启动容器四、浏览器登录 minio五、

手把手教你idea中创建一个javaweb(webapp)项目详细图文教程

《手把手教你idea中创建一个javaweb(webapp)项目详细图文教程》:本文主要介绍如何使用IntelliJIDEA创建一个Maven项目,并配置Tomcat服务器进行运行,过程包括创建... 1.启动idea2.创建项目模板点击项目-新建项目-选择maven,显示如下页面输入项目名称,选择

如何评价Ubuntu 24.04 LTS? Ubuntu 24.04 LTS新功能亮点和重要变化

《如何评价Ubuntu24.04LTS?Ubuntu24.04LTS新功能亮点和重要变化》Ubuntu24.04LTS即将发布,带来一系列提升用户体验的显著功能,本文深入探讨了该版本的亮... Ubuntu 24.04 LTS,代号 Noble NumBAT,正式发布下载!如果你在使用 Ubuntu 23.

TP-LINK/水星和hasivo交换机怎么选? 三款网管交换机系统功能对比

《TP-LINK/水星和hasivo交换机怎么选?三款网管交换机系统功能对比》今天选了三款都是”8+1″的2.5G网管交换机,分别是TP-LINK水星和hasivo交换机,该怎么选呢?这些交换机功... TP-LINK、水星和hasivo这三台交换机都是”8+1″的2.5G网管交换机,我手里的China编程has

Django中使用SMTP实现邮件发送功能

《Django中使用SMTP实现邮件发送功能》在Django中使用SMTP发送邮件是一个常见的需求,通常用于发送用户注册确认邮件、密码重置邮件等,下面我们来看看如何在Django中配置S... 目录1. 配置 Django 项目以使用 SMTP2. 创建 Django 应用3. 添加应用到项目设置4. 创建

IDEA中的Kafka管理神器详解

《IDEA中的Kafka管理神器详解》这款基于IDEA插件实现的Kafka管理工具,能够在本地IDE环境中直接运行,简化了设置流程,为开发者提供了更加紧密集成、高效且直观的Kafka操作体验... 目录免安装:IDEA中的Kafka管理神器!简介安装必要的插件创建 Kafka 连接第一步:创建连接第二步:选

使用 Python 和 LabelMe 实现图片验证码的自动标注功能

《使用Python和LabelMe实现图片验证码的自动标注功能》文章介绍了如何使用Python和LabelMe自动标注图片验证码,主要步骤包括图像预处理、OCR识别和生成标注文件,通过结合Pa... 目录使用 python 和 LabelMe 实现图片验证码的自动标注环境准备必备工具安装依赖实现自动标注核心