zoukankan      html  css  js  c++  java
  • 截取上传视频的第一帧作为封面的方法

    1,我们需要借助一个工具ffmpeg(http://www.ffmpeg.org/download.html)

    2,截取第一帧的方法

            /// <summary>  
            /// 从视频中截取img格式图片  
            /// </summary>  
            /// <param name="applicationPath">ffmpeg.exe文件路径</param>  
            /// <param name="fileNamePath">视频文件路径(带文件名)</param>  
            /// <param name="targetImgNamePath">生成img图片路径(带文件名)</param>  
            private void ConverToImg(string applicationPath, string fileNamePath, string targetImgNamePath)
            {
    
                //string c = applicationPath + @"\ffmpeg.exe -i" + fileNamePath + targetImgNamePath+"-ss 00:00:05  -r 1 -vframes 1 -an -vcodec mjpeg " ;  
                string c = applicationPath + @"\ffmpeg.exe -ss 00:00:05 -i" + " " + fileNamePath + " " + targetImgNamePath + " " + "-r 1 -vframes 1 -an -vcodec mjpeg ";//速度快  
                Cmd(c);
                //-i:设定输入文件名  
                //-r:设定帧 此处设为1帧  
                //-f:设定输出格式  
                //-ss 从指定时间截图  
                //-vcodec:设定影像解码器,没有输入时为文件原来相同的解码器  
                //-vframes 设置转换多少桢(frame)的视频  
                //-an 不处理声音  
            }    
            /// <summary>  
            /// 程序中调用CMD.exe程序,并且不显示命令行窗口界面  
            /// </summary>  
            /// <param name="c">执行的cmd命令</param>  
            private void Cmd(string c)
            {
                try
                {
                    System.Diagnostics.Process process = new System.Diagnostics.Process();
                    process.StartInfo.CreateNoWindow = true; //不显示程序窗口                  
                    process.StartInfo.FileName = "cmd.exe";//要执行的程序名称   
                    process.StartInfo.UseShellExecute = false;
                    //process.StartInfo.RedirectStandardError = true;  
                    process.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息   
                    process.StartInfo.RedirectStandardInput = true; //可能接受来自调用程序的输入信息   
                    process.Start();//启动程序   
                    process.StandardInput.WriteLine(c);
                    process.StandardInput.AutoFlush = true;
                    process.StandardInput.WriteLine("exit");
    
                }
                catch { }
            }
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意需保留此段声明,且在文章页面明显位置给出原文连接。

    作者:Lnice
    出处:http://www.cnblogs.com/lnice
  • 相关阅读:
    Web测试和App测试重点总结(转)
    bug等级和标准(转)
    App测试准入准出标准(转)
    开发人员应该怎么做,保证app在开发完毕后达到可提测的基本要求(转)
    1、Web网站常规测试点总结
    文件操作和函数
    python 数据类型
    Python-函数的各种器
    Python-函数的初始
    Python-文件操作
  • 原文地址:https://www.cnblogs.com/lnice/p/6676606.html
Copyright © 2011-2022 走看看