添加测试方法
This commit is contained in:
parent
00e01b50d7
commit
6f3878712a
@ -3,6 +3,9 @@ import ink.wgink.module.file.media.manager.domain.VideoMetaInfo;
|
||||
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;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@ -23,6 +26,8 @@ import java.util.regex.Pattern;
|
||||
* @Version: 1.0
|
||||
**/
|
||||
public class MediaTest {
|
||||
static long fullTime = 0L;
|
||||
static long currentTime = 0L;
|
||||
|
||||
@Test
|
||||
public void t1() {
|
||||
@ -44,7 +49,8 @@ public class MediaTest {
|
||||
System.out.println(line);
|
||||
}
|
||||
bufferedReader.close();
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}).start();
|
||||
process.waitFor();
|
||||
process.destroy();
|
||||
@ -57,6 +63,10 @@ public class MediaTest {
|
||||
String sourceName = "85355a761e3442cda765c3bc6f5bd526.mp4";
|
||||
File sourceFile = new File(sourcePath + File.separator + sourceName);
|
||||
File outFile = new File(sourcePath + File.separator + sourceName + ".mp4");
|
||||
|
||||
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}");
|
||||
|
||||
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 {
|
||||
@ -70,7 +80,26 @@ public class MediaTest {
|
||||
public void error(InputStream errorStream) throws Exception {
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(errorStream));
|
||||
for (String line; (line = bufferedReader.readLine()) != null; ) {
|
||||
System.out.println(line);
|
||||
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) + "%");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -84,7 +113,7 @@ public class MediaTest {
|
||||
Pattern timePattern = Pattern.compile("time=\\d{2}:\\d{2}:\\d{2}\\.\\d{2}");
|
||||
Matcher durationMatcher = durationPattern.matcher(line);
|
||||
Matcher timeMatcher = timePattern.matcher(line2);
|
||||
while(durationMatcher.find()) {
|
||||
while (durationMatcher.find()) {
|
||||
String count = durationMatcher.group();
|
||||
System.out.println(count);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user