• ffmpg转换FLV


    //转FLV

    public static string VideoConvertFlv(string FromName, string WidthAndHeight, string ExportName)
      {

      string ffmpeg = HttpContext.Current.Server.MapPath("~/FLV/ffmpeg.exe");
      string Command =" -i " + FromName + " -y -ab 56 -ar 22050 -b 500 -r 15 -s " + WidthAndHeight + " "+ ExportName; //Flv格式 
      //string Command = "E:\\FFmpeg\\ffmpeg.exe -i E:\\ClibDemo\\VideoPath\\admin\\a.wmv -y -ab 56 -ar 22050 -b 500 -r 15 -s 320*240 "+ ExportName; 
      System.Diagnostics.Process p = new System.Diagnostics.Process();
      p.StartInfo.FileName = ffmpeg;
      p.StartInfo.Arguments = Command; 
      p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/FLV/");
      p.StartInfo.UseShellExecute = false;
      p.StartInfo.RedirectStandardInput = true;
      p.StartInfo.RedirectStandardOutput = true;
      p.StartInfo.RedirectStandardError = true;
      p.StartInfo.CreateNoWindow = false;
      //开始执行 
      p.Start();
      p.BeginErrorReadLine();
      p.WaitForExit();
      p.Close();
      p.Dispose();
      //p.StandardInput.WriteLine(Command);
      //p.StandardInput.WriteLine("Exit ");
      return ExportName;
      }

    //同时生成PIC

      public static void GetImageFromVideo(string FromName, string imgName,string toolDir)
            {
                try
                {

                    Process p = new Process();//建立外部调用线程
                    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                    p.StartInfo.FileName = toolDir + @"\ffmpeg.exe";// HttpContext.Current.Server.MapPath(@"tool/ffmpeg.exe") ;//要调用外部程序的绝对路径                

                    p.StartInfo.Arguments = @" -i " + FromName + " -y -f image2 -t 0.001 -s 150x150 " + imgName;//参数(这里就是FFMPEG的参数了)
                    p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动线程(一定为FALSE,详细的请看MSDN)
                    p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中(这个一定要注意,FFMPEG的所有输出信息,都为错误输出流,用StandardOutput是捕获不到任何消息的...
                    p.StartInfo.CreateNoWindow = false;//不创建进程窗口
                    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                    p.Start();//启动线程
                    p.WaitForExit();//等待完成
                    p.StandardError.ReadToEnd();//开始同步读取
                    p.Close();//关闭进程
                    p.Dispose();//释放资源

                }
                catch (Exception err)
                {

                }
                finally
                {

                }

            }


     

    string toolDir = @"D:\works\tool\";
                try
                {

                   
                    //.flv|.wmv
                    System.IO.FileInfo fi = new System.IO.FileInfo(@"D:\works\.....avi");

                    if (fi.Exists)
                    {
                        string saveFlv = fi.FullName.Replace(fi.Extension, ".flv");
                        string saveImage = fi.FullName.Replace(fi.Extension, ".jpg");


                        VideoHelper.VideoConvertFlv(fi.FullName, saveFlv, "300x300", toolDir);
                        VideoHelper.GetImageFromVideo(saveFlv, saveImage, toolDir);
                    }
                }
                catch(Exception ex)
                {
                }

    -------长沙程序员技术交流QQ群:428755207-------
  • 相关阅读:
    grid布局
    flex弹性布局
    数据库连接使用ThreadLocal
    maven核心,pom.xml详解
    src和herf的区别
    表单校验出错,导致表单无法提交
    联机调试,如何配置局域网内文件服务器
    不同语言时间戳长度问题,及Java获取时间戳的效率
    OO设计原则 -- OO设计的原则及设计过程的全面总结
    Maven项目被clean命令之后的红叉或找不到class文件
  • 原文地址:https://www.cnblogs.com/qq4004229/p/1940377.html
Copyright © 2020-2023  润新知