gpt4 book ai didi

javascript - Node.js 使用亚马逊转码器格式化视频/音频文件

转载 作者:行者123 更新时间:2023-11-30 07:13:20 24 4
gpt4 key购买 nike

我的目标是确保所有上传到我的应用程序的视频都是正确的格式,并且它们的格式适合最小尺寸。

我在使用 ffmpeg 之前这样做了,但是我最近将我的应用程序移到了亚马逊服务器上。

这让我可以选择使用 Amazon Elastic Transcoder

但是从界面上看,我无法设置自 Action 业来查找视频或音频文件并进行转换。

为此,我一直在查看他们的 SDK/api 引用资料,但我不太确定如何在我的应用程序中使用它。

我的问题是,有没有人在 node.js 中成功开始转码工作,并且知道如何将视频从一种格式转换为另一种格式和/或降低比特率?如果有人能通过一些示例说明这可能如何工作,为我指明正确的方向,我将不胜感激。

最佳答案

However by the looks of it from the interface i am unable to set up automatic jobs that look for video or audio files and converts them.

Node.js SDK 不支持它,但您可以执行以下操作:如果您将视频存储在 S3 中(如果不将它们移动到 S3,因为弹性转码器使用 S3),您可以在 S3 上运行 Lambda 函数 putObject triggered由 AWS。

http://docs.aws.amazon.com/lambda/latest/dg/with-s3.html

My question is has anyone successfully started transcoding jobs in node.js and know how to convert videos from one format to another and / or down set the bitrate? I would really appreciate it if someone could point me in the right direction with some examples of how this might work.

我们使用 AWS 使用 Node 进行视频转码,没有任何问题。找出每个参数很费时间,但我希望这几行可以帮助你:

const aws = require('aws-sdk');

aws.config.update({
accessKeyId: config.AWS.accessKeyId,
secretAccessKey: config.AWS.secretAccessKey,
region: config.AWS.region
});

var transcoder = new aws.ElasticTranscoder();

let transcodeVideo = function (key, callback) {
// presets: http://docs.aws.amazon.com/elastictranscoder/latest/developerguide/system-presets.html
let params = {
PipelineId: config.AWS.transcode.video.pipelineId, // specifies output/input buckets in S3
Input: {
Key: key,
},
OutputKeyPrefix: config.AWS.transcode.video.outputKeyPrefix,
Outputs: config.AWS.transcode.video.presets.map(p => {
return {Key: `${key}${p.suffix}`, PresetId: p.presetId};
})
};

params.Outputs[0].ThumbnailPattern = `${key}-{count}`;
transcoder.createJob(params, function (err, data) {
if (!!err) {
logger.err(err);
return;
}
let jobId = data.Job.Id;
logger.info('AWS transcoder job created (' + jobId + ')');
transcoder.waitFor('jobComplete', {Id: jobId}, callback);
});
};

示例配置文件:

let config = {
accessKeyId: '',
secretAccessKey: '',
region: '',
videoBucket: 'blabla-media',
transcode: {
video: {
pipelineId: '1450364128039-xcv57g',
outputKeyPrefix: 'transcoded/', // put the video into the transcoded folder
presets: [ // Comes from AWS console
{presetId: '1351620000001-000040', suffix: '_360'},
{presetId: '1351620000001-000020', suffix: '_480'}
]
}
}
};

关于javascript - Node.js 使用亚马逊转码器格式化视频/音频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42674334/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com