海康视频不能在浏览器解析播放,需要转码
参考:https://blog.csdn.net/xcg340123/article/details/139825982
依赖
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-core</artifactId>
<version>2.4.5</version>
</dependency>
<!-- 核心包-->
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-native-win64</artifactId>
<version>2.4.5</version>
</dependency>
<!-- 这个是在windows环境下的jar,使用不同的环境,会调用不同的jar文件-->
<dependency>
<groupId>ws.schild</groupId>
<artifactId>jave-native-linux64</artifactId>
<version>2.4.5</version>
</dependency>
<!-- 这个是在linux环境下的jar-->
转码逻辑
import ws.schild.jave.*;
import java.io.File;
public class VideoConvertUtil {
public static void main(String[] args) throws EncoderException {
convertH264();
}
public static void convertH264() throws EncoderException {
//源视频位置
File file = new File("C:\\Users\\Administrator\\Documents\\录入脚本\\video1.mp4");
//目标视频位置
File file1 = new File("C:\\Users\\Administrator\\Documents\\录入脚本\\video1test.mp4");
// 创建转码器
AudioAttributes audio = new AudioAttributes();
//指定编码
audio.setCodec("aac");
audio.setBitRate(new Integer(128000));
//通道
audio.setChannels(new Integer(2));
audio.setSamplingRate(new Integer(44100));
VideoAttributes video = new VideoAttributes();
//设置编解码器
video.setCodec("h264");
video.setX264Profile(VideoAttributes.X264_PROFILE.BASELINE);
video.setBitRate(new Integer(1024 * 1024 * 2));
//设置帧率
video.setFrameRate(new Integer(25));
//设置大小
//video.setSize(new VideoSize(2560, 1440));
EncodingAttributes attrs = new EncodingAttributes();
//格式
attrs.setFormat("mp4");
//attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);
// 进行转码
Encoder encoder = new Encoder();
encoder.encode(new MultimediaObject(file), file1, attrs);
}
}