2

Android用のffmpegを正常にコンパイルし、移植しました。

置いた

  1. /system/libディレクトリの libffmpeg.so
  2. /system/binおよび/system/xbinディレクトリにある ffmpeg 実行可能ファイル(どこに配置すればよいかわかりませんでした)。ソースディレクトリからffmpeg実行可能ファイルを直接コピーしました(正しい方法かどうかはわかりません)

今、私は次のコードでアンドロイドからコマンドを実行しています!!

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();
        }
    }

  }

そして、logcat の出力は次のとおりです。

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 エラーもコマンドの出力も得られません。
最後に構文エラーが表示されます。
どのような構文エラーか知りたいです。どのように対処するのですか?

私は何か間違ったことをしていますか?

4

2 に答える 2

0

FIXED @Gaganpreet Singhこれについて多くの調査を行った後、CPUチップセットも重要であることを知りました.FFMPEGコマンドはINTEL ATOMプロセッサをサポートしていません. Intel ATOM CPU チップセットを使用する Asus Memo Pad 7 で ffmpeg コマンドを実行しようとすると、クラッシュしてエラー「SYNTAX ERROR」がスローされます。

私のコマンドは、INTEL ATOM チップセットを使用するデバイスを除くすべてのデバイスで完全に機能します。

これこのリンクが参考になるかどうかを確認してください。誰かが解決策を見つけたら。私たちと共有してください。

最後に、NDK を使用して x64 および armv7 用の ffmpeg lib を作成することにより、この問題を修正しました。そして、このライブラリを私の Andriod プロジェクトで使用しました。現在、2 つのライブラリがあり、このライブラリを別の Android CPU ARCH に使用しています。こちらのリンクもご確認ください。非常に役立ちます。

于 2015-09-29T05:01:46.760 に答える