[英]How to fix 'HTTP Response Code was 403 Forbidden' error in bitmovin-javascript on node.js server
我在node.js服務器上使用bitmovin-javascript。 我正在嘗試在Firebase存儲上為視頻創建編碼,並使用bitmovin-javascript API將輸出保存到我的bitmovin帳戶中。
我已經從舊的bitmovin api(v1)升級為javascript(現已棄用),並且正在實現當前的api(v2)。 但是每次我運行該代碼時,它都顯示HTTP請求失敗:在我的終端控制台中, HTTP響應代碼被禁止為403 。
我已經進行了交叉檢查,並確保我正在從Firebase存儲中讀取的API密鑰(accesss-key和secret-key)是有效密鑰,並且bitmovin API密鑰也是有效密鑰。 bitmovin的輸出ID也是有效的ID。
api生成輸入和視頻編解碼 器配置 , 音頻編解碼器配置和清單,但不生成輸出或編碼 。
該錯誤似乎是在api試圖創建編碼資源的時候發生的。
這是我的代碼的樣子:
const Bitmovin = require('bitmovin-javascript').default;
const start = async () => {
const bitmovin = Bitmovin({ 'apiKey': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' });
// create the input
const input = await bitmovin.encoding.inputs.gcs.create({
name: 'Input',
accessKey: 'GOOGXXXXXXXXXXXXXXXX',
secretKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
bucketName: 'project-name.appspot.com'
});
// create the output
const outputId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
// create the video and audio codec configurations
const videoCodecConfig1 = await bitmovin.encoding.codecConfigurations.h264.create({
name: 'H264 Codec Config',
bitrate: 240000,
width: 384,
profile: 'HIGH'
});
const audioCodecConfig = await bitmovin.encoding.codecConfigurations.aac.create({
name: 'my-aac-128kbit-cc',
bitrate: 128000, // 128 KBit/s
rate: 48000
});
// create the encoding resource
const encoding = await bitmovin.encoding.encodings.create({
name: 'Encoding',
cloudRegion: 'AUTO',
encoderVersion: '2.12.1'
});
// add the video and audio streams to the encoding
const inputPath = 'https://firebasestorage.googleapis.com/v0/b/project-name.appspot.com/o/new%2Fvideos%2Fsample.mp4?alt=media&token=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX';
const videoStreamConfig1 = {
codecConfigId: videoCodecConfig1.id,
inputStreams: [{
inputId: input.id,
inputPath: inputPath,
selectionMode: 'AUTO'
}]
};
const streamVideo1 = await bitmovin.encoding.encodings(encoding.id).streams.add(videoStreamConfig1);
const audioStreamConfig = {
codecConfigId: audioCodecConfig.id,
inputStreams: [{
inputId: input.id,
inputPath: inputPath,
selectionMode: 'AUTO'
}]
};
const audioStream = await bitmovin.encoding.encodings(encoding.id).streams.add(audioStreamConfig);
// add the video muxings to the encoding
const segmentLength = 4;
const outputPath = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/' + Date.now();
const segmentNaming = 'seg_%number%.m4s';
const initSegmentName = 'init.mp4';
const fmp4VideoMuxingConfig1 = {
segmentLength,
segmentNaming,
initSegmentName,
streams: [{
streamId: streamVideo1.id
}],
outputs: [{
outputId: outputId,
outputPath: outputPath + '/video/384_240000/fmp4/',
acl: [{
permission: 'PUBLIC_READ'
}]
}]
};
const videoMuxing1 = await bitmovin.encoding.encodings(encoding.id).muxings.fmp4.add(fmp4VideoMuxingConfig1);
// add the audio muxing to the encoding
const fmp4AudioMuxingConfig = {
segmentLength,
segmentNaming,
initSegmentName,
streams: [{
streamId: audioStream.id
}],
outputs: [{
outputId: outputId,
outputPath: outputPath + '/audio/128000/fmp4/',
acl: [{
permission: 'PUBLIC_READ'
}]
}]
};
const fmp4AudioMuxing = await bitmovin.encoding.encodings(encoding.id).muxings.fmp4.add(fmp4AudioMuxingConfig);
//create the manifest
const manifestConfig = {
name: 'Manifest',
manifestName: 'manifest.mpd',
outputs: [{
outputId: outputId,
outputPath: outputPath,
acl: [{
permission: 'PUBLIC_READ'
}]
}]
};
const manifest = await bitmovin.encoding.manifests.dash.create(manifestConfig);
const period = await bitmovin.encoding.manifests.dash(manifest.id).periods.add({});
let videoAdaptationSet = {
};
let audioAdaptationSet = {
lang: 'en'
};
videoAdaptationSet = await bitmovin.encoding.manifests
.dash(manifest.id)
.periods(period.id)
.adaptationSets.video.create(videoAdaptationSet);
audioAdaptationSet = await bitmovin.encoding.manifests
.dash(manifest.id)
.periods(period.id)
.adaptationSets.audio.create(audioAdaptationSet);
// Adding Audio Representation
const fmp4AudioRepresentation = {
type: 'TEMPLATE',
encodingId: encoding.id,
muxingId: fmp4AudioMuxing.id,
segmentPath: 'audio/128000/fmp4'
};
await bitmovin.encoding.manifests
.dash(manifest.id)
.periods(period.id)
.adaptationSets(audioAdaptationSet.id)
.representations.fmp4
.add(fmp4AudioRepresentation);
// Adding Video Representation
const fmp4VideoRepresentation1 = {
type: 'TEMPLATE',
encodingId: encoding.id,
muxingId: videoMuxing1.id,
segmentPath: 'video/384_240000/fmp4'
};
await bitmovin.encoding.manifests
.dash(manifest.id)
.periods(period.id)
.adaptationSets(videoAdaptationSet.id)
.representations.fmp4
.add(fmp4VideoRepresentation1);
// start the encoding
await bitmovin.encoding.encodings(encoding.id).start();
// wait for the encoding to be finished
await finish(encoding);
//start and wait for the manifest to be finished
await bitmovin.encoding.manifests.dash(manifest.id).start();
console.log('Generating DASH manifest...');
const waitForManifestToBeFinished = async () => {
let manifestResponse;
do {
await bitmovin.encoding.manifests
.dash(manifest.id)
.status()
.then(response => {
console.log('DASH Manifest status is ' + response.status);
manifestResponse = response;
});
await new Promise(resolve => setTimeout(resolve, 2000));
}
while (manifestResponse.status === 'RUNNING' || manifestResponse.status === 'CREATED');
};
await waitForManifestToBeFinished();
console.log('Everything finished...');
function getStatus(encoding) {
return bitmovin.encoding.encodings(encoding.id).status();
}
function finish(encoding, interval = 5 * 1000, timeout = 5 * 60 * 1000) {
let t, s = new Date();
const check = (resolve, reject) => {
clearTimeout(t);
t = setTimeout(() => {
getStatus(encoding)
.then(current => {
console.log('Encoding progress: ' + current.progress);
if (current.status === 'FINISHED') {
return resolve(current);
}
if (current.status === 'ERROR') {
return reject('Encoding error');
}
if (new Date() - s >= timeout) {
return reject('Timeout reached');
}
check(resolve, reject);
});
}, interval);
}
return new Promise((resolve, reject) => {
check(resolve, reject);
});
}
}
start().catch(e => console.log(e.message));
我希望該API能夠讀取我的Firebase存儲,對來自該存儲的視頻進行編碼,將其存儲在我的bitmovin輸出下,為我提供一個到輸出的bitmovin鏈接,以便可以將其保存到我自己的數據庫中。
幫助將不勝感激。
到目前為止,我還沒有注意到您提供的代碼段有任何特定的問題。 但是,此問題可能是由另一個因素引起的,例如輸入/輸出設置或輸入文件本身。
請隨時聯系support@bitmovin.com,並提供編碼ID和輸入文件,以便我們對此進行更詳細的研究。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.