2021-06-09 23:35:50 +08:00
|
|
|
|
import ink.wgink.module.file.media.manager.MediaManager;
|
|
|
|
|
import ink.wgink.module.file.media.manager.domain.VideoMetaInfo;
|
2021-06-10 18:16:59 +08:00
|
|
|
|
import ink.wgink.module.file.media.manager.domain.enums.CrfValueEnum;
|
|
|
|
|
import ink.wgink.module.file.media.manager.domain.enums.PresetVauleEnum;
|
|
|
|
|
import ink.wgink.module.file.media.manager.process.IMediaStream;
|
2021-06-11 11:48:57 +08:00
|
|
|
|
import org.joda.time.DateTime;
|
|
|
|
|
import org.joda.time.format.DateTimeFormat;
|
|
|
|
|
import org.joda.time.format.DateTimeFormatter;
|
2021-06-09 23:35:50 +08:00
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.File;
|
2021-06-10 18:16:59 +08:00
|
|
|
|
import java.io.InputStream;
|
2021-06-09 23:35:50 +08:00
|
|
|
|
import java.io.InputStreamReader;
|
2021-06-10 18:16:59 +08:00
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
2021-06-09 23:35:50 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* When you feel like quitting. Think about why you started
|
|
|
|
|
* 当你想要放弃的时候,想想当初你为何开始
|
|
|
|
|
*
|
|
|
|
|
* @ClassName: MediaTest
|
|
|
|
|
* @Description:
|
|
|
|
|
* @Author: WangGeng
|
|
|
|
|
* @Date: 2021/6/7 22:37
|
|
|
|
|
* @Version: 1.0
|
|
|
|
|
**/
|
|
|
|
|
public class MediaTest {
|
2021-06-11 11:48:57 +08:00
|
|
|
|
static long fullTime = 0L;
|
|
|
|
|
static long currentTime = 0L;
|
2021-06-09 23:35:50 +08:00
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void t1() {
|
|
|
|
|
File videoFile = new File("I:\\电视剧\\神探狄仁杰\\第一部\\神探狄仁杰-01.mp4");
|
|
|
|
|
// File frameFile = new File("C:\\Users\\wenc0\\Desktop\\UploadFiles\\frame.gif");
|
|
|
|
|
// MediaComponent.cutVideoFrame(videoFile, frameFile);
|
|
|
|
|
MediaManager.getInstance().setFFmpegPath("D:\\ffmpeg-4.4-full_build\\ffmpeg-4.4-full_build\\bin\\ffmpeg.exe");
|
|
|
|
|
VideoMetaInfo videoMetaInfo = MediaManager.getInstance().getVideoMetaInfo(videoFile);
|
|
|
|
|
System.out.println(videoMetaInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void t2() throws Exception {
|
|
|
|
|
Process process = Runtime.getRuntime().exec("node -v");
|
|
|
|
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK"));
|
|
|
|
|
new Thread(() -> {
|
|
|
|
|
try {
|
|
|
|
|
for (String line; (line = bufferedReader.readLine()) != null; ) {
|
|
|
|
|
System.out.println(line);
|
|
|
|
|
}
|
|
|
|
|
bufferedReader.close();
|
2021-06-11 11:48:57 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
}
|
2021-06-09 23:35:50 +08:00
|
|
|
|
}).start();
|
|
|
|
|
process.waitFor();
|
|
|
|
|
process.destroy();
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-10 18:16:59 +08:00
|
|
|
|
@Test
|
|
|
|
|
public void t3() {
|
|
|
|
|
MediaManager.getInstance().setFFmpegPath("/Users/wanggeng/ffmpeg/ffmpeg");
|
|
|
|
|
String sourcePath = "/Users/wanggeng/Desktop/UploadFiles/videos/20210119";
|
|
|
|
|
String sourceName = "85355a761e3442cda765c3bc6f5bd526.mp4";
|
|
|
|
|
File sourceFile = new File(sourcePath + File.separator + sourceName);
|
|
|
|
|
File outFile = new File(sourcePath + File.separator + sourceName + ".mp4");
|
2021-06-11 11:48:57 +08:00
|
|
|
|
|
|
|
|
|
Pattern durationPattern = Pattern.compile("Duration: \\d{2}:\\d{2}:\\d{2}\\.\\d{2}");
|
|
|
|
|
Pattern timePattern = Pattern.compile("time=\\d{2}:\\d{2}:\\d{2}\\.\\d{2}");
|
|
|
|
|
|
2021-06-10 18:16:59 +08:00
|
|
|
|
MediaManager.getInstance().convertVideo(sourceFile, outFile, true, CrfValueEnum.LOW_QUALITY.getCode(), PresetVauleEnum.MAX_FAST_ZIP_SPEED.getPresetValue(), null, null, new IMediaStream() {
|
|
|
|
|
@Override
|
|
|
|
|
public void input(InputStream inputStream) throws Exception {
|
|
|
|
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
|
|
for (String line; (line = bufferedReader.readLine()) != null; ) {
|
|
|
|
|
System.out.println(line);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void error(InputStream errorStream) throws Exception {
|
|
|
|
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(errorStream));
|
|
|
|
|
for (String line; (line = bufferedReader.readLine()) != null; ) {
|
2021-06-11 11:48:57 +08:00
|
|
|
|
Matcher durationMatcher = durationPattern.matcher(line);
|
|
|
|
|
Matcher timeMatcher = timePattern.matcher(line);
|
|
|
|
|
if (durationMatcher.find()) {
|
|
|
|
|
String duration = durationMatcher.group();
|
|
|
|
|
System.out.println(duration);
|
|
|
|
|
String durationTime = duration.replace("Duration: ", "");
|
|
|
|
|
DateTime dateTime = DateTime.parse(durationTime, DateTimeFormat.forPattern("HH:mm:ss.SSS"));
|
|
|
|
|
fullTime = dateTime.getMillis();
|
|
|
|
|
}
|
|
|
|
|
if (timeMatcher.find()) {
|
|
|
|
|
String time = timeMatcher.group();
|
|
|
|
|
System.out.println(time);
|
|
|
|
|
String timeTime = time.replace("time=", "");
|
|
|
|
|
DateTime dateTime = DateTime.parse(timeTime, DateTimeFormat.forPattern("HH:mm:ss.SSS"));
|
|
|
|
|
currentTime = dateTime.getMillis();
|
|
|
|
|
}
|
|
|
|
|
System.out.println(fullTime + "-" + currentTime);
|
|
|
|
|
if (fullTime > 0L) {
|
|
|
|
|
System.out.println((currentTime / fullTime * 100) + "%");
|
|
|
|
|
}
|
2021-06-10 18:16:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void t4() {
|
|
|
|
|
String line = " Duration: 00:14:05.11, start: 0.000000, bitrate: 1022 kb/s";
|
|
|
|
|
String line2 = "frame= 1 fps=0.0 q=0.0 size= 0kB time=00:00:00.13 bitrate= 2.8kbits/s speed=3.58x ";
|
|
|
|
|
Pattern durationPattern = Pattern.compile("Duration: \\d{2}:\\d{2}:\\d{2}\\.\\d{2}");
|
|
|
|
|
Pattern timePattern = Pattern.compile("time=\\d{2}:\\d{2}:\\d{2}\\.\\d{2}");
|
|
|
|
|
Matcher durationMatcher = durationPattern.matcher(line);
|
|
|
|
|
Matcher timeMatcher = timePattern.matcher(line2);
|
2021-06-11 11:48:57 +08:00
|
|
|
|
while (durationMatcher.find()) {
|
2021-06-10 18:16:59 +08:00
|
|
|
|
String count = durationMatcher.group();
|
|
|
|
|
System.out.println(count);
|
|
|
|
|
}
|
|
|
|
|
while (timeMatcher.find()) {
|
|
|
|
|
String count = timeMatcher.group();
|
|
|
|
|
System.out.println(count);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 23:35:50 +08:00
|
|
|
|
|
|
|
|
|
}
|