亲爱的StackOverflower用户:
我正在开发一个Android应用程序,试图使用ffmpeg-android-java快速获取视频中的一帧,并将其显示在ImageView
中。问题在于使用常规的ffmpeg
的-ss
寻求命令需要将输出写入内存,这会对性能造成很大的打击:
ffmpeg -ss 00:23:00 -i Mononoke.Hime.mkv -frames:v 1 out1.jpg
像上面这样的典型命令执行需要大约700-1200毫秒。因此,我想将它写入LruCache
中,希望以此获得更好的性能。
问题是ffmpeg-android-java
是一个包装器,用于执行ffmpeg
命令,因此我不知道如何正确提供LruCache
的地址来执行命令。
以下是我的代码片段:
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);
}
}