你能告訴我,下面的命令是否是正確的 一個用於視頻音頻合併?FFmpeg音頻視頻合併commad
vabsolutePath =視頻文件的絕對路徑(僅視頻),
aabsolutePath =音頻文件的絕對路徑(僅音頻)
String ccommand[] = {"-i",vabsolutePath,"-i",aabsolutePath, "-c:v", "copy", "-c:a", "aac","-shortest", dabsolutePath};
下面的代碼在機器人用於合併。 這裏的問題是代碼正在執行,但輸出合併文件「result.mp4」不可播放/未生成。 你能幫忙找出代碼/命令中的問題嗎?
public class Mrge extends AppCompatActivity {
private Button var_button_save,var_button_send;
Uri vuri=null;
public String vabsolutePath=null, aabsolutePath=null, dabsolutePath=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.message_layout);
OutputStream out;
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
InputStream ins = getResources().openRawResource(
getResources().getIdentifier("anvkl",
"raw", getPackageName()));
byte[] buf = new byte[1024];
int n;
while (-1 != (n = ins.read(buf)))
stream.write(buf, 0, n);
byte[] bytes = stream.toByteArray();
String root = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
File createDir = new File(root + "master" + File.separator);
createDir.mkdir();
File file = new File(root + "master" + File.separator + "master.mp4");
file.createNewFile();
out = new FileOutputStream(file);
out.write(bytes);
out.close();
vabsolutePath = file.getAbsolutePath();
//-------------------------------------------------------------------
ins = getResources().openRawResource(
getResources().getIdentifier("audio",
"raw", getPackageName()));
while (-1 != (n = ins.read(buf)))
stream.write(buf, 0, n);
bytes = stream.toByteArray();
root = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
createDir = new File(root + "audio" + File.separator);
createDir.mkdir();
file = new File(root + "audio" + File.separator + "audio.aac");
file.createNewFile();
out = new FileOutputStream(file);
out.write(bytes);
out.close();
aabsolutePath = file.getAbsolutePath();
root = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
createDir = new File(root + "result" + File.separator);
createDir.mkdir();
file = new File(root + "result" + File.separator + "result.mp4");
file.createNewFile();
dabsolutePath = file.getAbsolutePath();
//------------------------------------------------------------------------
} catch (IOException e) {
e.printStackTrace();
}
String ccommand[] = {"-y", "-i",vabsolutePath,"-i",aabsolutePath, "-c:v", "copy", "-c:a", "aac","-shortest", dabsolutePath};
loadFFMpegBinary();
execFFmpegBinary(ccommand);
}
FFmpeg ffmpeg;
private void loadFFMpegBinary() {
try {
if (ffmpeg == null) {
ffmpeg = FFmpeg.getInstance(this);
}
ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
@Override
public void onFailure() {
//showUnsupportedExceptionDialog();
}
@Override
public void onSuccess() {
}
});
} catch (FFmpegNotSupportedException e) {
//showUnsupportedExceptionDialog();
} catch (Exception e) {
}
}
private void execFFmpegBinary(final String[] command) {
try {
ffmpeg.execute(command, new ExecuteBinaryResponseHandler()
{
@Override
public void onFailure(String s) {
}
@Override
public void onSuccess(String s) {
}
@Override
public void onProgress(String s) {
}
@Override
public void onStart() {
}
@Override
public void onFinish() {
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
String m="hi";
}
}
}
對於將來的問題,請指定是否需要幫助在代碼中執行'ffmpeg'命令,或者如果您需要使用'ffmpeg'本身的幫助。如果是後者,請從代碼/腳本中刪除額外的複雜層,並在[su]處提出任何新問題。包括實際的,無腳本的'ffmpeg'命令和命令的完整日誌/控制檯輸出。 – LordNeckbeard