首页 新闻 会员 周边

有一段5,6秒的视频需要保存到oss服务器上,应该怎么做?

0
[已解决问题] 解决于 2018-12-13 16:18

直接用oss的文件流好像有点慢,大概要10多秒的时间,想要一种更快的方法
目前的想法是吧文件先压缩,再上传
尝试文件压缩,只能将9M的视频,压缩到8M
/**
* 压缩一个文件夹

@throws IOException
*/
public void zipDirectory(String path) throws IOException {
File file = new File(path);
String parent = file.getParent();
File zipFile = new File(parent, file.getName() + ".zip");
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile));
zip(zos, file, file.getName());
zos.flush();
zos.close();
}
尝试视频压缩,用都没有用起来,jar包工具我都下了,但然并卵
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 FfmepgUtil {
public static void ffmepg(String sourceAddr, String targetAddr,
String codec, int bitRate, String format) {

File source = new File(sourceAddr);
File target = new File(targetAddr);
try {

AudioAttributes audio = new AudioAttributes();// 音频属性
audio.setCodec("libmp3lame");// libfaac PGM编码
// audio.setBitRate(new Integer(128000));// 音频比特率
// audio.setChannels(new Integer(2));// 声道
// audio.setSamplingRate(new Integer(44100));// 采样率
VideoAttributes video = new VideoAttributes();// 视频属性
video.setCodec(codec);// 视频编码
video.setBitRate(new Integer(bitRate));// 视频比特率
// video.setFrameRate(new Integer(30));// 帧率
// video.setSize(new VideoSize(1920,1080));// 视频宽高
EncodingAttributes attrs = new EncodingAttributes();// 转码属性
attrs.setFormat(format);// 视频格式
attrs.setAudioAttributes(audio);// 音频属性
attrs.setVideoAttributes(video);// 视频属性
Encoder encoder = new Encoder();// 创建解码器
encoder.encode(source, target, attrs);
System.out.println("上传成功!!!");
} catch (EncoderException e) {
e.printStackTrace();
System.out.println("文件格式不正确!");
}
}
}

玄月白的主页 玄月白 | 初学一级 | 园豆:6
提问于:2018-11-27 18:07
< >
分享
最佳答案
0

你这压缩没有任何意义啊,并且我记得这个方法还不支持h264编码,压缩速度也很一般。
推荐一种方法:
通过OSS直传,你后台回调阿里上传结果,获得上传地址

奖励园豆:5
疯狂的熊猫 | 菜鸟二级 |园豆:228 | 2018-12-13 16:10

前台直接放秘钥好像不安全

玄月白 | 园豆:6 (初学一级) | 2018-12-13 16:10

@玄月白: 临时身份信息是后台接口给你的(先获取身份信息AssumeRole),并且每次请求身份信息都会发生变化

疯狂的熊猫 | 园豆:228 (菜鸟二级) | 2018-12-13 16:13

@疯狂的熊猫: AssumeRole这是阿里接口产生的一种类似token的安全机制吗?

玄月白 | 园豆:6 (初学一级) | 2018-12-13 16:15

@玄月白: 是的,就相当于你去某地方参观的时候别人会给你一个临时出入卡

疯狂的熊猫 | 园豆:228 (菜鸟二级) | 2018-12-13 16:17

@玄月白:
这是回调接口代码
//解析阿里回调服务器的接口数据
String ossCallbackBody = AliOssBack.getPostBody(request.getInputStream(), Integer.parseInt(request.getHeader("content-length")));
//验证是否是阿里发起的回调
boolean ret = AliOssBack.verifyOSSCallbackRequest(request, ossCallbackBody);
if (ret) {阿里那边上传完成}

疯狂的熊猫 | 园豆:228 (菜鸟二级) | 2018-12-13 16:22
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册