2013年12月1日星期日

JSP to do video streaming server online play AVI, MP4, WMV format , Jiqiu ! ! !

Brother came first use JSP to do online video , you need to play format AVI, MP4, WMV , etc. ( the server where it has been stored in several formats , and follow-up there are people uploading more video files through the project structure CS project CS I can not modify the structure , in order to achieve can only assume that the video playback pages of the TOMCAT)

Problem: MEDIA PLAYER should be able to play WMV can be buffered while playing side , but not AVI format .

ideas: that is the question , and AVI decoder does not support streaming . Baidu also used tools such as audio and video playback, but even WMV format also need to complete before you can download the entire broadcast it.


Question: Baidu many online audio and video formats such as AVI and Nora , etc. can be buffered while playing side , they need to assume a streaming media server ?

I am now the environment is mapped to the path TOMCAT video folder, and then call the JSP page video URL.

Great God please help analyze and provide some ideas. Online extremely grateful !
------ Solution ---------------------------------------- ----
use streaming media . Use ffmpeg transcoding.
Players this , I have done : http://flowplayer.org/tools/demos/
------ Solution --------------------------------------------
not a player problem ! You want to convert all your back into flv format video format . Now basically large online video websites are flv format. I said above with ffmpeg can convert flv format. api or exe can do . Study after yourself , turn into basically use a flash flv player can change download becomes put , and easily drag .

I wrote a straight Converter, you can refer to the following

package com.cemso.util;

import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class VideoConverter {

        private final static String BASE_PATH = FileOperationTool.DEFAULT_VIDEO_DES_PATH;
        private final static String FLV_PATH = FileOperationTool.DEFAULT_FLV_PATH;
        private static String PATH = "";
        private static String FILE_NAME = "";
        
        private static final Log log = LogFactory.getLog(com.cemso.util.VideoConverter.class);

        public static boolean convert(String fileName) {
                PATH = BASE_PATH + fileName;
                FILE_NAME = fileName;
                if(log.isDebugEnabled()){
                        log.debug("start to convert video to flv format...");
                        log.debug("the file name is : " + FILE_NAME);
                        log.debug("the file path is : " + PATH);
                }

                if (!checkfile(PATH)) {
                        return false;
                } else {
                        if (process()) {
                                if(log.isDebugEnabled()){
                                        log.debug("process() ok");
                                }
                                return true;
                        } else {
                                return false;
                        }
                }
        }

        private static boolean process() {
                int type = checkContentType();
                boolean status = false;
                if (type == 0) {
                        if(log.isDebugEnabled()){
                                log.debug("Start to convert to flv file");
                        }
                        status = processFLV(PATH);// 直接将文件转为flv文件
                } else if (type == 1) {
                        String avifilepath = processAVI(type);
                        if (avifilepath == null){
                                return false;// avi文件没有得到
                        }
                        status = processFLV(avifilepath);// 将avi转为flv
                } else if(type == 9){
                        if(log.isDebugEnabled()){
                                log.debug("this file is no need to convert.");
                        }
                        return false;
                }
                return status;
        }

        private static int checkContentType() {
                String type = PATH.substring(PATH.lastIndexOf(".") + 1, PATH.length())
                                .toLowerCase();
                // ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等)
                if (type.equals("avi")) {
                        return 0;
                } else if (type.equals("mpg")) {
                        return 0;
                } else if (type.equals("wmv")) {
                        return 0;
                } else if (type.equals("3gp")) {
                        return 0;
                } else if (type.equals("mov")) {
                        return 0;
                } else if (type.equals("mp4")) {
                        return 0;
                } else if (type.equals("asf")) {
                        return 0;
                } else if (type.equals("asx")) {
                        return 0;
                } else if (type.equals("flv")) {
                        return 0;
                }
                // 对ffmpeg无法解析的文件格式(wmv9,rm,rmvb等),
                // 可以先用别的工具(mencoder)转换为avi(ffmpeg能解析的)格式.
                else if (type.equals("wmv9")) {
                        return 1;
                } else if (type.equals("rm")) {
                        return 1;
                } else if (type.equals("rmvb")) {
                        return 1;
                }
                return 9;
        }

        // check file
        private static boolean checkfile(String path) {
                File file = new File(path);
                if (!file.isFile()) {
                        return false;
                }
                return true;
        }

        // 对ffmpeg无法解析的文件格式(wmv9,rm,rmvb等), 可以先用别的工具(mencoder)转换为avi(ffmpeg能解析的)格式.
        private static String processAVI(int type) {
                List<String> commend = new ArrayList<String>();
                commend.add(FLV_PATH + "/mencoder");
                commend.add(PATH);
                commend.add("-oac");
                commend.add("lavc");
                commend.add("-lavcopts");
                commend.add("acodec=mp3:abitrate=64");
                commend.add("-ovc");
                commend.add("xvid");
                commend.add("-xvidencopts");
                commend.add("bitrate=600");
                commend.add("-of");
                commend.add("avi");
                commend.add("-o");
                commend.add(FLV_PATH + FILE_NAME.substring(0,FILE_NAME.lastIndexOf(".")) + ".avi");
                try {
                        ProcessBuilder builder = new ProcessBuilder();
                        builder.command(commend);
                        builder.start();
                        return FLV_PATH + FILE_NAME.substring(0,FILE_NAME.lastIndexOf(".")) + ".avi";
                } catch (Exception e) {
                        e.printStackTrace();
                        return null;
                }
        }

        // ffmpeg能解析的格式:(asx,asf,mpg,wmv,3gp,mp4,mov,avi,flv等)
        private static boolean processFLV(String oldfilepath) {

                if (!checkfile(PATH)) {
                        return false;
                }

                List<String> commend = new ArrayList<String>();
                commend.add(FLV_PATH + "ffmpeg");
                commend.add("-i");
                commend.add(oldfilepath);
                commend.add("-ab");
                commend.add("56");
                commend.add("-ar");
                commend.add("22050");
                commend.add("-qscale");
                commend.add("8");
                commend.add("-r");
                commend.add("15");
                commend.add("-s");
                commend.add("600x500");
                commend.add(FLV_PATH + FILE_NAME.substring(0,FILE_NAME.lastIndexOf(".")) + ".flv");

                try {
                        Runtime runtime = Runtime.getRuntime();
                        String cmd = "";
                        String cut = FLV_PATH + "ffmpeg.exe -i "
                                        + oldfilepath
                                        + " -y -f image2 -ss 8 -t 0.001 -s 600x500 "
                                        + FLV_PATH
                                        + FILE_NAME.substring(0,FILE_NAME.lastIndexOf("."))
                                        + ".jpg";
                        String cutCmd = cmd + cut;
                        runtime.exec(cutCmd);
                        ProcessBuilder builder = new ProcessBuilder(commend);
                        builder.command(commend);
                        Process process = builder.start();
                        int i = doWaitFor(process);
                        if(i == 0){
                                if(log.isDebugEnabled()){
                                        log.debug("ffmpeg has finished.");
                                }
                        }

                        return true;
                } catch (Exception e) {
                        e.printStackTrace();
                        return false;
                }
        }
        
        public static int doWaitFor(Process p) {
         int exitValue = -1; // returned to caller when p is finished
         try {

         InputStream in = p.getInputStream();
         InputStream err = p.getErrorStream();
         boolean finished = false; // Set to true when p is finished

         while(!finished){
         try {
         while( in.available() > 0) {
         // Print the output of our system call
         Character c = new Character( (char) in.read());
         if(log.isDebugEnabled()){
                 log.debug( c);
         }
         }
         while( err.available() > 0) {
         // Print the output of our system call
         Character c = new Character( (char) err.read());
         if(log.isDebugEnabled()){
                 log.debug( c);
         }
         }

         // Ask the process for its exitValue. If the process
         // is not finished, an IllegalThreadStateException
         // is thrown. If it is finished, we fall through and
         // the variable finished is set to true.
         exitValue = p.exitValue();
         finished = true;
         }
         catch (IllegalThreadStateException e) {
         Thread.currentThread();
                                        // Process is not finished yet;
         // Sleep a little to save on CPU cycles
         Thread.sleep(500);
         }
         }
         }
         catch (Exception e) {
         // unexpected exception! print it out for debugging...
                 if(log.isErrorEnabled()){
                         log.error("doWaitFor(): unexpected exception - " +
         e.getMessage());
                 }
         if(log.isErrorEnabled()){
                 log.error(e.getMessage());
         }
         }
         // return completion status to caller
         return exitValue;
        }
}


