Пример #1
0
 /// <summary>
 /// 生成视频封面
 /// </summary>
 /// <param name="path">视频的绝对路径:/Upload/File/zzzzz.mp4</param>
 /// <param name="uploadifyResult"></param>
 public void GenerateVideoCoverImg(string path, UploadifyResult uploadifyResult)
 {
     #region 生成图片
     string       videoFullPath = WebHelper.GetMapPath(path);
     FFmpegHelper ff            = new FFmpegHelper(videoFullPath);
     VideoInfo    videoInfo     = ff.GetVideoInfo();
     string       saveImgPath   = string.Empty;
     if (videoInfo.Width < 1)
     {
         videoInfo.Width  = 500;
         videoInfo.Height = 330;
     }
     if (videoInfo.Width > 0)
     {
         uploadifyResult.videoInfo = JsonConvert.SerializeObject(videoInfo);
         int[]  whInt         = GetDpi(_videoCoverDpi);
         string dir           = Path.GetDirectoryName(videoFullPath);
         string videoFileName = Path.GetFileNameWithoutExtension(videoFullPath);
         int    index         = videoFileName.LastIndexOf(']');
         videoFileName = videoFileName.Substring(index + 1);//去掉括号
         int duration = 3;
         if (uploadifyResult.fileSize < 10485760)
         {
             duration = 2;
         }
         saveImgPath = string.Concat(dir, "\\", videoFileName, ".jpg");
         ff.GetVideoFirstImage(saveImgPath, videoInfo.Width, videoInfo.Height, duration);
         //生成的缩略图的路径格式是:原图路径 + “-”+ dpi + 后缀
         if (System.IO.File.Exists(saveImgPath))
         {
             string desPath = string.Concat(dir, "\\", videoFileName, "-" + _videoCoverDpi, ".jpg");// videoFullPath.Insert(videoFullPath.LastIndexOf('.'), "-" + _videoCoverDpi);
             ThumbnailHelper.GenerateImage2(saveImgPath, desPath, whInt[0], whInt[1]);
         }
     }
     #endregion
 }