zoukankan      html  css  js  c++  java
  • .net c# 视频剪切抓取缩略图

    public string Cut(string ffmpegPath, string videoPath, string savePath, string imgSize, int sleepTime = 0xbb8)
            {
                if (File.Exists(ffmpegPath) && File.Exists(videoPath))
                {
                    string str = savePath;
                    string str2 = imgSize;
                    string path = savePath.Substring(0, savePath.LastIndexOf(@"\"));
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    ProcessStartInfo startInfo = new ProcessStartInfo(ffmpegPath)
                    {
                        WindowStyle = ProcessWindowStyle.Hidden,
                        Arguments = " -i " + videoPath + " -y -f image2 -t 0.001 -s " + str2 + " " + savePath
                    };
                    try
                    {
                        Process.Start(startInfo);
                        Thread.Sleep(sleepTime);
                    }
                    catch
                    {
                        return string.Empty;
                    }
                    if (File.Exists(savePath))
                    {
                        return savePath;
                    }
                }
                return string.Empty;
            }
     
            public string Cut(string ffmpegPath, string videoPath, string savePath, string imgSize, int sleepTime = 0xbb8, float startPos = 10, float cutTime = 1)
            {
                if (File.Exists(ffmpegPath) && File.Exists(videoPath))
                {
                    string str = savePath;
                    string str2 = imgSize;
                    string path = savePath.Substring(0, savePath.LastIndexOf(@"\"));
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    ProcessStartInfo startInfo = new ProcessStartInfo(ffmpegPath)
                    {
                        WindowStyle = ProcessWindowStyle.Hidden,
                        Arguments = string.Format(" -i {0} -t {1} -ss {2} -s {3} {4}", new object[] { videoPath, cutTime, startPos, str2, savePath })
                    };
                    try
                    {
                        Process.Start(startInfo);
                        Thread.Sleep(sleepTime);
                    }
                    catch
                    {
                        return string.Empty;
                    }
                    if (File.Exists(savePath))
                    {
                        return savePath;
                    }
                }
                return string.Empty;
            }
     
            protected void btnFetch_Click(object sender, EventArgs e)
            {
                try
                {
                    string imgDir = Server.MapPath(@"ffmpeg\\");
                    string ffmpegPath = imgDir + "ffmpeg.exe";
                    string imgSize = txtImgSize.Text.Trim();
                    int sleepTime = 500;
                    string ret = string.Empty;
                    float startPos = Convert.ToSingle(txtStartPos.Text.Trim());
                    float cutTime = Convert.ToSingle(txtCutTime.Text.Trim());
     
                    string temp = @"" + System.Configuration.ConfigurationManager.AppSettings["filepath"] + @"" + txtDownloadUrl.Text.Trim().Replace(@"/", @"\");
                    temp = temp.Replace(@"\\", @"\");
                    if (System.IO.File.Exists(temp))
                    {
                        ret = Cut(ffmpegPath, temp, imgDir + "img\\" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".jpg", imgSize, sleepTime);
     
                        if (string.IsNullOrEmpty(ret))
                        {
                            ret = Cut(ffmpegPath, temp, imgDir + "img\\" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".jpg", imgSize, sleepTime, startPos, cutTime);
                        }
     
                    }
                    litMsg.Text = ret;
                    imgDiagram.ImageUrl = ret.Replace(@"D:\site\20150914\", "/").Replace(@"\", "/");
                }
                catch (Exception ex) {
                    litMsg.Text = ex.Message;
                }
            }
     
  • 相关阅读:
    详解CUDA编程
    卷积神经网络详解
    python操作Excel读写--使用xlrd
    pycharm启动慢 –xms -xmx相关参数设置
    pycharm开发python利器入门
    win10安装windows live writer 错误:OnCatalogResult:0x80190194
    curl 模拟请求
    Python AES_ECB_PKCS5加密代码
    如何让eclipse恢复默认布局
    eclipse中项目jdk1.8刷新下就变成1.5的解决办法
  • 原文地址:https://www.cnblogs.com/hofmann/p/5012058.html
Copyright © 2011-2022 走看看