为什么我的代码不适用于棉花糖和棒棒糖设备。或任何想法如何在该版本中使用FFMPEG。任何帮助。
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import com.kru.ffmpeglibs.FFmpeg;
import com.kru.ffmpeglibs.FFmpegExecuteResponseHandler;
import com.kru.ffmpeglibs.FFmpegLoadBinaryResponseHandler;
import com.kru.ffmpeglibs.exceptions.FFmpegCommandAlreadyRunningException;
import com.kru.ffmpeglibs.exceptions.FFmpegNotSupportedException;
public class CommandsActivity extends AppCompatActivity {
private FFmpeg fFmpeg;
private Button btnGenerate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fFmpeg = FFmpeg.getInstance(CommandsActivity.this);
executeBinary();
btnGenerate = (Button) findViewById(R.id.btnGenerate);
btnGenerate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
String[] ffmpegCommand = { "-i "
+ Environment.getExternalStorageDirectory()
.getPath()
+ "/vid.mp4"
+ " -r 10 "
+ Environment.getExternalStorageDirectory()
.getPath()
+ "/com.mobvcasting.mjpegffmpeg/frame_%05d.jpg" };
executeCommand(ffmpegCommand);
} catch (FFmpegCommandAlreadyRunningException e) {
e.printStackTrace();
}
}
});
}
private void executeCommand(String[] cmd)
throws FFmpegCommandAlreadyRunningException {
fFmpeg.execute(cmd, new FFmpegExecuteResponseHandler() {
@Override
public void onSuccess(String message) {
Toast.makeText(CommandsActivity.this, "Sucesses..",
Toast.LENGTH_SHORT).show();
System.out.println(message);
}
@Override
public void onProgress(String message) {
// Toast.makeText(MainActivity.this, "On Process",
// Toast.LENGTH_SHORT).show();
System.out.println(message);
}
@Override
public void onFailure(String message) {
Toast.makeText(CommandsActivity.this, "Fail this",
Toast.LENGTH_SHORT).show();
System.out.println(message);
}
@Override
public void onStart() {
}
@Override
public void onFinish() {
Toast.makeText(CommandsActivity.this, "Finish",
Toast.LENGTH_SHORT).show();
}
});
}
private void executeBinary() {
try {
fFmpeg.loadBinary(new FFmpegLoadBinaryResponseHandler() {
@Override
public void onFailure() {
}
@Override
public void onSuccess() {
}
@Override
public void onStart() {
}
@Override
public void onFinish() {
}
}); } catch (FFmpegNotSupportedException e) { e.printStackTrace();
}
}
}
这是我的代码,但它仍然无效。请告诉我代码中有什么问题 我得到的例外是这样的。
02-22 11:18:41.469: E/AndroidRuntime(27839): FATAL EXCEPTION: main
02-22 11:18:41.469: E/AndroidRuntime(27839): java.lang.UnsatisfiedLinkError: Native method not found: com.kru.ffmpeglibs.ArmArchHelper.cpuArchFromJNI:()Ljava/lang/String;
02-22 11:18:41.469: E/AndroidRuntime(27839): at com.kru.ffmpeglibs.ArmArchHelper.cpuArchFromJNI(Native Method)
02-22 11:18:41.469: E/AndroidRuntime(27839): at com.kru.ffmpeglibs.CpuArchHelper.getCpuArch(CpuArchHelper.java:61)
02-22 11:18:41.469: E/AndroidRuntime(27839): at com.kru.ffmpeglibs.FFmpeg.loadBinary(FFmpeg.java:40)
02-22 11:18:41.469: E/AndroidRuntime(27839): at com.kru.sampleffmpeg.MainActivity.loadFFMpegBinary(MainActivity.java:68)
02-22 11:18:41.469: E/AndroidRuntime(27839): at com.kru.sampleffmpeg.MainActivity.onCreate(MainActivity.java:36)
02-22 11:18:41.469: E/AndroidRuntime(27839): at android.app.Activity.performCreate(Activity.java:5372)
02-22 11:18:41.469: E/AndroidRuntime(27839): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
02-22 11:18:41.469: E/AndroidRuntime(27839): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
02-22 11:18:41.469: E/AndroidRuntime(27839): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
02-22 11:18:41.469: E/AndroidRuntime(27839): at android.app.ActivityThread.access$700(ActivityThread.java:159)
02-22 11:18:41.469: E/AndroidRuntime(27839): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
02-22 11:18:41.469: E/AndroidRuntime(27839): at android.os.Handler.dispatchMessage(Handler.java:99)
02-22 11:18:41.469: E/AndroidRuntime(27839): at android.os.Looper.loop(Looper.java:176)
02-22 11:18:41.469: E/AndroidRuntime(27839): at android.app.ActivityThread.main(ActivityThread.java:5419)
02-22 11:18:41.469: E/AndroidRuntime(27839): at java.lang.reflect.Method.invokeNative(Native Method)
02-22 11:18:41.469: E/AndroidRuntime(27839): at java.lang.reflect.Method.invoke(Method.java:525)
02-22 11:18:41.469: E/AndroidRuntime(27839): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
02-22 11:18:41.469: E/AndroidRuntime(27839): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
02-22 11:18:41.469: E/AndroidRuntime(27839): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:2)
让我们看看FFmpeg设置是否必须将compile 'com.github.hiteshsondhi88.libffmpeg:FFmpegAndroid:0.2.5'
放入您的gradle中。现在使用this链接执行步骤,现在必须在使用execute命令之前调用ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
。其他明智的问题。现在看下面的代码和Sceenshot
<强> MainActivity.java 强>
public class MainActivity extends AppCompatActivity {
EditText editText;
Button click;
FFmpeg fFmpeg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fFmpeg = FFmpeg.getInstance(MainActivity.this);
executeBinary();
click = (Button) findViewById(R.id.btnChk);
editText=(EditText)findViewById(R.id.editText);
Log.e("Log",Environment.getExternalStorageDirectory().getAbsolutePath().toString());
click.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String cmd=editText.getText().toString();
// frameCount.mp4
executeCommand(cmd);
} catch (FFmpegCommandAlreadyRunningException e) {
e.printStackTrace();
}
}
});
}
private void executeCommand(String cmd) throws FFmpegCommandAlreadyRunningException {
fFmpeg.execute(cmd, new FFmpegExecuteResponseHandler() {
@Override
public void onSuccess(String message) {
Toast.makeText(MainActivity.this, "Sucesses..", Toast.LENGTH_SHORT).show();
System.out.println(message);
}
@Override
public void onProgress(String message) {
// Toast.makeText(MainActivity.this, "On Process", Toast.LENGTH_SHORT).show();
System.out.println(message);
}
@Override
public void onFailure(String message) {
Toast.makeText(MainActivity.this, "Fail this", Toast.LENGTH_SHORT).show();
System.out.println(message);
}
@Override
public void onStart() {
}
@Override
public void onFinish() {
Toast.makeText(MainActivity.this, "Finish", Toast.LENGTH_SHORT).show();
}
});
}
private void executeBinary() {
try {
fFmpeg.loadBinary(new FFmpegLoadBinaryResponseHandler() {
@Override
public void onFailure() {
}
@Override
public void onSuccess() {
}
@Override
public void onStart() {
}
@Override
public void onFinish() {
}
});
} catch (FFmpegNotSupportedException e) {
e.printStackTrace();
}
}
}
参见下图使用EditText中的命令作为输入-i /storage/emulated/0/frameCount.mp4 -r 7 /storage/emulated/0/frame%03d.jpg