1.我在java中上传视频文件,大概150M左右,上传成功后在项目web端网页上访问
是可以流畅播放的。
2.但是在项目APP端播放就出现问题,播放了几秒钟后就卡死了。
3.然后我测试小视频15M,web端和app端都能正常播放,这个是什么原因呢?
找不到原因的我,只能在视频上传的时候把视频做压缩处理,进行压缩处理后,APP端和web端都能正常播放,但是做压缩处理的过程就很慢,导致接口响应过长超时。大神们改怎么处理。我
的压缩代码:
private void videoCompressToMP4(String sourcePath,String targetPath){
Log.info("url=="+sourcePath+",,,"+targetPath);
File source = new File(sourcePath);
File target = new File(targetPath);
try {
log.info("压缩转换开始:");
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));
video.setSize(new VideoSize(400, 300));
EncodingAttributes attr=new EncodingAttributes();
attr.setFormat("mp4");
attr.setAudioAttributes(audio);
attr.setVideoAttributes(video);
Encoder encoder=new Encoder();
encoder.encode(source, target, attr);
log.info("压缩转换成功--结束,路径:"+targetPath);
} catch (Exception e) {
e.printStackTrace();
}
}
但是这个效率很低感觉,150M的得耗时60秒左右,怎么优化。
或者解决根本问题,为什么大视频在APP端播放几秒钟就不能播放啊,小视频ok.