------ Solution ------------------------------------ --------
it with streaming media server , fms or red5
------ Solution -------------------- ------------------------
that you tested the other formats of video yet ? QVOD also decoded , can not also put some solution can not . Tell your solution is to use streaming media . All formats get
------ Solution ------------------------------------- -------
you stand a red5 server Well, or else RTMP servers .
------ Solution ---------------------------------------- ---- how I finished
landlord QQ video playback , we can discuss the next
------ For reference only ------------ ---------------------------

how to do in order to have online play multiple formats video , while the buffer while playing the kind ?
------ For reference only -------------------------------------- -



can say in detail about it? In the action which is to do a conversion ? Transcoding a flush one and then play one ?
------ For reference only -------------------------------------- -
I just tried it with Nora , in the remote server to set up a TOMCAT, APPS following a video call directly Nora remote URL address , AVI, WMV ; formats are tested , you can support the side cushion while playing , do I have a problem with Baidu afternoon when the video test ? Or when the afternoon test LAN , no external network environment , it is not networked to download decoder ?
------ For reference only -------------------------------------- -
I tested using QVOD can directly call the URL to complete the video playback to work , but now the environment is within the network , the call will be prompted each time a QVOD mistake , if not what the to read, and then use JS to set a QvodPlayer.URL can solve

The problem is that now there will be advertising pages , http://buffer-ad.qvod.com/pi4.html this address ( within the network , page 404 )

I've set Did this work?
------ For reference only -------------------------------------- -




mainstream formats are tested passed. No problem , then buffered and paused ads I changed the hosts file shield .

Another problem is that every time I click a playlist to replace the other URL will be more time to play out of a Nora icon ( bottom right corner of the task column )

so I clicked 10 URL it produces 10 Nora icon in the task bar , mouse slip past, only one , I feel there should be no problem to call normal .

I wrote a JS change the URL

function changeUrl (url) {
QvodPlayer.URL = encodeURI (url);
}

This code produces the above said that problem. I should not know how to do it ? There are only a bit from the Internet to find support page called, do not install the client , the decoder too , can not play a lot of formats.

My goal now is to broadcast only on the page above the line, you do not want to install a program Nora , Nora nor inside the bundled plug-ins , do not know if you have any good way to provide ?

Thank you !
------ For reference only -------------------------------------- -


502410997
------ For reference only --------------------------------- ------
statement posted late due to travel so , now is a plug-in implementation qvod web video playback , thus avoiding the flow of operational problems , such as avi format

没有评论:

发表评论