【问题标题】:How to upload video to youtube with chunked stream using data api如何使用数据 api 通过分块流将视频上传到 youtube
【发布时间】:2022-07-03 20:30:26
【问题描述】:

首先让我解释一下我的目标,

我正在从本地、S3、Drive 或 Mega 等不同来源以流的形式下载视频,还带有缓冲区和流并将它保存到MemoryBuffer,然后当我上传它时,它会立即上传而无需等待其他块,我不知道如何解决这个问题。这是我的代码。

    var video = new Video();
    video.Snippet = new VideoSnippet();
    video.Snippet.Title = "Default Video Title";
    video.Snippet.Description = "Default Video Description";
    video.Snippet.Tags = new string[] { "tag1", "tag2" };
    video.Snippet.CategoryId = "22";
    video.Status = new VideoStatus();
    video.Status.PrivacyStatus = "unlisted";

    var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", stream, "video/*");
    videosInsertRequest.ChunkSize = ResumableUpload.MinimumChunkSize;

    videosInsertRequest.ProgressChanged += (progress) =>
    {
      switch (progress.Status)
      {
        case UploadStatus.Starting:
          Console.WriteLine("Starting to upload.");
          break;
        case UploadStatus.Uploading:
          Console.WriteLine("{0} bytes sent.", progress.BytesSent);
          break;
        case UploadStatus.Completed:
          Console.WriteLine("Uploaded.");
          break;
        case UploadStatus.Failed:
          Console.WriteLine("An error prevented the upload from completing.\n{0}", progress.Exception);
          break;
      }
    };

    return videosInsertRequest;
    var stream = Mega.Download(video);

    int bufferSize = 1024 * 256;
    byte[] buffer = new byte[bufferSize];
    int bufferPosition = 0;

    Stream memoryStream = new MemoryStream(buffer);

    var youtubeVideo = Uploader.YouTube(memoryStream); //this is the code above

    bool isEnd = false;
    while (isEnd is false)
    {
      while (bufferPosition < bufferSize && isEnd is false)
      {
        var readBytes = await stream.BaseStream.ReadAsync(buffer, bufferPosition, bufferSize - bufferPosition);
        bufferPosition += readBytes;
        isEnd = readBytes == 0;
      }

      await memoryStream.FlushAsync();
      memoryStream.Position = 0;
      await memoryStream.WriteAsync(buffer, 0, bufferPosition);

      await youtubeVideo.UploadAsync();

      Array.Clear(buffer);
      bufferPosition = 0;
    }

【问题讨论】:

    标签: .net google-api youtube-api


    【解决方案1】:

    链接备用 Ipinslot https://s.id/IPINSLOT4 Silahkan di coba kak 玫瑰^,^

    Harap Selalu ganti 用户 ID 密码 ya setelah Di berikan ..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-27
      • 2014-01-06
      • 2021-03-22
      • 2020-06-29
      • 2015-07-12
      • 2015-08-31
      • 2011-05-13
      相关资源
      最近更新 更多