.Net get video cover

Do the course of the project needs to obtain cover demand at the time of video uploading video frame can be pumped through this video ffmpeg exe file to upload. Specific code as follows:

string videoPath = Request.Form["videoPath"];
string uploadPath = AppSettingUtil.AppSettings["UploadFilePath"];
string videoFilePath = Server.MapPath("~/" + uploadPath + videoPath);
string ffmpegPath = Server.MapPath(AppSettingUtil.AppSettings["ffmpeg"]);
if (!File.Exists(ffmpegPath)) return new AjaxResult("ffmpeg不存在");
string imagePath = DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.Ticks + ".png";
string imageSavePath = Server.MapPath("~/" + uploadPath + "" + imagePath);
string cmd = string.Format("-i {0} -ss 00:00:01 -vframes 1 {1}", videoFilePath, imageSavePath);
ProcessStartInfo startInfo = new ProcessStartInfo(ffmpegPath)
{
    WindowStyle = ProcessWindowStyle.Hidden,
    Arguments = cmd
};
try
{
    Process proc = Process.Start(startInfo);
    if (proc != null) proc.WaitForExit();
}
catch (Exception ex)
{
    return new AjaxResult(ex.Message);
}
if (File.Exists(imageSavePath))
    return new AjaxResult
    {
        IsSuccess = true,
        Data = imagePath
    };
return new AjaxResult("视频截图失败");

Reference address
ffmpeg Download
Create a thumbnail image every X seconds of the video - FFmpeg

Guess you like

Origin www.cnblogs.com/blogcore/p/12459700.html