`
雨中伞
  • 浏览: 42316 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

VIDEO DEMO

    博客分类:
  • SSH
阅读更多
<?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;
	}
} 
分享到:
评论

相关推荐

    video demo

    video demo

    VideoDemo.rar

    Android视频播放器,使用VideoView控件实现播放,自定义MediaController,是一款不错的Android播放器

    VideoDemo Agora视频通话1-1

    声网Agora集成视频通话1-1,只有集成1-1视频通话的代码,清晰易懂

    videoDemo.py

    简单明了,适合初学者。采用了最最简单初级的技术, python101

    VideoDemo:测试

    VideoDemo 本项目是一个在Android studio上搭建的一个播放视频的demo Android版本23,gradle版本1.3.0

    videodemo_DEMOapp下载_DEMO_视频demo_

    拉流视频demo的压缩包资源,主要是窗体应用,系统比较老了,可以尝试调试

    video-demo.zip

    基于springboot调用百度api视频审核demo,需要将对应ak和sk替换为自己申请的ak,sk,启动方法,启动springBoot后调用main方法

    VideoDemo.zip

    h5支持rtmp的网页播放器,video标签,亲测有效。

    videodemo.zip

    简易的本地视频播放器,用qt写的,适合刚学者

    videoDemo.zip

    MVVM 就是将其中的View 的状态和行为抽象化,让我们将视图 UI 和业务逻辑分开。这个是OnlineVideo最新代码

    videoDemo:一个小程序的上传视频的demo

    videoDemo 一个小程序的demo 该项目是是用小程序做的一个模板。一些小程序中常用的组件做,为了以后方便小程序的开发 Author 梦魇 E-mail 主要页面 1.首页 -index 1.1 轮播图 1.2 水平滚动视图区域。 1.3 上拉加载 ...

    videojs 使用Demo

    videojs 使用Demo

    video.js demo.zip

    video.js 使用demo

    ffmpeg_encode_video_demo.c例子

    FFmpeg是领先的多媒体框架,能够解码,编码, 转码,复用,解复用,流,过滤和播放人类和机器创造的任何东西(ffmpeg encode video demo.c)

    video.js使用常用方法110行demo源程序资源

    video.js常用方法使用demo

    Android Video Demo

    一个最简单的Android camera录像的Demo代码,适用用于熟悉camera部分的API

    ffmpeg_decode_video_demo.c例子

    FFmpeg是领先的多媒体框架,能够解码,编码, 转码,复用,解复用,流,过滤和播放人类和机器创造的任何东西(ffmpeg decode video demo.c)

Global site tag (gtag.js) - Google Analytics