从C#中的视频网址创建缩略图

时间:2015-01-30 15:43:31

标签: c# video ffmpeg video-thumbnails

我想从C#中的视频网址生成缩略图。我经常搜索,找到一个简洁的方法,但没有成功。我使用过NrecoMediaToolKit,但都没有提取缩略图。使用ffmpeg还有mumbo jumbos,但没有用!

使用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);
        }

考虑视频文件不是本地的,我只有文件的直接链接: e.g:http://phytonord.com/Film-Series/hana/26.mp4

有没有人有任何解决方案?任何有效的示例代码?

2 个答案:

答案 0 :(得分:2)

使用NReco创建视频缩略图:

我发现了我的问题:

1:我没有使用过Server.MapPath。我刚刚输入了relativePath。

2:视频文件不必是 local ,它可以托管在其他地方。 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);

答案 1 :(得分:0)

我可以看到问题已经回答但是没有写清楚,所以这是我的答案: 首先下载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);

现在运行此代码并检查缩略图文件的创建位置