我想在 C# 中从视频 URL 生成缩略图。我进行了很多搜索以找到一种简洁的方法但没有成功。我使用过 Nreco
和 MediaToolKit
但它们都没有提取缩略图。使用 ffmpeg 也有一些无效的庞然大物!
使用 NReco:
var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
string thumbnailJPEGpath = "http://localhost:81882/content/hashem.jpeg";
ffMpeg.GetVideoThumbnail(videoUrl,thumbnailJPEGpath);
使用 ffmpeg:
try
{
System.Diagnostics.Process ffmpeg;
string video;
string thumb;
video = Server.MapPath("~/Content/Movies/bye.mp4");
thumb = Server.MapPath("~/Content/frame.jpg");
ffmpeg = new System.Diagnostics.Process();
ffmpeg.StartInfo.Arguments = " -i " + video + " -ss 00:00:07 -vframes 1 -f image2 -vcodec mjpeg " + thumb;
ffmpeg.StartInfo.FileName = Server.MapPath("~/Content/ffmpeg.exe");
ffmpeg.Start();
ffmpeg.WaitForExit();
ffmpeg.Close();
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
}
考虑到视频文件不是本地的,我只有文件的直接链接:
例如:http://phytonord.com/Film-Series/hana/26.mp4
有没有人有什么解决办法?任何有效的示例代码?
最佳答案
使用 NReco 创建视频缩略图:
我发现了我的问题:
1:我没有用过Server.MapPath。我刚进入 relativePath。
2:视频文件不一定是本地,它可以托管在其他地方。 NReco 只需下载所需的视频部分,然后提取缩略图。 您的视频文件应位于本地服务器的 localHost 目录中。我的意思是,如果您的站点正在开发中并且视频文件位于本地计算机文件夹中,它不会工作,因为 NReco 需要 HTTP 响应头文件中的字节范围支持。
Not Acceptable 链接:“http://localhost:81882/content/AVSEQ01.mp4”
所以对于我的本地测试,我已将我的视频文件移动到本地 IIS 目录:C:\inetpub\wwwroot\AVSEQ01.mp4
//sample remote video file
//string videoUrl = "http://phytonord.com/Film-Series/peik%20sahar/1.mp4";
//local video file
string localVideoFile = "http://localhost/AVSEQ01.mp4"
var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
string thumbnailJPEGpath = Server.MapPath("~/Content/videoThumb.jpg");
ffMpeg.GetVideoThumbnail(videoUrl, thumbnailJPEGpath);
关于c# - 在 C# 中从视频 URL 创建缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28239491/