簡體   English   中英

來自 s3 存儲桶的 Stream 個視頻文件

[英]Stream video files from s3 bucket

我從 aws s3 存儲桶中獲取 stream 視頻文件有些困難。 我已經在 nest.js 中實現了視頻 stream,但是沒有按預期工作。 (我正在使用@aws-sdk/client-s3庫)

  1. 我找不到視頻。
  2. 視頻總長度僅在觀看完整視頻時顯示。

這是我的代碼:

  async getVideoFromStorage(@Query('path') pathToStorage: string) {
    if (!pathToStorage) {
      throw new NotFoundException('Please provide a path');
    }
    const videoFromStorage = await this.client.send(
      new GetObjectCommand({
        Bucket: 'bucket',
        Key: pathToStorage,
      }),
    );

    if (!videoFromStorage) {
      throw new NotFoundException('File not found');
    }

    const uintArray = await videoFromStorage.Body.transformToByteArray();

    return new StreamableFile(uintArray, {
      type: 'video/webm',
      length: videoFromStorage.ContentLength,
    });
  }

對於理想的流式傳輸設置,您需要為自適應比特率分辨率對文件進行轉碼,例如將原始文件轉換為 360p、480p 等。然后您可以 package / transmux 並將其用於 stream。這樣視頻將分塊下載並播放. 否則,您將下載整個文件。 注意:您可以在 ec2 上使用 ffmpeg 來轉碼您的文件。 或者使用 aws Mediaconvert。 然后是 stream。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM