[英]create thumbnail from video URL in C#
我想从 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响应头文件中的字节范围支持。
不可接受的链接 :“ 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);
我可以看到问题已经回答但是没有写清楚,所以这是我的答案:首先下载DLL
ffMpeg.GetVideoThumbnail(inputFile,outputFile, frameTime);
// Summary:
// Extract video frame from local video file at specified position
//
// Parameters:
// inputFile:
// path to local video file
//
// outputFile:
// path to thumbnail jpeg file
//
// frameTime:
// video position (in seconds)
这就是我在项目中的表现
var thumbNailMovieImage = PHYSICAL_PATH_UPLOAD_FILE + "/" + folder + "/thumb_" + filenameWithoutExtn + ".jpg";
var ffMpeg = new FFMpegConverter();
ffMpeg.GetVideoThumbnail(path, thumbNailMovieImage, 1);
现在运行此代码并检查缩略图文件的创建位置
以防万一,如果有人正在寻找使用 ffmpeg 或 NReco 库创建多个拇指图像提取以创建精灵图像。
使用命令行--> ffmpeg -i corpfilm.mp4 -s 280x150 -vf fps=1 thumb/img%03d.jpg
在引擎盖下, NReco.VideoConverter执行 ffmpeg 和 System.Diagnostics.Process API; 这意味着您可以在命令行中运行任何可能的命令。
对于此具体命令 VideoConverter 的 API 等价物:
var ffmpeg = new NReco.VideoConverter.FFMpegConverter();
ffmpeg.ConvertMedia(
"corpfilm.mp4", null,
" thumb/img%03d.jpg", null,
new ConvertSettings() {
CustomOutputArgs = " -s 280x150 -vf fps=1 "
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.