FFmpeg输出寻求结果到Android LruCache [英] FFmpeg output seeking result to Android LruCache
问题描述
亲爱的StackOverflower,
Dear fellow StackOverflower,
在我的Android应用程序中,我正在尝试使用 ffmpeg-android-java 显示在 ImageView
中。问题是使用典型的 ffmpeg
的 -ss
寻找命令将需要将输出写入内存中假设是对表演的重大影响:
In my Android application, I'm trying to quickly retrieve a frame from a video using ffmpeg-android-java to display in an ImageView
. The problem is using a typical ffmpeg
's -ss
seeking command will require to write the output into the memory which I suppose is the big hit on performance:
ffmpeg -ss 00:23:00 -i Mononoke.Hime.mkv -frames:v 1 out1 .jpg
上面的典型命令执行大概需要700到1200毫秒。因此,我不想写入内存,而是将其写入 LruCache
希望实现更好的性能。
A typical command execution like above takes around 700 - 1200 milliseconds. So instead of writing into the memory, I would like to write it into LruCache
hoping to achieve a better performance.
问题是 ffmpeg-android-java
是执行 ffmpeg
命令的包装器,所以我不知道如何正确提供 LruCache
的命令地址。
The problem is ffmpeg-android-java
is a wrapper to execute ffmpeg
command and as such I don't know how to correctly supply the LruCache
's address for the command.
以下是我的代码片段:
private void seekToPosition(long currentVideoPosition){
String position = DiskUtils.formatMillisForFFmpeg(currentVideoPosition);
String[] cmd = {"-ss", String.valueOf(position), "-i", mVideoPath,
"-y", "-an", "-frames:v", "1",
"/storage/emulated/0/Videos/out.jpg"}; //this the problem, I would like to change this to the address of LruCache
try {
// to execute "ffmpeg -version" command you just need to pass "-version"
mFFmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
long start;
long end;
@Override
public void onStart() {
canSeek = false;
start = System.currentTimeMillis();
}
@Override
public void onProgress(String message) {}
@Override
public void onFailure(String message) {
Log.d(TAG, "FFmpeg cmd failure");
}
@Override
public void onSuccess(String message) {
Log.d(TAG, "FFmpeg cmd success");
/*mFFmpeg.killRunningProcesses();
Log.d(TAG, "FFmpeg kill running process: " + mFFmpeg.killRunningProcesses());*/
}
@Override
public void onFinish() {
canSeek = true;
Log.d(TAG, "FFmpeg cmd finished: is FFmpeg process running: " + mFFmpeg.isFFmpegCommandRunning());
end = System.currentTimeMillis();
Log.d(TAG, "FFmpeg excuted in: " + (end - start) + " milliseconds");
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// Handle if FFmpeg is already running
Log.d(TAG, "FFmpeg exception: " + e);
}
}
推荐答案
回答我自己的问题,我还没有找到解决方案,因为它本质上是不可能的。所以,我采取了艰难的方式编译FFmpeg,并使用JNI将其用作一个库。
To answer my own question, I haven't found the solution for this yet as it's kind of impossible in nature. So instead, I take the hard way of compiling the FFmpeg and using the JNI to use it as a library.
你可以看看我的一步一步说明,如果您需要一些关于使用Android Studio构建和使用FFmpeg的指导,因为我知道试图找出这个出来是一场真正的噩梦。
You can take a look at my step-by-step instructions if you need some guidance on building and using FFmpeg with Android Studio because I know trying to figure this out is a real nightmare.
对不起,我无法发布所有的说明,因为它太久了,加上我更容易保存1个信息来源的最新信息。
Sorry I can't post all the instructions here as it is way too long, plus it is easier for me to keep 1 source of information up-to-date.
这篇关于FFmpeg输出寻求结果到Android LruCache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!