【问题标题】:From URL of Video GetThumbnail Using Nreco从使用 Nreco 的视频 GetThumbnail 的 URL
【发布时间】:2016-01-22 09:29:03
【问题描述】:

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

成功上传视频
spfile = item.Folder.Files.Add(fuUpload.FileName, fuUpload.PostedFile.InputStream, true);

我正在使用 Nreco 从视频中获取缩略图。但是我的代码在本地机器上运行良好,但是当我从其他电脑浏览器使用我的应用程序时,它给出了错误“http://mysite/Download/abc/abc.mp4: Server returned 401 Unauthorized (authorization failed) (exit code: 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;
    }

【问题讨论】:

  • 您是否有权从其他电脑访问缩略图?
  • 是的,当我直接在浏览器上点击 url 时,它会播放视频文件。

标签: c# asp.net ffmpeg sharepoint-2013 video-conversion


【解决方案1】:

我终于设法解决了这个问题。由于某种原因,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;
        }

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-18
    • 2017-02-24
    • 2018-10-24
    • 2011-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多