2

I have successfully compiled ffmpeg for android and have ported it.

I placed

  1. libffmpeg.so in /system/lib directory
  2. ffmpeg executable in /system/bin and /system/xbin directory (i was not sure where to place it). i directly copied ffmpeg executable from source directory (Not sure whether it's a correct way)

Now i am executing commands from android with following code !!

imports *
public class LatestActivity extends Activity {

    private Process process;
    String command,text;

    static { 
        System.loadLibrary("ffmpeg");
    }

  @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_latest);

          //Execute Command !!  
          try {
               Execute();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (InterruptedException e) {
               // TODO Auto-generated catch block
                e.printStackTrace();
          }
     }




public void Execute() throws IOException, InterruptedException{
        try {
            File dir=new File("/system/bin");
            String[] cmd= {"ffmpeg","-codecs"};

            process=Runtime.getRuntime().exec(cmd,null,dir);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            Log.d("Process IOException starts:",e.getMessage());
            e.printStackTrace();
            Log.d("System Manual exit !!",e.getMessage());
            System.exit(MODE_PRIVATE);
        }

        BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()),16384);

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

           // read the output from the command
           Log.d("Application output: ","Output if any !"); 
            while ((text = stdInput.readLine()) != null) {
                Log.d("Output: ",text); //$NON-NLS-1$
               }


        text="";
           // read any errors from the attempted command
        Log.d("Application output: ","Errors if any !");  //$NON-NLS-1$
           while ((text = stdError.readLine()) != null) {

               Log.d("Error: ",text);  //$NON-NLS-1$
           }



           stdInput.close();
           stdError.close();

           process.waitFor();
           process.getOutputStream().close();
           process.getInputStream().close();
           process.getErrorStream().close(); 
           destroyProcess(process);
           //process.destroy();

    }

    private static void destroyProcess(Process process) {
        try {
            if (process != null) {
                // use exitValue() to determine if process is still running.
                process.exitValue();
            }
        } catch (IllegalThreadStateException e) {
            // process is still running, kill it.
            process.destroy();
        }
    }

  }

And Here is the logcat output:

09-05 15:29:13.287: D/dalvikvm(2670): No JNI_OnLoad found in /system/lib/libffmpeg.so 0x44e7e910, skipping init
09-05 15:29:29.117: I/global(2670): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
09-05 15:29:29.117: D/Application output:(2670): Output if any !
09-05 15:29:29.117: D/Application output:(2670): Errors if any !
09-05 15:29:29.127: D/Error:(2670): /system/bin/ffmpeg: 1: Syntax error: "(" unexpected

m neither getting any errors nor output of command.
At the end it shows syntax error.
I want to know what kind of syntax error it is. how to tackle it?

m i doing something wrong?

Chaitanya Chandurkar
  • 2,142
  • 3
  • 24
  • 43
  • can you add the code for ffmpeg file as well? I mean the file that you refer here: System.loadLibrary("ffmpeg"); – TharakaNirmana Jan 08 '13 at 07:24
  • You don't need to load libfmpeg in this scenario. I suggest that you first try to run `/system/bin/ffmpeg -codecs` from ADB shell command line, maybe your binary has some problems – Alex Cohn Sep 30 '15 at 09:30

2 Answers2

4

This Error occurs if the ffmpeg file does not compiled for your cpu architechture.

Your commands might be right but you need to find correct ffmpeg file.

Gaganpreet Singh
  • 886
  • 1
  • 9
  • 20
0

FIXED @Gaganpreet Singh You are right after so much research on this, I have got to know that CPU Chip-set matters too, FFMPEG commands doesn't support INTEL ATOM processor. Asus Memo Pad 7 using INTEL ATOM cpu chip-set and when trying running ffmpeg command on it, it crashes and throw error "SYNTAX ERROR"

My commands working perfectly on all the devices except the device using INTEL ATOM chipset.

Please review this and this link if it will be helpful for you. If anyone finds a solution. Please share with us.

Finally Fixed this issue by creating ffmpeg lib for x64 & armv7 using NDK. And used this Library in my Andriod project. Now I have 2 lib and using this lib for different Android CPU ARCH. Please check this link too. Very helpful.

Community
  • 1
  • 1
Ahmad Arslan
  • 4,498
  • 8
  • 38
  • 59