<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean name="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean name="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean name="txProxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="get*">
PROPAGATION_REQUIRED,readOnly,-Exception
</prop>
<prop key="query*">
PROPAGATION_REQUIRED,readOnly,-Exception
</prop>
<prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="mdodify*">
PROPAGATION_REQUIRED,-Exception
</prop>
<prop key="del*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">
PROPAGATION_REQUIRED,-Exception
</prop>
</props>
</property>
</bean>
<bean id="VideoDAO" class="com.gcg.video.dao.VideoDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="ScheduleVideoDAO"
class="com.gcg.video.dao.ScheduleVideoDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean name="videoImpl" class="com.gcg.video.service.VideoImpl">
<property name="videoDAO" ref="VideoDAO" />
</bean>
<bean id="videoImplproxy" parent="txProxyTemplate">
<property name="target">
<ref bean="videoImpl" />
</property>
</bean>
<bean id="ScheduleVideoImpl"
class="com.gcg.video.service.ScheduleVideoImpl">
<property name="scheduleVideoDAO" ref="ScheduleVideoDAO" />
</bean>
<bean id="ScheduleVideoImplproxy" parent="txProxyTemplate">
<property name="target">
<ref bean="ScheduleVideoImpl" />
</property>
</bean>
<bean id="ScheduleImpl"
class="com.gcg.video.service.quterz.ScheduleImpl">
<constructor-arg index="0">
<ref bean="videoImplproxy"/>
</constructor-arg>
<constructor-arg index="1">
<ref bean="ScheduleVideoImplproxy"/>
</constructor-arg>
<!-- <property name="videoDAO">
<ref bean="VideoDAO" />
</property>
<property name="scheduleVideoDAO">
<ref bean="ScheduleVideoDAO" />
</property> -->
</bean>
<bean id="ScheduleImplproxy" parent="txProxyTemplate">
<property name="target">
<ref bean="ScheduleImpl" />
</property>
</bean>
<!-- <bean id="convertVideoTask class="org.springframework.scheduling.">
<property name="targetObject">
<ref bean="ScheduleImplproxy" />
</property>
<property name="targetMethod">
<value>converVedio</value>
</property>
</bean>-->
<bean id="convertVideoTask"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="ScheduleImplproxy" />
</property>
<property name="targetMethod">
<value>converVedio</value>
</property>
</bean>
<bean id="cronTrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="convertVideoTask" />
</property>
<property name="cronExpression">
<!-- 每天 11:56 触发 -->
<value>0 56 11 * * ?</value>
</property>
</bean>
<bean autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="cronTrigger" />
</list>
</property>
</bean>
<bean name="/upload"
class="com.gcg.video.struts.action.UploadAction">
<property name="scheduleVideo">
<ref bean="ScheduleVideoImplproxy" />
</property>
</bean>
</beans>
package com.gcg.video.service.quterz;
import com.gcg.video.dao.ScheduleVideoDAO;
import com.gcg.video.dao.VideoDAO;
import com.gcg.video.entity.ScheduleVideo;
import com.gcg.video.entity.Video;
import com.gcg.video.service.IVideo;
import com.gcg.video.service.IscheduleVideo;
import com.gcg.video.utils.ChangPathInfo;
import com.gcg.video.utils.SysPath;
import com.gcg.video.utils.Win_ffmpeg;
public class ScheduleImpl {
private static IVideo videoService;
private static IscheduleVideo scheduleVideoService;
public ScheduleImpl(){
}
public ScheduleImpl(IVideo videoService, IscheduleVideo scheduleVideoService){
this.videoService = videoService;
this.scheduleVideoService = scheduleVideoService;
}
public static void main(String[] args){
// String test = "E:/apache-tomcat-6.0.26/webapps/VideoDemo/uncovert/heh";
// //test.replace('/', '\\');
// //test.replaceAll("/^\\*&/", "\\");
// //test.replaceAll(regex, replacement)
// char [] array = test.toCharArray();
// for(int i=0;i<array.length;++i){
// if(array[i] == '/'){
// array[i] ='\\';
// }
//
// }
//
//System.out.println(new String(array));
}
public static synchronized void converVedio()
throws RuntimeException {
// TODO Auto-generated method stub
try {
ScheduleVideo scheduleVideo = scheduleVideoService.getEarlySchedule();
while(scheduleVideo != null){
String videoName = scheduleVideo.getScSourcePath();
String postfix = videoName.substring(videoName.lastIndexOf('.') + 1,videoName.length());
String wantPath = SysPath.getPath();
String fromPath = wantPath + "/unconvert/" + videoName;
fromPath = ChangPathInfo.change(fromPath);
System.out.println(fromPath);
System.out.println(postfix);
String converName = videoName.substring(0,videoName.lastIndexOf('.')+1)+"flv";
String toPath = wantPath + "/convert/" + converName;
toPath = ChangPathInfo.change(toPath);
System.out.println(toPath);
// String fromPath = "unconvert/"
String pattern = "300*200";
System.out.println(Win_ffmpeg.isValidPatter(postfix));
if(Win_ffmpeg.isValidPatter(postfix)){
if(Win_ffmpeg.conver(fromPath, toPath, pattern)==0){
String VImgPath = Win_ffmpeg.getConverVideoImg(fromPath);
if(VImgPath != null){
videoService.addVideo(new Video(videoName ,videoName,scheduleVideo.getScUploadDate(),VImgPath) );
scheduleVideo.setScState(0L);
scheduleVideoService.updateScheduleVideo(scheduleVideo);
}
}
}
scheduleVideo = scheduleVideoService.getEarlySchedule();
}
} catch (RuntimeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw e;
}
}
public IVideo getVideoService() {
return videoService;
}
public void setIdeoService(IVideo ideoService) {
videoService = ideoService;
}
public IscheduleVideo getScheduleVideoService() {
return scheduleVideoService;
}
public void setScheduleVideoService(IscheduleVideo scheduleVideoService) {
scheduleVideoService = scheduleVideoService;
}
}
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.gcg.video.struts.action;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.MappingDispatchAction;
import com.gcg.video.entity.ScheduleVideo;
import com.gcg.video.service.IscheduleVideo;
import com.gcg.video.utils.UUIDString;
public class UploadAction extends MappingDispatchAction {
private IscheduleVideo scheduleVideo;
public ActionForward upload(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
//System.out.println(request.getSession().getServletContext().getRealPath("/")+"unconvert"+System.getProperty("file.separator"));
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(1024 * 1024 * 2);
factory.setRepository(new File(request.getSession().getServletContext().getRealPath("/")+System.getProperty("file.separator")+"unconvert"));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(1024 * 1024 * 200);
String upLoadVideoName = null;
List items = upload.parseRequest(request);
//System.out.println(items.size());
for (Iterator it = items.iterator(); it.hasNext() ; )
{
FileItem item = (FileItem)it.next();
if (item.isFormField())
{
String name = item.getFieldName();
String value = item.getString("UTF-8");
//out.println("表单域的name=value对为:" + name + "=" + value);
//System.out.println(name + "=" + value);
}
else
{
String fieldName = item.getFieldName();
String fileName = item.getName();
String contentType = item.getContentType();
//System.out.println(contentType);
upLoadVideoName = UUIDString.getUUID() + fileName.substring(fileName.lastIndexOf(".") , fileName.length());
FileOutputStream fos = new FileOutputStream( request.getSession().getServletContext().getRealPath("/") + "unconvert" + System.getProperty("file.separator") +
upLoadVideoName);
// System.out.println(request.getSession().getServletContext().getRealPath("/") + "unconvert"+System.getProperty("file.separator") +
// upLoadVideoName);
if (item.isInMemory() )
{
fos.write(item.get());
}
else
{
InputStream is = item.getInputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = is.read(buffer)) > 0 )
{
fos.write(buffer , 0 , len);
}
is.close();
fos.close();
}
}
}
scheduleVideo.addScheduleVideo(new ScheduleVideo(upLoadVideoName, 1L, new java.util.Date()) );
return mapping.findForward("success");
}
public IscheduleVideo getScheduleVideo() {
return scheduleVideo;
}
public void setScheduleVideo(IscheduleVideo scheduleVideo) {
this.scheduleVideo = scheduleVideo;
}
CREATE SEQUENCE SEQ_VIDEO INCREMENT BY 1 NOMINVALUE NOMAXVALUE CACHE 20 NOCYCLE NOORDER;
CREATE SEQUENCE SEQ_SCHEDULE_VIDEO INCREMENT BY 1 NOMINVALUE NOMAXVALUE CACHE 20 NOCYCLE NOORDER;
CREATE TABLE VIDEO
(
V_ID NUMBER(10) ,
V_NAME VARCHAR2(100) NOT NULL ,
V_PATH VARCHAR2(200) NOT NULL,
V_UPLOAD_DATE DATE DEFAULT SYSDATE NOT NULL ,
V_IMG_PATH VARCHAR2(200) NOT NULL
)
CREATE TABLE SCHEDULE_VIDEO
(
SC_ID NUMBER(10),
SC_SOURCE_PATH VARCHAR2(200) NOT NULL,
SC_STATE NUMBER(1) NOT NULL,
SC_UPLOAD_DATE DATE DEFAULT SYSDATE NOT NULL
)
ALTER TABLE VIDEO ADD CONSTRAINTS PK_VIDEO PRIMARY KEY (V_ID);
ALTER TABLE SCHEDULE_VIDEO ADD CONSTRAINTS PK_SC_VIDEO PRIMARY KEY( SC_ID);
ALTER TABLE SCHEDULE_VIDEO ADD CONSTRAINTS CK_SC_VIDEO CHECK (SC_STATE IN (-1,0,1));
package com.gcg.video.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
public class Win_ffmpeg {
private static final Logger logger =Logger.getLogger(Win_ffmpeg.class);
private static final String[] PATTER = {"mpg", "asf", "avi", "mp4", "wav", "mp4", "dv"};
//private static final String[] MenCode = {"rmvb" ,"rm"};
public static boolean isValidPatter(String patter){
boolean result = false;
if(patter == null || patter.length() < 2){
logger.error("参数非法");
throw new IllegalArgumentException("视频参数非法") ;
}
patter = patter.trim().toLowerCase();
for(String t : PATTER){
if(t.equals(patter)){
result = true;
}
}
return result;
}
synchronized public static String getConverVideoImg(String fromPath){
if(fromPath==null||fromPath.length()<2){
logger.error("参数非法");
throw new IllegalArgumentException("视频参数非法") ;
}
String imgName = UUIDString.getUUID() + ".jpg";
String imgPath = SysPath.getPath()+"/preview/" + imgName;
imgPath = ChangPathInfo.change(imgPath);
Process process = null;
StringBuilder message = new StringBuilder();
List<String> commandList = new ArrayList<String>();
commandList.add("D:\\ffmpeg_full_SDK_V3.0\\Libs\\ffmpeg.exe");
commandList.add("-i");
commandList.add(fromPath);
commandList.add("-y");
commandList.add("-f");
commandList.add("image2");
commandList.add("-ss");
commandList.add("60");
commandList.add("-vframes");
commandList.add("1");
commandList.add(imgPath);
ProcessBuilder builder = new ProcessBuilder(commandList);
int status = -1;
try {
process = builder.start();
builder.redirectErrorStream(true);
//builder.directory();
process = builder.start();
BufferedReader in = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
message.append(line + System.getProperty("line.separator"));
}
status = process.waitFor();
} catch (IOException e) {
// TODO Auto-generated catch block
logger.error("IOException");
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.error("ThreadException");
}
if (status == 0){
logger.debug("convert success");
return imgName;
}
else{
logger.error("convert failture");
}
return null;
}
synchronized public static int conver(String fromPath, String toPath, String pattern){
if(fromPath==null||fromPath.length()<2||toPath==null||toPath.length()<2||pattern==null||pattern.length()<7){
logger.error("参数非法");
throw new IllegalArgumentException("视频参数非法") ;
}
Process process = null;
StringBuilder message = new StringBuilder();
List<String> commandList = new ArrayList<String>();
commandList.add("D:\\ffmpeg_full_SDK_V3.0\\Libs\\ffmpeg.exe");
commandList.add("-i");
commandList.add(fromPath);
commandList.add("-ab");
commandList.add("56");
commandList.add("-ar");
commandList.add("22050");
commandList.add("-b");
commandList.add("500");
commandList.add("-r");
commandList.add("15");
commandList.add("-s");
commandList.add(pattern);
commandList.add(toPath);
ProcessBuilder builder = new ProcessBuilder(commandList);
int status = -1;
try {
process = builder.start();
builder.redirectErrorStream(true);
//builder.directory();
process = builder.start();
BufferedReader in = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
message.append(line + System.getProperty("line.separator"));
}
status = process.waitFor();
} catch (IOException e) {
// TODO Auto-generated catch block
logger.error("IOException");
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.error("ThreadException");
}
if (status == 0){
logger.debug("convert success");
}
else{
logger.error("convert failture");
}
return status;
}
}
分享到:
相关推荐
在Android平台上,开发一款视频播放器是常见的任务,而`VideoDemo.rar`提供的就是一个使用`VideoView`控件实现的简单视频播放器示例。在这个项目中,开发者自定义了`MediaController`来提供更个性化的用户体验。接...
在"VideoDemo"这个项目中,主要涉及以下几个关键知识点: 1. **Agora SDK集成**:首先,你需要在项目中引入Agora的SDK,通常通过Gradle或CocoaPods进行依赖管理。对于Android,需要在build.gradle文件中添加依赖;...
"video demo"可能是一个展示如何使用video.js库创建和控制视频播放的示例项目。video.js是一个流行的开源JavaScript和CSS库,专为增强HTML5视频体验而设计,提供了丰富的自定义选项和跨浏览器兼容性。 在视频播放...
标题中的"videodemo_DEMOapp下载_DEMO_视频demo_"表明这是一个关于视频演示应用程序的DEMO版本,可能是一个供用户试用或开发者参考的简化版软件。这个DEMO app专注于视频流处理,可能是用于展示如何接收和播放网络...
总之,"VideoDemo.zip"中的项目很可能提供了一个在H5页面上实现RTMP播放的实例,通过`<video>`标签和定制的JavaScript代码,实现了对实时流媒体的支持。这种技术在在线教育、新闻直播、游戏直播等领域有着广泛的应用...
"videodemo.zip"是一个压缩包文件,其中包含了一个示例项目,用于演示如何实现在播放视频时,通过手势来监听并执行如调节音量和屏幕亮度等操作。下面将详细介绍这个项目可能涉及的知识点。 1. 触摸监听(Touch ...
"videoDemo.zip"压缩包中包含的"onlineVideo"项目,正是一个基于MVVM架构的在线视频应用实例,它充分展示了MVVM如何在实际项目中提升开发效率和代码可维护性。 MVVM的核心思想是解耦视图(View)与模型(Model),...
【VideoDemo: 测试】 VideoDemo 是一个专为Android Studio设计的示例项目,它演示了如何在Android设备上实现视频播放功能。这个项目适用于初学者和开发者,他们希望了解如何在自己的应用中集成视频播放功能。...
简单明了,适合初学者。采用了最最简单初级的技术, python101
"video-js 播放器demo" 是一个基于HTML5技术构建的开源视频播放器解决方案,主要用于在网页上实现高质量的视频播放体验。这个播放器兼容多种浏览器,包括对Internet Explorer 9及以下版本的支持,通过Flash技术确保...
《基于SpringBoot调用百度API视频审核的实战指南》 在现代互联网应用中,内容审核是必不可少的一环,尤其在视频分享平台。本教程将详细讲解如何利用SpringBoot框架调用百度API进行视频审核,确保内容合规性。...
《videojs深度解析与实战应用》 视频在现代互联网中的地位日益重要,各种视频平台的兴起使得视频播放技术成为开发者必须掌握的一项技能。video.js是一个强大的开源HTML5视频播放器库,它提供了一套优雅的API和丰富...
videoDemo 一个小程序的demo 该项目是是用小程序做的一个模板。一些小程序中常用的组件做,为了以后方便小程序的开发 Author 梦魇 E-mail 主要页面 1.首页 -index 1.1 轮播图 1.2 水平滚动视图区域。 1.3 上拉加载 ...
这是一个基于Web的多媒体上传与处理的项目,名为"VideoDemo"。该项目采用了多个技术栈,包括前端的jQuery File Upload、Bootstrap,后端的Spring MVC、Hibernate、MyBatis以及视频处理工具ffmpeg。以下是对这些技术...
本资源包含VideoJs的包文件以及一个经过优化的演示Demo,允许你在本地直接运行播放视频。 ### 1. VideoJs简介 VideoJs是一个强大的跨浏览器、跨设备的JavaScript和CSS库,用于构建用户友好的、交互式的HTML5视频...
本篇将深入探讨video.js的使用,并结合"video.js demo.zip"中的示例,带你领略其魅力。 1. **video.js简介** video.js是一个基于JavaScript和CSS的开源HTML5视频播放器,它提供了一套统一的API和用户界面,使...
【Android Video Camera Demo】是一个专为开发者设计的实践项目,旨在帮助他们理解和掌握Android平台上的摄像头API,特别是视频录制功能。这个Demo展示了如何利用Android SDK中的相关类来创建一个简单的应用,用户...