FFmpeg音频视频合并commad
你能告诉我,下面的命令是否是正确的 一个用于视频音频合并?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
命令代码中的正确实施,并且不提供错误。 - 您正在将视频和音频格式输出到适当的输出格式容器。
- 该
vabsolutePath
只包含视频和aabsolutePath
只包含音频。否则,使用-map
选项手动选择流而不是依赖默认的stream selection行为。否则,它可能会选择错误的流。
问题用完整的代码和问题描述更新。请您检查? – djac
@djac与'ffmpeg'命令本身或你的代码有问题吗?显示正在发出的实际'ffmpeg'命令以及该命令的完整日志。 – LordNeckbeard
CAN NOT LINK EXECUTABLE“/ data/data/xxxxxffmpeg”:有文字重定位 。这是错误,我在我的gradle中“编译”com.writingminds:FFmpegAndroid:0.3.2“。 – djac
尝试在下面way-
File moviesDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_MOVIES
);
boolean success = true;
if (!moviesDir.exists()) {
success = moviesDir.mkdir();
}
if(success) {
File dest = new File(moviesDir, filePrefix + fileExtn);
int fileNo = 0;
while (dest.exists()) {
fileNo++;
dest = new File(moviesDir, filePrefix + fileNo + fileExtn);
}
....//execute ffmpeg command with dest.getAbsolutePath() as an output file path
}else
{
Snackbar.make(mainlayout, "Unable to create directory", 4000).show();
}
创建目的地(输出)文件使用dest.getAbsolutePath()
作为一个输出文件路径的ffmpeg command.You可以改变所需的目录按您的要求。
对于将来的问题,请指定是否需要帮助在代码中执行'ffmpeg'命令,或者如果您需要使用'ffmpeg'本身的帮助。如果是后者,请从代码/脚本中删除额外的复杂层,并在[su]处提出任何新问题。包括实际的,无脚本的'ffmpeg'命令和命令的完整日志/控制台输出。 – LordNeckbeard