c# - Youtube API上载时间太短

标签 c# video youtube google-api youtube-api

我正在尝试使用C#上传视频,上传本身可以

视频总是太短(例如,在YouTube中2:14视频变成00:29视频,00:45视频变成00:05视频)。

上传过程中没有错误消息或异常

这是我正在使用的代码

        UserCredential credential;
        ClientSecrets secrets = new ClientSecrets();
        secrets.ClientId = "clientid";
        secrets.ClientSecret = "clientsecret";
        credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
            secrets,
            new[] { YouTubeService.Scope.YoutubeUpload },
            "username", 
            CancellationToken.None
        );

        var youtubeService = new YouTubeService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
        });

        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 = "public";
        var filePath = @"filepath";
        using (var fileStream = new FileStream(filePath, FileMode.Open))
        {
            var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet, status", fileStream, "video/mp4");

            videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
            videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;
            videosInsertRequest.Upload();
        }

收件人代码源自google-api示例

最佳答案

通过使用ffmpeg命令行对视频进行转码:

  • ffmpeg -i%source%%target%.mp4

  • 我们发现使用mediainfo
  • http://mediaarea.net/en/MediaInfo/Download

  • ffmpeg的输出比原始输出短。 ffmpeg输出确实指示一些有关未找到的NAL单元的错误消息,这意味着输入流被加扰,并且上传的视频实际上比VLC媒体播放器显示的短。

    关于c# - Youtube API上载时间太短,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47024398/

    相关文章:

    c# - 如何将 XMLDocument 反序列化为 C# 中的对象?

    c# - 我在 C# 中的程序的注销部分出错,我能得到一些帮助吗?

    android - 如何从 H264 流中获取 slice-height 和 stride?

    javascript - 如何在 youtube javascript API 中删除 youtube 视频的名称?

    python-3.x - 用 Selenium 刮活聊天直到流结束

    youtube - 有没有一种方法可以在一个API调用中搜索多个Youtube channel

    c# - 这是滥用依赖注入(inject)吗? (什么时候依赖不是依赖)

    c# - 一般检查不会在非约束类型上装箱可空值的 null。

    Flash 视频替代品

    c# - 当左键单击原始图像时,如何设置做某事?