洞庭熊猫
无兄弟不篮球,无团队不项目!
随笔- 70  文章- 0  评论- 52 
博客园  首页  新随笔  联系  管理  订阅 订阅
2010年6月11日
Ffmpeg 实现视频截图

Ffmpeg
得到文件

下载好之后首先就是配置一下环境变量

我下载的放在了D盘跟目录

D:oracleproduct10.2.0client_1bin;D:oracleproduct10.2.0db_1bin;%SystemRoot%system32;%SystemRoot%;%SystemRoot%System32Wbem;C:Program FilesJavajdk1.7.0bin;C:Program FilesATI TechnologiesATI.ACECore-Static;C:Program FilesCommon FilesThunder NetworkKanKanCodecs;D:Program FilesTortoiseSVNbin;C:Program FilesMicrosoft SQL Server90Toolsbinn;D:ffmpeg

配的有点多,最后那个就是我的ffmpeg

配置好之后就先在Dos中测试下

打开Dos界面 输入 ffmpeg

如果成功的话会显示好多的命令

如果失败则显示 你输入的不是内部命令之类的。

如果失败就看看自己的环境变量是否配置OK

OK之后先在Dos下测试是否能成功转换

首先在一个目录放入一个视频

我在D盘跟目录放入了Demo.avi 视频,我将要转换为Flv

输入命令:ffmpeg -i D:/Demo.avi  D:/Demo..flv

-i 后面紧跟的是要转换的文件地址 在后是你要把文件转换到哪里以及相对应的文件名和格式

输入命令之后回车,看看相对应的目录是否出现了你需要的转换后的文件。

如果失败检查命令是否错误。

PHP中执行转换的命令

//转换为Flv
function makeFlv($video_file,$flv_file)
{
//判断给定的文件是否正常
if(!is_file($video_file)){
  return false;
}

global $flv_msg;
    $flv_cmd="ffmpeg -i ".$video_file." ".$flv_file;
    exec($flv_cmd,$flv_msg);
}

//创建flv视频的图片
function makeFlvPic($flv_file,$flv_pic_file)
{
global $flv_msg;

    $flv_pic_cmd="ffmpeg -i ".$flv_file.
       " -y -f image2 ".
       " -ss 1 ".
       " -t 0.001 ".
       " -s 350x240 ".$flv_pic_file;

    exec($flv_pic_cmd,$flv_msg);
}

 

 

 

代码
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace WebApplication1
{
    
public class makePic
    {

    
public static string CatchImg(string vFileName)
        {
           
string defPic="images/nopic.gif";//无法生成时显示的图片
    string picPath="UploadImage/" ;//生成图片输出位置
    string movPath="case/";//视频文件位置
            string ffmpeg = HttpContext.Current.Server.MapPath("bin/ffmpeg.exe");
        
            
if (!System.IO.File.Exists(ffmpeg))
            {
                
return defPic;
            }
            
if (!System.IO.File.Exists(HttpContext.Current.Server.MapPath("case/"+vFileName)))
            {
                
return defPic;
            }
          
            
string flv_img =picPath + System.IO.Path.ChangeExtension(vFileName, ".jpg");

            
           
string flv_img_p = HttpContext.Current.Server.MapPath(flv_img);
          
           
if (System.IO.File.Exists(flv_img_p))
            {
                
return flv_img;
            }

            
            
string FlvImgSize = "240x180";

            System.Diagnostics.ProcessStartInfo startInfo 
= new System.Diagnostics.ProcessStartInfo(ffmpeg);
            startInfo.WindowStyle 
= System.Diagnostics.ProcessWindowStyle.Normal;

          
            startInfo.Arguments 
= " -i " + HttpContext.Current.Server.MapPath(movPath+vFileName) + " -y -f image2 -t 10 -s " + FlvImgSize + " " +  flv_img_p;

            
try
            {
                System.Diagnostics.Process.Start(startInfo);
            }
            
catch
            {
                
return defPic;
            }

           
if (System.IO.File.Exists(flv_img_p))
            {
                
return flv_img;
            }

            
return defPic;
        }

}


 

 

posted @ 2010-06-11 01:22 木神易 阅读(196) 评论(0) 编辑
JQuery .Ajax 详解 中文问题

jQuery ajax乱码问题解决

一、测试环境
jQuery:1.3.2
tomcat:5.5.17

二、测试方法

1.使用get方式

服务器端代码:
String name = new String(request.getParameter("name").getBytes("iso8859-1"),"utf-8");

客户端js代码:
  <1>$.ajax({url: "2.jsp",type: "get",data: {name:"中文"},success: function(response){
        alert(response);
        }});
           结果:正确显示

<2>$.ajax({url: "2.jsp",type: "get",data: "name=中文",success: function(response){
        alert(response);
      }});
           结果:乱码

<3>$.get("2.jsp", { name: "中文" },function(response){
    alert(response);
      });
           结果:正确显示

<4>$.get("2.jsp", "name=中文",function(response){
    alert(response);
    });
     结果:乱码


2.post方式

服务器端代码:
request.setCharacterEncoding("UTF-8");  
String name = request.getParameter("name");

客户端js代码:
<1>$.ajax({url: "3.jsp",type: "post",data: "method=testAjaxPost&name=中文",success: function(response){
    alert(response);
     }});
     结果:正确显示

<2>$.ajax({url: "3.jsp",type: "post",data: {name:"中文"},success: function(response){
    alert(response);
     }});
     结果:正确显示

<3>$.post("3.jsp", { name: "中文" },function(response){
    alert(response);
     });
      结果:正确显示

<4>$.post("3.jsp", "name=中文",function(response){
    alert(response);
     });
     结果:正确显示

三、使用filter

public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    if (req.getHeader("X-Requested-With") != null && req.getHeader("X-Requested-With").equalsIgnoreCase("XMLHttpRequest")) {
        request.setCharacterEncoding("utf-8");
    } else {
        request.setCharacterEncoding("gbk");
    }
    chain.doFilter(request, response);
}

      jQuery在使用ajax的时候会在header中加入X-Requested-With,值为:XMLHttpRequest,filter中判断是jQuery的ajax请求时就把字符编码设为utf8,这样可以解决post提交中的中文乱码问题,不需要在代码中设置request.setCharacterEncoding("UTF-8");

对于get方式的中文乱码问题,建议不使用get方式提交中文,统统改为post ^-^

 

      为了和prototype.js处理中文的方式一致,可以使用如下的方式,自定义header中的属性RequestType
$.ajax({
    url: "3.jsp",
    type: "post",
    data: {name:"中文"},
    beforeSend: function(XMLHttpRequest){
        XMLHttpRequest.setRequestHeader("RequestType", "ajax");
        alert("开始");
    },
    success: function(data, textStatus){
        alert(data);
    },
    error: function(XMLHttpRequest, textStatus, errorThrown){
        alert("错误:" + textStatus);
    },
    complete: function(XMLHttpRequest, textStatus){
        alert("完成:" + textStatus);
    }
 });
filter代码如下:
public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    if (req.getHeader("RequestType") != null && req.getHeader("RequestType").equalsIgnoreCase("ajax"))) {
        request.setCharacterEncoding("utf-8");
    } else {
        request.setCharacterEncoding("gbk");
    }
    chain.doFilter(request, response);
}

 

posted @ 2010-06-11 01:16 木神易 阅读(616) 评论(0) 编辑
Copyright ©2012 木神易