首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从使用Nreco的视频GetThumbnail的URL

从使用Nreco的视频GetThumbnail的URL
EN

Stack Overflow用户
提问于 2016-01-22 17:29:03
回答 1查看 1.5K关注 0票数 0

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

代码语言:javascript
复制
spfile = item.Folder.Files.Add(fuUpload.FileName, fuUpload.PostedFile.InputStream, true);

我正在使用Nreco从视频中获取缩略图。然而,我的代码在本地机器上运行良好,但当我在其他pc浏览器上使用我的应用程序时,它给出了错误"http://mysite/Download/abc/abc.mp4:Server returned 401 Unauthorized (authorization failed) (退出代码: 1)“。

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

下面是我使用的代码

代码语言:javascript
复制
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;
    }
EN

回答 1

Stack Overflow用户

发布于 2016-02-08 14:47:23

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

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

代码语言:javascript
复制
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;
        }

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34943201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档