`
jiataibin
  • 浏览: 41606 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

JSP上传视频后自动转成flv的核心JAVA方法

阅读更多
(转)JSP上传视频后自动转成flv的核心JAVA方法
摘要

作者:古刹飞鹰

BLOG:www.v246.com

QQ:28095553

Email:aquaqu(圈.a)gmail.com

本文属古刹飞鹰原创,转载请注明出处!

以下是源码:



【全文】

作者:古刹飞鹰

BLOG:www.v246.com

QQ:28095553

Email:aquaqu(圈.a)gmail.com

本文属古刹飞鹰原创,转载请注明出处!

本方法以经经过实战验证,正在项目中使用,稍后您可以查看:http://www.0431net.com,网站的视频模快的核心功能就是用这个方法实现的:)

以下是源码:

Cnvert 类

package com.v246.convertFLV;


import java.util.ArrayList;
import java.util.List;


import com.v246.utils.Aqu;

//作者:古刹飞鹰 blog:www.v246.com懒汉模式
public class Convert {

private static Convert instance = null;

//作者:古刹飞鹰 blog:www.v246.com flv截图工具的绝对地址
private String aquInterceptPicToolsPath = "c:\\FLVTools\\ffmpeg.exe";

//作者:古刹飞鹰 blog:www.v246.com flv修复工具的绝对地址
private String fixFLVToolsPath = "c:\\FLVTools\\flvmdi.exe";

//作者:古刹飞鹰 blog:www.v246.com flv转换工具的绝对地址
private String aquCoverFLVToolsPath = "c:\\FLVTools\\mencoder\\mencoder.exe";

private Convert() {
  //作者:古刹飞鹰 blog:www.v246.cominit();
}

public static Convert getInstance() {
  if (instance == null) {
   instance = new Convert();
  }
  return instance;
}
public void reset(){
  //作者:古刹飞鹰 blog:www.v246.cominit();
}
private void init() {
  /*aquInterceptPicToolsPath = Aqu.getXMLValue("convertFLV.xml",
    "//作者:古刹飞鹰 blog:www.v246.com古刹飞鹰/FLV转换工具全路径")[0];
  fixFLVToolsPath = Aqu
    .getXMLValue("convertFLV.xml", "//作者:古刹飞鹰 blog:www.v246.com古刹飞鹰/FLV截图工具全路径")[0];
  aquCoverFLVToolsPath = Aqu.getXMLValue("convertFLV.xml",
    "//作者:古刹飞鹰 blog:www.v246.com古刹飞鹰/FLV修复工具全路径")[0];
  aquInterceptPicToolsPath = aquInterceptPicToolsPath.replace("/", "\\");
  fixFLVToolsPath = fixFLVToolsPath.replace("/", "\\");
  aquCoverFLVToolsPath = aquCoverFLVToolsPath.replace("/", "\\");
  System.out.println(aquInterceptPicToolsPath);
  System.out.println(fixFLVToolsPath);
  System.out.println(aquCoverFLVToolsPath);*/

}

public synchronized boolean convert(String aquInputPath, String outPath) {
  boolean re = false;
  //作者:古刹飞鹰 blog:www.v246.com 通一路径定位符
  aquInputPath = aquInputPath.replace("/", "\\");
  //作者:古刹飞鹰 blog:www.v246.com 通一路径定位符
  outPath = outPath.replace("/", "\\");
  //作者:古刹飞鹰 blog:www.v246.com 分析不包含文件名的输出路径
  String interceptPicSavePath = outPath.substring(0, outPath
    .lastIndexOf("\\") + 1);
  //作者:古刹飞鹰 blog:www.v246.com 分析输出的文件名
  String outFileName = outPath.substring(outPath.lastIndexOf("\\") + 1,
    outPath.length());
  //作者:古刹飞鹰 blog:www.v246.com 继续分析得出不包含扩展名的文件名
  String outFileNameNoExt = outFileName.substring(0, outFileName
    .lastIndexOf("."));

  //作者:古刹飞鹰 blog:www.v246.com 工作目录,随便设置
  //作者:古刹飞鹰 blog:www.v246.com String workdirectory = "c:\\windows\\temp";
  //作者:古刹飞鹰 blog:www.v246.com 修复命令
  List<String> parameterForFix = new ArrayList<String>(100);
  //作者:古刹飞鹰 blog:www.v246.com 转换命令
  List<String> aquParameterForConvert = new ArrayList<String>(100);
  //作者:古刹飞鹰 blog:www.v246.com 截图命令
  List<String> aquParameterForIntercept = new ArrayList<String>(100);
  //作者:古刹飞鹰 blog:www.v246.com 构建转换命令
  aquParameterForConvert.add(aquCoverFLVToolsPath);
  aquParameterForConvert.add("-vf");
  aquParameterForConvert.add("scale=320:240");
  aquParameterForConvert.add("-ffourcc");
  aquParameterForConvert.add("FLV1");
  aquParameterForConvert.add("-of");
  aquParameterForConvert.add("lavf");
  aquParameterForConvert.add("-lavfopts");
  aquParameterForConvert
    .add("i_certify_that_my_video_stream_does_not_use_b_frames");
  aquParameterForConvert.add("-ovc");
  aquParameterForConvert.add("lavc");
  aquParameterForConvert.add("-lavcopts");
  aquParameterForConvert.add("vcodec=flv:vbitrate=200");
  aquParameterForConvert.add("-srate");
  aquParameterForConvert.add("22050");
  aquParameterForConvert.add("-oac");
  aquParameterForConvert.add("lavc");
  aquParameterForConvert.add("-lavcopts");
  aquParameterForConvert.add("acodec=mp3:abitrate=56");
  aquParameterForConvert.add(aquInputPath);
  aquParameterForConvert.add("-o");
  aquParameterForConvert.add(outPath);

  //作者:古刹飞鹰 blog:www.v246.com 构建修复命令
  parameterForFix.add(fixFLVToolsPath);
  parameterForFix.add(outPath);
  //作者:古刹飞鹰 blog:www.v246.com 构建截图命令
  aquParameterForIntercept.add(aquInterceptPicToolsPath);
  aquParameterForIntercept.add("-i");
  aquParameterForIntercept.add(outPath);
  aquParameterForIntercept.add("-y");
  aquParameterForIntercept.add("-f");
  aquParameterForIntercept.add("image2");
  aquParameterForIntercept.add("-ss");
  aquParameterForIntercept.add("8");
  aquParameterForIntercept.add("-t");
  aquParameterForIntercept.add("0.001");
  aquParameterForIntercept.add("-s");
  aquParameterForIntercept.add("320x240");
  aquParameterForIntercept.add(interceptPicSavePath + outFileNameNoExt
    + ".jpg");
  //作者:古刹飞鹰 blog:www.v246.com转换
  String tmp1 = Aqu.exec(aquParameterForConvert);
  //作者:古刹飞鹰 blog:www.v246.com截图
  String tmp2 = Aqu.exec(aquParameterForIntercept);
  return re;
}

public static void main(String[] args) {
  getInstance().convert("h:\\QQ28095553\\古刹飞鹰.wmv", "h:\\aquaqu(quana)gmail.com\\古刹飞鹰.flv");
}
}

ConvertThread 类

package com.v246.convertFLV;

public class ConvertThread extends Thread{

private String fromPath = null;
private String toPath = null;
@Override
public void run(){
  Convert.getInstance().convert(fromPath, toPath);
}
public void setFromPath(String fromPath) {
  this.fromPath = fromPath;
}
public void setToPath(String toPath) {
  this.toPath = toPath;
}
}



ConvertThreadProxy类:

package com.v246.convertFLV;

public class ConvertThreadProxy {
public static void convert(String fromPath, String toPath) {
  ConvertThread ct = new ConvertThread();
  ct.setFromPath(fromPath);
  ct.setToPath(toPath);
  ct.start();
}
}





使用的时候只要通过ConvertThreadProxy 类的静态方法将源视频绝对地址(包括文件名+括展名)和要生成的FLV文件的绝对地址(包括文件名+括展名)以字符串的方式传进去即可!因为用的是多线程,所以转换过程不会占用当前线程!

核心转换类是线程同步的,所以您不用担心并法问题,因为一次只能转换一个文件!

注:安装和使用ffmpeg转换视频为flv文件(windows和linux)
用java程序调用ffmpeg执行视频文件格式转换flv 

分享到:
评论
3 楼 七夜寒星 2010-04-26  
楼主可以加我吗?QQ:330936779,我想要你这个源代码!我们最近的做一个关于此项目的东西~~
2 楼 stta04 2008-08-25  
楼主,可以把 Aqu类的源代码贴上来共享一下吗?我做的项目里也要实现这个功能,但是当先转换后截图,总无法实现同步。
1 楼 Jatula 2008-07-11  
其它格式转成wmv有没有办法?

相关推荐

    jsp上传视频自动转换为flv 算法

    jsp上传视频自动转换为flv 的算法,使用的时候只要通过ConvertThreadProxy 类的静态方法将源视频绝对地址(包括文件名+括展名)和要生成的FLV文件的绝对地址(包括文件名+括展名)以字符串的方式传进去即可!...

    在jsp中嵌入flv视频播放器

    本文将深入探讨如何在JSP(JavaServer Pages)页面中嵌入FLV格式的视频播放器,实现类似视频播放网站的功能。通过分析提供的代码示例,我们将理解其中的关键技术点,并学习如何在自己的项目中应用这些技术。 ### 一...

    基于javaweb+jsp的flv视频播放程序

    【标题】:“基于javaweb+jsp的flv视频播放程序” 这个项目是关于使用JavaWeb和JSP技术实现一个FLV(Flash Video)格式的视频播放器。在Web开发中,提供视频流服务是一项常见的需求,而FLV是早期广泛用于网页视频的...

    JSP文件上传视频和源代码

    在Java服务器页面(JSP)开发中,文件上传是一个常见的需求,例如用户可能需要上传视频、图片或者其他文档。本教程将深入讲解如何在JSP中实现视频文件的上传功能,并提供相关的源代码供学习和参考。 一、JSP文件...

    JAVA JSP教学视频点播系统 源代码

    【JAVA JSP教学视频点播系统】是一种基于Java技术的在线教育平台,它结合了JSP(JavaServer Pages)和Servlet技术,为用户提供了一个交互式的视频学习环境。这个系统涵盖了视频管理、会员管理、留言管理和系统管理等...

    jsp上传组件下载,内含两个核心java类

    本篇将详细介绍标题为"jsp上传组件下载,内含两个核心java类"的知识点,以及描述中提到的源代码组件。 该组件主要关注的是文件上传功能的实现,其核心在于提供的两个Java类:`upBean.java`和`Request.java`。这两个...

    jsp实现视频播放

    7. **视频编码与转码**:不同的设备和浏览器可能支持不同的视频格式,所以视频上传后可能需要进行转码,确保所有用户都能播放。 8. **安全控制**:对视频访问进行权限控制,例如只有登录用户才能观看某些视频,或者...

    java+jsp上传文件

    最后,根据`struts-config.xml`中的配置,当文件成功上传后,用户会被重定向到`success.jsp`,显示上传成功的消息;如果发生错误,则会跳转到`error.jsp`,显示错误信息。 总的来说,Java和JSP结合Struts实现文件...

    kindeditor(jsp版)视频上传

    4. **安装七牛Java SDK**:在你的服务器端,需要集成七牛Java SDK,以便处理视频上传的请求,验证身份,将文件保存到七牛云,并返回保存后的URL给KindEditor。 5. **编写服务器端处理程序**:使用七牛Java SDK,...

    动态Jsp页面转换成静态Html页面

    在Java EE开发中,动态网页技术如JSP(JavaServer Pages)被广泛用于构建交互式Web应用程序。然而,为了提高网站性能,降低服务器负载,并优化搜索引擎优化(SEO),经常需要将动态JSP页面转换为静态HTML页面。这个...

    ckeditor配置上传视频

    最后配置视频上传路径的URL路径,也就是POST上传文件的地址:config.filebrowserFlvPlayerUploadUrl = '/ckeditor/upload_json.ashx?dir=media',注意一定要是filebrowserFlvPlayerUploadUrl,这里要对应flvPlayer...

    java+jsp实现上传下载对话框

    此外,JSP脚本会调用`UploadXml.java`中的方法来处理提交的表单数据,同时可能通过jspsmart库提供上传进度和错误处理的反馈。 在实际应用中,为了确保安全性,还需要考虑以下几点: - 文件名的安全过滤:防止恶意...

    java宏软JSP上传系统.zip

    java宏软JSP上传系统java宏软JSP上传系统java宏软JSP上传系统java宏软JSP上传系统java宏软JSP上传系统java宏软JSP上传系统java宏软JSP上传系统java宏软JSP上传系统java宏软JSP上传系统java宏软JSP上传系统java宏软...

    FCKeditor添加FLV视频和上传文件自动更名

    FCKeditor(jsp版本)目录文件,FCKeditor.jar包,增加FCKeditor添加FLV视频功能和FCKeditor上传文件自动更名功能 1.修正了上传中文文件乱码的问题,上传之后会重命名文件 2.修正了不能上传FLV视频的问题

    在java中,如何jsp查询结果转成excel

    在java中,如何jsp查询结果转成excel

    java项目之ExtJS 2.2 开源网络硬盘系统(jsp上传下载).zip

    java项目之ExtJS 2.2 开源网络硬盘系统(jsp上传下载)java项目之ExtJS 2.2 开源网络硬盘系统(jsp上传下载)java项目之ExtJS 2.2 开源网络硬盘系统(jsp上传下载)java项目之ExtJS 2.2 开源网络硬盘系统(jsp上传...

    Java基于jsp的在线视频教育系统的实现.zip

    Java基于jsp的在线视频教育系统的实现.zipJava基于jsp的在线视频教育系统的实现.zipJava基于jsp的在线视频教育系统的实现.zipJava基于jsp的在线视频教育系统的实现.zipJava基于jsp的在线视频教育系统的实现.zipJava...

    jsp在ie 火狐 360 搜狗等浏览器播放Flv格式视频。

    本示例主要关注如何使用JSP(JavaServer Pages)技术,在IE、火狐、360和搜狗等常见浏览器上播放FLV(Flash Video)格式的视频。FLV是Adobe Flash Player支持的一种流媒体格式,广泛应用于在线视频内容的传输。 ...

    FCKeditor java版安装和flv插件

    本文将详细介绍如何在Java环境中安装FCKeditor,并添加FLV视频播放插件。 **一、FCKeditor Java版的安装** 1. **下载FCKeditor**:首先,你需要从FCKeditor的官方网站或者第三方资源网站下载Java版本的FCKeditor。...

    jsp视频播放jsp视频播放代码和实现

    "jsp视频播放"是这个话题的核心,它涉及到如何在网页上实现视频的播放功能。下面我们将详细探讨JSP视频播放的原理、实现方式以及可能涉及的相关技术。 1. **视频播放原理**: 视频播放主要依赖于浏览器支持的视频...

Global site tag (gtag.js) - Google Analytics