gpt4 book ai didi

c# - 从使用 Nreco 的视频 GetThumbnail 的 URL

转载 作者:行者123 更新时间:2023-12-04 23:16:22 26 4
gpt4 key购买 nike

我在一个共享点项目中工作,我必须将文档库中的视频作为视频集上传。创建视频集后,我必须上传视频并从视频中获取缩略图并上传。视频使用成功上传

spfile = item.Folder.Files.Add(fuUpload.FileName, fuUpload.PostedFile.InputStream, true);

我正在使用 Nreco 从视频中获取缩略图。但是,我的代码在本地机器上运行良好,但是当我从其他 PC 浏览器使用我的应用程序时,它给出错误“ http://mysite/Download/abc/abc.mp4:服务器返回 401 Unauthorized(授权失败)(退出代码:1)”。

ffMpeg.GetVideoThumbnail(videoPath, ms, 10);错误行。

这是我正在使用的代码
private MemoryStream SaveThumbnail(string videoPath) 
{
MemoryStream ms;
try
{
videoPath = "http://mysitehttp/Download/abc/abc.mp4"
ms = new MemoryStream();
SPSecurity.RunWithElevatedPrivileges(delegate() {

var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
ffMpeg.GetVideoThumbnail(videoPath, ms, 10);
});


}
catch(Exception ex)
{
throw ex;
}

return ms;
}

最佳答案

最后我设法解决了这个问题。由于某种原因,SharePoint 不允许我使用 NReco 直接从 URL 访问文件,所以我像这样调整了函数。

我没有使用文件 URL 作为参数,而是使用了它自己的文件对象。并将流复制到虚拟目录中的服务器临时文件夹中,然后我使用系统上的文件路径为 NRreco 创建缩略图。最后从服务器上删除了文件。

private MemoryStream SaveThumbnail(SPFile videoFile) 
{
MemoryStream ms;
try
{
//Creating Temp File Path to be used by Nreco


ms = new MemoryStream();
SPSecurity.RunWithElevatedPrivileges(delegate() {

string destinationFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + videoFile.Name);

//Copying the content the content of the file at temp loaction from stream
using (FileStream fileStream = File.Create(destinationFile))
{
Stream lStream = videoFile.OpenBinaryStream();
byte[] contents = new byte[lStream.Length];
lStream.Read(contents, 0, (int)lStream.Length);
lStream.Close();

// Use write method to write to the file specified above
fileStream.Write(contents, 0, contents.Length);
fileStream.Close();
}


var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
ffMpeg.GetVideoThumbnail(destinationFile, ms, 10);

System.IO.File.Delete(destinationFile);
});


}
catch(Exception ex)
{
throw ex;
}

return ms;
}

有人可能会从我的回答中节省一些时间。如果有人有更好的解决方案,请告诉我。

关于c# - 从使用 Nreco 的视频 GetThumbnail 的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34943201/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com