如何在node.js服务器上修复bitmovin-javascript中的'HTTP Response Code was 403 Forbidden'错误



我在node.js服务器上使用了bitmovin-javascript。我正在尝试使用BitMovin-Javascript API。

我已经从旧的Bitmovin API(V1)升级了JavaScript(现在已弃用),我正在实现当前的(V2)。但是,每次我运行代码时,它都会显示 HTTP请求不成功:HTTP响应代码在我的终端控制台中为403 prebdide

我已经进行了交叉检查并确保我用来从Firebase存储中读取的API键(Accesss-key&secret-key)是有效的,而Bitmovin API键也是有效的。。对于BitMovin来说,输出ID也是有效的。

API生成输入和 video-codec-configuarations audio-codec-configurations &表现出,但不会生成 outputs 编码

错误似乎是在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以及输入文件,以便我们对此进行更详细的调查。

相关内容

  • 没有找到相关文章

最新更新