cmd 退出码是啥?还有,执行情况有 log 输出,最好追踪一下

解决方案 »

  1.   

    ffmpeg 的  log 输出
      

  2.   

    @RequestMapping("/stoprecord")
    public String stoprecord(HttpServletRequest req, Model model, HttpServletResponse res) throws IOException {
    logger.info("execute VdProgramScheduleController.remove()");


    logger.info( "视频直播停止录制中...");
    /**
     * 关闭进程
     */
     Process listprocess;
      String programName= "ffmpeg.exe";
      try {
       listprocess = Runtime.getRuntime().exec("cmd.exe /c tasklist");
       InputStream is = listprocess.getInputStream();
       BufferedReader r = new BufferedReader(new InputStreamReader(is));
       //StringBuffer sb = new StringBuffer();
       String str = null;
       while ((str = r.readLine()) != null) { 
        String id = null; 
        Matcher matcher = Pattern.compile(programName + "[ ]*([0-9]*)").matcher(str); 
        while (matcher.find()) {  
         if (matcher.groupCount() >= 1) {   
          id = matcher.group(1);   
          if (id != null) {    
           Integer pid = null;    
           try {     
            pid = Integer.parseInt(id);    
            } catch (NumberFormatException e) {     
             e.printStackTrace();    
             }    
            if (pid != null) { 
             //windows 关闭进程的代码
             Runtime.getRuntime().exec("cmd.exe /c taskkill /f /pid " + pid);  
            // unix/linux下
           //  Runtime.getRuntime().exec("abc=`ps -ef|grep $LOGNAME|grep 要终止的进程名称|grep -v grep |cut -c 10-16`;kill -9 $abc");
             //System.out.println("kill progress"+pid);    
             }   
            }  
          }
        }
       }
      } 
      catch (IOException e) {
       e.printStackTrace();
      }
    return null;
    }

    /**
     * @param p
     * @return
     */
    protected int doWaitFor2(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 {
    StringBuilder inSb = new StringBuilder();
    while (in.available() > 0) {
    // Print the output of our system call
    Character c = new Character((char) in.read());
    inSb.append(c);
    }
    logger.debug(inSb.toString());
    StringBuilder errSb = new StringBuilder();
    while (err.available() > 0) {
    Character c = new Character((char) err.read());
    errSb.append(c);
    }
    logger.debug(errSb.toString());
    // 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) {
    // Process is not finished yet;
    // Sleep a little to save on CPU cycles
    //e.printStackTrace();
    TimeUnit.MILLISECONDS.sleep(500L);
    }
    }
    } catch (Exception e) {
    // unexpected exception! print it out for debugging...
    e.printStackTrace();
    } // return completion status to caller
    return exitValue;
    }

    /**
     * author zy
     * @param p
     * @return
     */
    protected int doWaitFor3(Process p) {
    int exitValue = 0; // returned to caller when p is finished
    // return completion status to caller
    return exitValue;
    }
      

  3.   

    cmd里运行命令 报错 netStream.Play.StreamNotFound
    d:\share\var\converttools\ffmpeg.exe -y -i rtmp://192.168.1.145/live/livestream1 live=1 -vcodec copy -acodec copy -b 128k -s 320*240 -f flv d:\test.flv
      

  4.   

    cmd里运行命令 报错 netStream.Play.StreamNotFound
    d:\share\var\converttools\ffmpeg.exe -y -i rtmp://192.168.1.145/live/livestream1 live=1 -vcodec copy -acodec copy -b 128k -s 320*240 -f flv d:\test.flv
    已解决