java变换视频到avi by mencoder

时间:2015-03-03 02:57:34

标签: java linux content-management-system mencoder

这是我的java代码,当我使用命令时 " mencoder 1.rmvb -o 2.avi -vf scale = 320:240 -oac pcm -ovc lavc -lavcopts vcodec = mpeg4:vbitrate = 500"
在linux中,它成功了,

String toAvi = "mencoder "+ originPath
             +"-o " + aviPath 
             + "-vf scale=320:240 -oac pcm -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=500";
        try {
                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec(toAvi);
                InputStream is = proc.getInputStream();
                final BufferedReader stdout = new BufferedReader(new InputStreamReader(is));
                is = proc.getErrorStream();
                final BufferedReader stderr = new BufferedReader(new InputStreamReader(is));
                final Vector outputLines = new Vector();
                //this deals with the output from the process in it's own thread
                Thread stdoutThread = new Thread() {
                    public void run() {
                        try { 
                        PrintWriter writer = new PrintWriter(new FileWriter("log.txt"));
                        int l;
                        String line;
                        for (l = 0; (line = stdout.readLine()) != null;) {
                            if (line.length() > 0) {
                                l++;
                                outputLines.appendElement(line);
                                // if (line.matches("Starting playback..."))
                            }

                        }
                        System.out.println("\nRead " + l
                                + " lines from stdout.");
                        stdout.close();
                        writer.close();
                        } catch (IOException ie) {
                            System.out.println("IO exception on stdout: " + ie);
                        }
                    }
                };
                stdoutThread.start();

                Thread stderrThread = new Thread() {
                    public void run() {
                        try {
                            int l;
                            String line;
                            for (l = 0; (line = stderr.readLine()) != null;) {
                                if (line.length() > 0)
                                    l++;
                                System.out.print(",");
                            }
                            System.out.println("\nRead " + l
                                    + " lines from stderr.");
                            stderr.close();
                        } catch (IOException ie) {
                            System.out.println("IO exception on stderr: " + ie);
                        }
                    }
                };
                stderrThread.start();

                System.out.println("About to waitfor");
                try {
                    int exitVal = proc.waitFor();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                System.out.println("Done.");

            } catch (IOException e) {
                e.printStackTrace();
                System.out.println("Exec failed. Exiting");
                System.exit(0);
                return false;
            }


            return true;

在我执行之后,linux告诉我这样,没有错误,

[2015-03-03 11:14:20] [INFO] [System.out] [creat folder:/app/tongweb02/deployment/modules/cms-web/static/upload/video/origin/2015/03/03/1.rmvb]
[2015-03-03 11:14:20] [INFO] [System.out] [creat folder:/app/tongweb02/deployment/modules/cms-web/static/upload/video/flv/2015/03/03/1425352460609.flv]
[2015-03-03 11:14:20] [INFO] [System.out] [creat folder:/app/tongweb02/deployment/modules/cms-web/static/upload/video/videoTemp]
[2015-03-03 11:14:20] [INFO] [System.out] [originVideo:/app/tongweb02/deployment/modules/cms-web/static/upload/video/origin/2015/03/03/1.rmvb]
[2015-03-03 11:14:20] [INFO] [System.out] [transform video:/app/tongweb02/deployment/modules/cms-web/static/upload/video/videoTemp/1425352460776.avi]
[2015-03-03 11:14:20] [INFO] [System.out] [About to waitfor]
[2015-03-03 11:14:20] [INFO] [System.out] [
Read 0 lines from stderr.]
[2015-03-03 11:14:20] [INFO] [System.out] [
Read 2 lines from stdout.]
[2015-03-03 11:14:20] [INFO] [System.out] [Done.]
[2015-03-03 11:14:20] [INFO] [System.out] [rmvb to avi true]

并且videoTemp的文件夹没有视频,我的java代码有什么问题

0 个答案:

没有答案
相关问题