Commit 7ed5cf69 authored by yanzg's avatar yanzg

压缩视频

parent 33e3822a
......@@ -37,5 +37,10 @@
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>com.yanzuoguang</groupId>
<artifactId>yzg-util-base</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package helper;
import com.yanzuoguang.util.MediaHelper;
import com.yanzuoguang.util.thread.RunnableListAuto;
import com.yanzuoguang.util.thread.ThreadHelper;
import it.sauronsoftware.jave.EncoderException;
import jdk.management.resource.internal.inst.ThreadRMHooks;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class TestMediaHelper {
private boolean isFirstImage = false;
public float[] sizes = new float[]{1f, 0.5f, 1f, 1f, 0.5f, 0.5f};
public float[] quotes = new float[]{1f, 1f, 0.5f, 0.25f, 0.5f, 0.25f};
private String getFile() {
// 注意,路径应为文件在工程中的相对路径
......@@ -26,7 +34,7 @@ public class TestMediaHelper {
return;
}
String file = getFile();
MediaHelper.getFirstImage(file, file + ".jpg");
MediaHelper.getVideoFirstImage(file, file + ".jpg");
isFirstImage = true;
}
......@@ -37,4 +45,65 @@ public class TestMediaHelper {
String file = getFile();
MediaHelper.compressPic(file + ".jpg", file + ".zip.jpg", 0.25f);
}
@Test
public void testVideoZipFlv() {
List<Runnable> list = new ArrayList<>();
for (int i = 0; i < sizes.length; i++) {
list.add(testVideoZipFlvThread(sizes[i], quotes[i]));
}
RunnableListAuto.run(list);
}
private Runnable testVideoZipFlvThread(float size, float quote) {
return new Runnable() {
@Override
public void run() {
try {
testVideoZipFlv(size, quote);
} catch (EncoderException e) {
throw new RuntimeException(e);
}
}
};
}
private void testVideoZipFlv(float size, float quote) throws EncoderException {
String file = getFile();
String name = String.format("%s.size_%d.quot_%d.flv",
file, (int) (size * 100), (int) (quote * 100));
MediaHelper.zipVideoFlv(file, name, size, (int) (MediaHelper.DEFAULT_BIT_RATE * quote));
}
@Test
public void testVideoZipMpeg() throws EncoderException {
List<Runnable> list = new ArrayList<>();
for (int i = 0; i < sizes.length; i++) {
list.add(testVideoZipMpegThread(sizes[i], quotes[i]));
}
RunnableListAuto.run(list);
}
private Runnable testVideoZipMpegThread(float size, float quote) {
return new Runnable() {
@Override
public void run() {
try {
testVideoZipMpeg(size, quote);
} catch (EncoderException e) {
throw new RuntimeException(e);
}
}
};
}
private void testVideoZipMpeg(float size, float quote) throws EncoderException {
String file = getFile();
String name = String.format("%s.size_%d.quot_%d.mpeg.mp4",
file, (int) (size * 100), (int) (quote * 100));
MediaHelper.zipVideoMpeg(file, name, size, (int) (MediaHelper.DEFAULT_BIT_RATE * quote));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment