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
  • 相关阅读:
    HTML 语义化标签-新增标签介绍
    HTML基础知识点
    Android JSON 解析关键代码
    [USACO16DEC]Cities and States省市
    [洛谷P1835]素数密度
    [洛谷P1168]中位数
    [HNOI2008]越狱
    [HAOI2007]上升序列
    [SHOI2009]Booking 会场预约
    [洛谷P1892][codevs2597]团伙
  • 原文地址:https://www.cnblogs.com/lnice/p/6676606.html
Copyright © 2011-2022 走看看