ffmpeg
Link: https: //pan.baidu.com/s/1oh_36qFxnLW5Kmdf8F5eTQ
extraction code: rsdn
copy the contents of this open Baidu network disk phone App, the operation more convenient oh
Preparation 3 video
test.txt
-
file
'20190516150254.mp4'
-
file
'20190516151754.mp4'
-
file
'20190516153254.mp4'
2. Code
-
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
{
-
-
/**
-
* The video synthesizing a plurality of video
-
*/
-
@
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 is ffmepg installation address
3 Notes
Input files must be ordered, text.txt written to the file in
the input file format is preferably the same, preferably the same resolution size
Reprinted from: https: //blog.csdn.net/qq_16855077/article/details/90265073