FFmpeg - 找不到ExecuteBinaryResponseHandler - Android / Java [英] FFmpeg - cannot find ExecuteBinaryResponseHandler - Android/Java
问题描述
我正在尝试制作一个反馈原生的模块,将视频更改为gif。我对android工作室/ java几乎没有任何经验,但我很想学习更多!我正在使用此库将视频转换为gif。这是我的代码:
package com.reactlibrary;
import android.widget.Toast;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.github.hiteshsondhi88.libffmpeg.FFmpeg;
public class RNGifMakerModule extends ReactContextBaseJavaModule {
private final ReactApplicationContext reactContext;
public RNGifMakerModule(ReactApplicationContext reactContext){
super(reactContext);
this.reactContext = reactContext;
}
@Override
public String getName(){
returnRNGifMakerModule;
}
@ReactMethod
public void alert(String message){
Toast.makeText(getReactApplicationContext(),Error,Toast.LENGTH_LONG).show );
String [] cmd = {-i
,消息
,Image.gif};
转换(cmd);
}
public void conversion(String [] cmd){
FFmpeg ffmpeg = FFmpeg.getInstance(this.reactContext);
尝试{
//执行ffmpeg -version命令,您只需要传递-version
ffmpeg.execute(cmd ,new ExecuteBinaryResponseHandler(){
@Override
public void onStart(){
}
@Override
public void onProgress消息){
}
@Override
public void onFailure(String message){
}
@Override
public void onSuccess(String message){
}
@Override
public void onFinish(){
}
});
} catch(FFmpegCommandAlreadyRunningException e){
//如果FFmpeg已经运行,则处理
e.printStackTrace();
}
}
}
我收到此错误:
错误:(43,31)错误:找不到符号类ExecuteBinaryResponseHandler
/ pre>
这似乎是奇怪的,因为在 ffmpeg-android-java的文档,它表示使用完全相同的代码几乎。
赏金
如果您可以找到转换video.mp4的方式,奖励将被授予给您成为gif您不要必须使用
FFmpeg
,但您的解决方案必须与java / android工作室配合使用。解决方案首先你应该正确启动ffmpeg。
FFmpeg ffmpeg = FFmpeg.getInstance(this.reactContext);
//请在
ffmpeg.loadBinary后添加以下方法(新的FFmpegLoadBinaryResponseHandler(){
@Override
public void onFailure(){
//可能您的设备不支持
}
@Override
public void onSuccess(){
//您应该在此处使用init标志(isLoaded,isReady等) 。
}
只有在
onSuccess()
你可以使用命令。
然后请检查以下回答<一个>由LordNeckbeard。
所以你的代码应该是这样的:
if(isFFmpegLoaded){
// ffmpeg.execute(从答案的链接的命令)
}
请不要忘记从命令的字符串和ffmpeg字中删除所有空格
为了使命令更易于阅读,我将建议d创建这样的命令:final String [] command = new String [11]; //答案中的第一个命令示例
command [0] =-y;
command [1] =-ss;
command [2] =30;
command [3] =-t;
command [4] =3;
command [5] =-i;
command [6] =-t;
command [7] =filePath;
command [8] =-vf;
command [9] =fps = 10,scale = 320:-1:flags = lanczos,palettegen;
command [10] =palette.png;
请确保您具有处理文件的存储权限,以防您正在使用外部存储。
根据这个策略,ffmpeg对我有用。谢谢,祝你好运!
更新:
其实我不相信行:
FFmpeg ffmpeg = FFmpeg.getInstance(this.reactContext);
看起来像ffmpeg不得不使用应用程序上下文
I am trying to make a module for react-native that will change a video into a gif. I have little to no experience with android studios/java, but I would love to learn more! I am using this library to convert the video to a gif. Here is my code:
package com.reactlibrary; import android.widget.Toast; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; import com.github.hiteshsondhi88.libffmpeg.FFmpeg; public class RNGifMakerModule extends ReactContextBaseJavaModule { private final ReactApplicationContext reactContext; public RNGifMakerModule(ReactApplicationContext reactContext) { super(reactContext); this.reactContext = reactContext; } @Override public String getName() { return "RNGifMakerModule"; } @ReactMethod public void alert(String message) { Toast.makeText(getReactApplicationContext(), "Error", Toast.LENGTH_LONG).show(); String[] cmd = {"-i" , message , "Image.gif"}; conversion(cmd); } public void conversion(String[] cmd) { FFmpeg ffmpeg = FFmpeg.getInstance(this.reactContext); try { // to execute "ffmpeg -version" command you just need to pass "-version" ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() { @Override public void onStart() { } @Override public void onProgress(String message) { } @Override public void onFailure(String message) { } @Override public void onSuccess(String message) { } @Override public void onFinish() { } }); } catch (FFmpegCommandAlreadyRunningException e) { // Handle if FFmpeg is already running e.printStackTrace(); } } }
And I get this error:
Error:(43, 31) error: cannot find symbol class ExecuteBinaryResponseHandler
This seems odd to be, because in the documentation for ffmpeg-android-java it says to use almost exactly the same code.
Bounty
The bounty will be awarded to you if you can find a way to convert a video.mp4 into a gif. You do not necessarily have to use
FFmpeg
, but your solution has to work with java/android studios.解决方案First of all you should init ffmpeg correctly.
FFmpeg ffmpeg = FFmpeg.getInstance(this.reactContext); // please add following method after ffmpeg.loadBinary(new FFmpegLoadBinaryResponseHandler() { @Override public void onFailure() { // probably your device not supported } @Override public void onSuccess() { // you should init flag here (isLoaded, isReady etc.) }
Only after
onSuccess()
you can work with commands.Then please check following answer by LordNeckbeard.
So your code should be something like this:
if (isFFmpegLoaded) { // ffmpeg.execute(commands from link from the answer) }
Please do not forget to remove all spaces from command's string and "ffmpeg" word. To keep command more readable I will recommend to build command like this:
final String[] command = new String[11]; // example of the first command in the answer command[0] = "-y"; command[1] = "-ss"; command[2] = "30"; command[3] = "-t"; command[4] = "3"; command[5] = "-i"; command[6] = "-t"; command[7] = "filePath"; command[8] = "-vf"; command[9] = "fps=10,scale=320:-1:flags=lanczos,palettegen"; command[10] = "palette.png";
Please make sure that you have storage permission to work with file just in case you are working on external storage.
Based on this strategy ffmpeg works well for me. Thanks and good luck!
Update:
Actually I do not trust this line:
FFmpeg ffmpeg = FFmpeg.getInstance(this.reactContext);
Looks like ffmpeg had to use application context
这篇关于FFmpeg - 找不到ExecuteBinaryResponseHandler - Android / Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!