我正在尝试使用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命令行对视频进行转码:
我们发现使用mediainfo
ffmpeg的输出比原始输出短。 ffmpeg输出确实指示一些有关未找到的NAL单元的错误消息,这意味着输入流被加扰,并且上传的视频实际上比VLC媒体播放器显示的短。
关于c# - Youtube API上载时间太短,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47024398/