0
我想在android中使用ffmpeg。這是目前的代碼。我參考了this項目。它只是讓我轉換視頻文件。但我想用ffmpeg播放視頻文件。可能嗎?如果是的話,我們該怎麼做?在Android中使用ffmpeg播放視頻
package com.ffmpeg;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import com.github.hiteshsondhi88.libffmpeg.ExecuteBinaryResponseHandler;
import com.github.hiteshsondhi88.libffmpeg.FFmpeg;
import com.github.hiteshsondhi88.libffmpeg.LoadBinaryResponseHandler;
import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegCommandAlreadyRunningException;
import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegNotSupportedException;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
Boolean loadedFlag = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (!loadedFlag) {
FFmpegInitLoader();
}
decodeVideo();
}
public void FFmpegInitLoader() {
FFmpeg ffmpeg = FFmpeg.getInstance(this);
try {
ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
@Override
public void onStart() {
}
@Override
public void onFailure() {
}
@Override
public void onSuccess() {
System.out.println("Successfully loaded FFmpeg!!!");
loadedFlag = true;
}
@Override
public void onFinish() {
}
});
} catch (FFmpegNotSupportedException e) {
System.out.println("Whatever....this thing is not supported :::::::::::::::::::: ");
}
}
public void decodeVideo() {
FFmpeg ffmpeg = FFmpeg.getInstance(this);
try {
ffmpeg.execute(new String[]{"-y", "-i", "/storage/sdcard0/AVSEQ02.mp4", "-c:v", "libx264", "/storage/sdcard0/conv.mp4"}, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
System.out.println("FFmpeg started for decoding");
}
@Override
public void onProgress(String message) {
System.out.println("progress message:::: " + message);
}
@Override
public void onFailure(String message) {
System.out.println("failure message:::: " + message);
}
@Override
public void onSuccess(String message) {
System.out.println("success message:::: " + message);
}
@Override
public void onFinish() {
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
System.out.println("already running::::::");
}
}
}
謝謝。我會看看。 – devxcon
我已經使用第一個鏈接成功編譯FFmpeg。現在,如何使用編譯的文件? – devxcon