ffmpeg
链接:https://pan.baidu.com/s/1oh_36qFxnLW5Kmdf8F5eTQ
提取码:rsdn
复制这段内容后打开百度网盘手机App,操作更方便哦
准备3个视频
test.txt
-
file
'20190516150254.mp4'
-
file
'20190516151754.mp4'
-
file
'20190516153254.mp4'
2.代码
-
package com.qihui.qxj.services.system;
-
-
import java.io.IOException;
-
import java.io.InputStream;
-
import java.util.ArrayList;
-
import java.util.List;
-
-
import org.junit.Test;
-
-
public
class
Test1 {
-
-
/**
-
* 把多个视频合成一个视频
-
*/
-
@
Test
-
public
void
test4(
){
-
try {
-
List commend =
new ArrayList();
-
commend.
add(
"c:/bin/ffmpeg.exe");
-
commend.
add(
"-loglevel");
-
commend.
add(
"8");
-
commend.
add(
"-y");
-
commend.
add(
"-f");
-
commend.
add(
"concat");
-
commend.
add(
"-safe");
-
commend.
add(
"0");
-
commend.
add(
"-i");
-
commend.
add(
"D:/project/direct/40/test.txt");
-
commend.
add(
"-c");
-
commend.
add(
"copy");
-
commend.
add(
"-y");
-
commend.
add(
"d:/out.mp4");
-
start(commend);
-
}
catch (Exception e) {
-
e.printStackTrace();
-
}
-
}
-
-
private void start(List commend) {
-
Process p =
null;
-
try {
-
ProcessBuilder builder =
new ProcessBuilder(commend);
-
builder.command(commend);
-
p = builder.start();
-
p.getOutputStream().close();
-
doWaitFor(p);
-
p.destroy();
-
}
catch (Exception e) {
-
PrintCatchErrorMsg.Print(e,
"Part",
"getRSTPPicture.catch",
"Exception");
-
p.destroy();
-
}
-
}
-
-
-
public static int doWaitFor(Process p) {
-
InputStream
in =
null;
-
InputStream err =
null;
-
int exitValue =
-1;
-
-
try {
-
in = p.getInputStream();
-
err = p.getErrorStream();
-
boolean finished =
false;
-
-
while(!finished) {
-
try {
-
Character c;
-
while(
in.available() >
0) {
-
c =
new Character((
char)
in.read());
-
System.
out.print(c);
-
}
-
-
while(err.available() >
0) {
-
c =
new Character((
char)err.read());
-
System.
out.print(c);
-
}
-
-
exitValue = p.exitValue();
-
finished =
true;
-
}
catch (IllegalThreadStateException var19) {
-
Thread.currentThread();
-
Thread.sleep(
500L);
-
}
-
}
-
}
catch (Exception var20) {
-
}
finally {
-
try {
-
if (
in !=
null) {
-
in.close();
-
}
-
}
catch (IOException var18) {
-
}
-
-
if (err !=
null) {
-
try {
-
err.close();
-
}
catch (IOException var17) {
-
}
-
}
-
-
}
-
-
return exitValue;
-
}
-
}
c:/bin/ffmpeg.exe 是ffmepg的安装地址
3、注意事项
输入文件必须是有序的,写入文件text.txt中
输入文件格式最好相同,分辨率大小最好相同
转载自:https://blog.csdn.net/qq_16855077/article/details/90265073