0

sorry when I tag ffmpeg because I couldn't tag MP4Box.But I have proplem with excuted with ffmpeg via javacode too. I read at How to execute cmd commands via Java but i can't find my proplem.

I'm tested commands in cmd, it was ok:

MP4Box -dash 10000 -dash-profile live -segment-name output- seg -rap -bs-switching no input.mp4

but when i executed cmd via java code , i get error:

Error - only one input file found as argument, please check usage

Below is my code, has something wrong?

package com.uit.reformatvideo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Logger;

public class ExecuteComandToFormatVideo {

    public final static String LINK_MP4BOX = "C:/MP4Box/Tools/MP4Box.exe";
    public final static String CREATE_MPD_ECLIPSE = "mp4box -dash 10000 -frag 1000 -rap -bs-switching no";
    public final static String CREATE_MPD_IE = "MP4Box -dash 10000 -dash-profile live -segment-name output-seg -rap -bs-switching no";
    private static final Logger log = Logger.getLogger(ExecuteComandToFormatVideo.class.getName());


    public static void main(String[] args) throws IOException, InterruptedException {
          String s = null;

            try {

            // run the Unix "ps -ef" command
                // using the Runtime exec method:
                String lsCmd[] = new String [2];
                lsCmd[0] = LINK_MP4BOX;
                lsCmd[1] = "MP4Box -dash 10000 -dash-profile live -segment-name output-seg -rap -bs-switching no input.mp4";
                Process p = Runtime.getRuntime().exec(lsCmd);
                p.waitFor();
                BufferedReader stdInput = new BufferedReader(new
                     InputStreamReader(p.getInputStream()));

                BufferedReader stdError = new BufferedReader(new
                     InputStreamReader(p.getErrorStream()));

                // read the output from the command
                System.out.println("Here is the standard output of the command:\n");
                while ((s = stdInput.readLine()) != null) {
                    System.out.println(s);
                }

                // read any errors from the attempted command
                System.out.println("Here is the standard error of the command (if any):\n");
                while ((s = stdError.readLine()) != null) {
                    System.out.println(s);
                }

                System.exit(0);
            }
            catch (IOException e) {
                System.out.println("exception happened - here's what I know: ");
                e.printStackTrace();
                System.exit(-1);
            }
    }

}

Here was out put:

Here is the standard output of the command:

Here is the standarderror of the command (if any): Error - only one input file found as argument, please check usage

Community
  • 1
  • 1
Ducthien
  • 417
  • 1
  • 3
  • 13

1 Answers1

0

sorry because my English is bad. I created a bat file which included command such as CMD, then I used Runtime.getRuntime().exec(url+name+".bat"); to execute the bat file. This is my solution. My bat file:

cd C:/MP4Box/Tools/
MP4Box
MP4Box -dash 10000 -dash-profile live -segment-name output-seg -rap -bs-switching no "C:\Users\ducth\Desktop\New folder (2)\SharingVideo\src\main\webapp\resources\video\output.mp4"
Ducthien
  • 417
  • 1
  • 3
  • 13