java实现视频压缩转码
其实很简单,直接上代码.
snippet.java
import java.io.File;
import it.sauronsoftware.jave.AudioAttributes;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncodingAttributes;
import it.sauronsoftware.jave.VideoAttributes;
public class Snippet {
public static void main(String[] args) {
File source = new File("D:/Tool/workspace/MtnoWeb_SDWK/WebContent//temp_path/868551034812720_3059ba1bd9861dcdae9d4ccf222e3fd8.mp4");
File target = new File("D:/Tool/workspace/MtnoWeb_SDWK/WebContent//temp_path/868551034812720_3059ba1bd9861dcdae9d4ccf222e3fd81.mp4");
try {
System.out.println("begin");
AudioAttributes audio= new AudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(new Integer(56000));
audio.setChannels(new Integer(1));
audio.setSamplingRate(new Integer(22050));
VideoAttributes video=new VideoAttributes();
video.setCodec("mpeg4");
video.setBitRate(new Integer(800000));
video.setFrameRate(new Integer(15));
EncodingAttributes attr=new EncodingAttributes();
attr.setFormat("mp4");
attr.setAudioAttributes(audio);
attr.setVideoAttributes(video);
Encoder encoder=new Encoder();
encoder.encode(source, target, attr);
System.out.println("end");
} catch (Exception e) {
e.printStackTrace();
}
}
}
测试代码
import java.io.File;
import it.sauronsoftware.jave.AudioAttributes;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.EncodingAttributes;
import it.sauronsoftware.jave.VideoAttributes;
import it.sauronsoftware.jave.VideoSize;
public class FileZipTest {
public static void main(String[] args) {
File source = new File("E:\\gaolt.mp4");
File target = new File("E:\\gaolt201.flv");
try {
// 音频编码设置
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(new Integer(64000));
audio.setChannels(new Integer(1));
audio.setSamplingRate(new Integer(22050));
// 视频编码设置
VideoAttributes video = new VideoAttributes();
video.setCodec("flv");
video.setBitRate(new Integer(160000));
video.setFrameRate(new Integer(15));
video.setSize(new VideoSize(400, 300));
// 视频转码编码设置
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("flv");
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);
// 编码器
Encoder encoder = new Encoder();
encoder.encode(source, target, attrs);
System.out.println("压缩完成...");
} catch (EncoderException e) {
e.printStackTrace();
}
}
}
版权声明:本文为CSDN博主「QuellanAn2」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_27790011/article/details/84863428
本文来自博客园,作者:Forever丶随风,转载请注明原文链接:https://www.cnblogs.com/Forever-wind/articles/11727188.html