我编写Java应用程序,并运行在Linux服务器上的Java应用程序运行Linux shell脚本。 linux shell脚本正在运行。 但是,我需要通过shell运行ffmpeg程序。
使用shell脚本命令通过./shellName.sh运行ffmpeg
ffmpeg没有运行java运行的应用程序。
#!/bin/bash echo -n "ffmpeg cmd :" /home/popsline/ffmpeg -i /home/popsline/sub02_chocolat.mp4 -r 0.14 -ss 00:00:20 -t 10:00:00 -vframes 10 -f image2 -y /home/popsline/img/iamges%d.png mkdir /home/username/test pwd
Java代码。
HomeController.java将sh.java引用为Object。 所以代码如下:
HomeController.java
/** * Simply selects the home view to render by returning its name. */ @RequestMapping(value = "/", method = RequestMethod.GET) public String home(Locale locale, Model model) { logger.info("Welcome home! The client locale is {}.", locale); Sh sh = new Sh(); sh.shRun(); return "home"; }
sh.java
private static final Logger logger = LoggerFactory.getLogger(HomeController.class); public void shRun(){ Runtime rt = Runtime.getRuntime(); Process proc = null; InputStream is = null; BufferedReader bf = null; try { String[] cmd = { "/bin/sh" , "-c" , "/usr/local/bin/creaThum.sh" }; proc = rt.exec(cmd); proc.getInputStream(); is = proc.getInputStream(); bf = new BufferedReader(new InputStreamReader(is)); while (true) { String info = bf.readLine(); if(info == null || info.equals("")){ break; } logger.info("info haeyoon:: " + info); } } catch (Exception e) { logger.info(e.getMessage()); } }