JavaWeb实现视频在线播放



  • video.js实现视频在线播放(支持MP4、webm、ogg三中格式)
<%@ page language="java" contentType="text/html; charset=UTF-8"  
    pageEncoding="UTF-8"%>  
<%  
    String swfFilePath=session.getAttribute("document_url").toString();  
%>  




Video.js 6.2.8
	 	
	 
	 
	
		
		



	

  • ffmpeg把上传的视频格式转换为MP4格式(并添加水印)
import java.util.ArrayList;  
import java.util.List;  

public class ConvertVideo {	
    /**  
     * 视频转码 (PC端MP4) 
     * @param ffmpegPath    转码工具的存放路径 
     * @param upFilePath    用于指定要转换格式的文件,要截图的视频源文件 
     * @param codcFilePath    格式转换后的的文件保存路径 
     * @return  
     * @throws Exception  
     */    
    public static boolean exchangeToMp4(String ffmpegPath, String upFilePath, String codcFilePath) throws Exception {    
        // 创建List集合来保存转换视频文件为flv格式的命令   
        List convert = new ArrayList();    
        convert.add(ffmpegPath); // 添加转换工具路径    
        convert.add("-y"); // 该参数指定将覆盖已存在的文件    
        convert.add("-i");  
        convert.add(upFilePath);  
        convert.add("-c:v");  
        convert.add("libx264");  
        convert.add("-c:a");  
        convert.add("aac");  
        convert.add("-strict");  
        convert.add("-2");  
        convert.add("-pix_fmt");  
        convert.add("yuv420p");  
        convert.add("-movflags");  
        convert.add("faststart");  
        convert.add("-vf");   // 添加水印  
        //convert.add("movie=logosmall.png[wm];[in][wm]overlay=20:20[out]");  
        convert.add("movie=D\\\\:/conver/ffmpeg/tonghua.png[wm];[in][wm]overlay=10:main_h-overlay_h-10[out]");
        convert.add(codcFilePath);    
    
        boolean mark = true;    
                  
        try {    
            Process videoProcess = new ProcessBuilder(convert).redirectErrorStream(true).start();              
            new PrintStream(videoProcess.getInputStream()).start();                          
            //videoProcess.waitFor();  // 加上这句,系统会等待转换完成。不加,就会在服务器后台自行转换。  
              
        } catch (Exception e) {    
            mark = false;    
            System.out.println(e);    
            e.printStackTrace();    
        }    
        return mark;    
    }   


    
   
    public static void main(String s[]) {  
    	try {   		
			exchangeToMp4("D:\\conver\\ffmpeg\\ffmpeg.exe","E:\\updouad\\01.flv","E:\\updouad\\011213.mp4");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
}


你可能感兴趣的:(Java)