android 上传视频到腾讯云文档,上传视频截取第一帧做视频封面,并上传腾讯云点播...

1、VUE页面上传视频到后台

:limit="1"

:http-request="uploadVideo"

:file-list="fileList3">

点击上传

只能上传AVI、WMV、RM、RMVB、MP4等格式文件

2、自定义上传方法

import axios from 'axios'

uploadVideo (event){

let form = new FormData()

var that = this

form.append('file', event.file)

form.append('dir', 'temp1')

const option = {

url: that.uploadURL,//上传路径

data: form,

method: 'post',

headers: {

'Content-Type': 'multipart/form-data'

}

}

axios(option).then((res) => {

console.log('上传结束')

console.log(res)

that.dataInfo = res.data.data

this.loadingUpload = false

this.buttonName = '确定上传'

}).catch((err) => {

console.log('上传错误')

console.log(err)

this.loadingUpload = false

this.buttonName = '确定上传'

})

},

3、下载 ffmpeg 插件并放入相应位置

链接:https://pan.baidu.com/s/16OC2ce1crgaTjChBCryWKA

提取码:75m5

注:如果下载后不可用,请自行搜索 ffmpeg 下载使用

4、后台接收文件并保存本地,截图并上传

@PostMapping("/uploadFile")

public Result upload(@RequestParam("file")MultipartFile file,String dir) {

try {

VodUploadResponse response = uploadFile(file, dir);

return this.success(response);

} catch (Exception var3) {

return this.failure(var3.getMessage());

}

}

public VodUploadResponse uploadFile(MultipartFile file, String resSort) throws Exception {

String shortPath = file.getOriginalFilename();

File dest = new File("D://temp", shortPath);

if (!dest.getParentFile().exists()) {

boolean rel = dest.getParentFile().mkdirs();

if (!rel) {

throw new Exception("文件夹创建失败");

}

}

InputStream is = file.getInputStream();

OutputStream os = new FileOutputStream(dest);

try {

byte[] buffer = new byte[8 * 1024];

int bytesRead;

while ((bytesRead = is.read(buffer)) != -1) {

os.write(buffer, 0, bytesRead);

}

} catch (Exception e) {

throw e;

} finally {

if (is != null) {

is.close();

}

if (os != null) {

os.close();

}

}

VodUploadResponse response = uploadTecent("D://temp/".concat(shortPath));

return response;

}

public VodUploadResponse uploadTecent(String url) {

VodUploadResponse response = null;

String imgurl = vidpicirl(url);

VodUploadClient client = new VodUploadClient(tencentSecretId, tencentSecretKey);

VodUploadRequest request = new VodUploadRequest();

request.setMediaFilePath(url);

request.setCoverFilePath(imgurl);

try {

response = client.upload("ap-beijing", request);

logger.info("Upload FileId = {}", response.getMediaUrl());

} catch (Exception e) {

// 业务方进行异常处理

logger.error("Upload Err", e);

}

return response;

}

public String vidpicirl(String videourl) {

System.err.println(videourl);

String picId = UUID.randomUUID().toString().replace("-", "");

String picurl = "D:\\temp\\"

+ picId + ".jpg";//截图存放路径

List commend = new java.util.ArrayList();

commend.add("D:\\ffmpeg.exe");//插件存放路径

commend.add("-i");

commend.add(videourl);

commend.add("-y");

commend.add("-f");

commend.add("image2");

commend.add("-ss");

commend.add("1");

commend.add("-t");

commend.add("0.001");

commend.add("-s");

commend.add("350*240");

commend.add(picurl);

try {

ProcessBuilder builder = new ProcessBuilder();

builder.command(commend);

builder.redirectErrorStream(true);

Process process = builder.start();

InputStream in = process.getInputStream();

byte[] re = new byte[1024];

while (in.read(re) != -1) {

System.out.print(".");

}

System.out.println("");

in.close();

} catch (Exception e) {

e.printStackTrace();

System.out.println("视频截图失败!");

}

return picurl;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值