uni-app视频压缩失败
uni-app视频压缩失败
测试过的手机:
Android:huawei;xioami;honor; iOS:iPhone 14 Pro,iOS 17.1.2;iPhone 13 Pro Max,iOS 17.0.3;iPhone 11,iOS 15.5;iPhone 14,iOS 17.1.1
示例代码:
<template>
<view>
<button type="primary" size="mini" @tap="addVideo(true)">上传视频</button>
<button type="default" size="mini" @tap="addVideo(false)">保存相册</button>
</view>
</template>
<script>
export default {
data() {
return {
videoHint: '',
}
},
methods: {
addVideo(isUploadVideo) {
let self = this;
uni.chooseVideo({
compressed: false,
sourceType: ['camera', ], //开启视频相机
maxDuration: 60 * 5, //时长 5分钟
mediaType: ['video'], //类型为视频
success: (res) => {
if (res.duration < 300) {
uni.showToast({
title: '视频录制时间不足 5 分钟!',
icon: 'none',
});
return;
}
let videPath = plus.io.convertLocalFileSystemURL(res.tempFilePath)
self.videoCompress(videPath, isUploadVideo);
},
fail: (err) => { //提示
this.videoHint = '视频录制失败';
console.log('err: ', err);
uni.showToast({
title: '视频录制失败!',
icon: 'none',
});
}
})
},
// 视频压缩
videoCompress(tempFilePath, isUploadVideo) {
this.videoHint = '晨会视频压缩中...'
var that = this;
let time = `${uni.$u.timeFormat(Number(new Date()), 'yyyy-mm-dd-hh:MM:ss')}.mp4`
console.log('tempFilePath: ', tempFilePath);
uni.getVideoInfo({
src: tempFilePath,
success: (res) => {
console.log('getVideoInfoSucc: ', res);
},
fail: (res) => {
console.log('getVideoInfoFail: ', res);
}
})
let params = {
src: tempFilePath, //路径
quality: 'medium', //'low':低,'medium':中,'high':高
}
// 第一种方式
plus.zip.compressVideo(params, (success) => {
console.log('success: ', success);
let filePath = plus.io.convertLocalFileSystemURL(success.tempFilePath)
if (isUploadVideo) {
this.videoHint = '晨会视频压缩完成'
// that.getAliyunOssPolicy(filePath)
} else {
that.saveMeetingLog(5);
}
}, (error) => {
this.videoHint = '晨会视频压缩失败'
uni.showToast({
title: '视频压缩失败',
icon: 'none'
})
})
//第二种方式
uni.compressVideo({
src: tempFilePath,
quality: 'medium', //'low':低,'medium':中,'high':高
success: function(res) {
console.log('压缩后大小---', res.size / 1024 / 1024 + 'M');
let filePath = plus.io.convertLocalFileSystemURL(res.tempFilePath)
if (isUploadVideo) {
that.videoHint = '晨会视频压缩完成';
// that.getAliyunOssPolicy(filePath)
} else {
uni.saveImageToPhotosAlbum({
filePath: filePath,
success(path) {
console.log('saveImageToPhotosAlbum: ', path);
that.baseInfo.imgPaths = path.path;
that.videoHint = '保存相册成功,请用PC端上传视频';
uni.showToast({
title: '保存相册成功',
icon: 'none'
});
},
fail() {
that.videoHint = '保存相册失败';
uni.showToast({
title: '保存相册失败',
icon: 'none'
});
}
})
}
},
fail: function(err) {
console.log(err)
uni.showToast({
title: '视频压缩失败',
icon: 'none'
})
}
});
}
},
}
</script>
操作步骤:
当天偶尔复现,第二天 第一次必现
预期结果:
尽快修复,压缩成功,不再压缩失败
实际结果:
压缩成功,不再压缩失败
bug描述:
1、Android
honor,NTH-AN00,Android 12; huawei,CET-AL00,Android 12;huawei,ANG-AN00,Android 12;xiaomi,23116PN5BC,Android 14
({“code”:-99,“message”:“Surface frame wait timed out”})
huawei,RTE-AL00,Android 12
({“code”:-99,“message”:“Error 0xffffffe0”})
huawei,HMA-AL00,Android 10
({“code”:-99,“message”:“null”})
2、iOS
{“code”:-100,“message”:"[Zip:-11800]这项操作无法完成,"}
1 回复
在使用 uni-app
进行视频压缩时,可能会遇到压缩失败的情况。以下是一些可能的原因和解决方案:
1. 检查插件或API的兼容性
- 如果你使用的是第三方插件(如
uni.chooseVideo
或uni.compressVideo
),请确保插件支持当前平台(如微信小程序、H5、App等)。 - 某些API可能在某些平台上不可用或不支持视频压缩功能。
2. 检查视频格式和大小
- 确保视频格式是支持的格式(如MP4、MOV等)。
- 检查视频文件大小是否超出限制,某些平台对视频大小有严格限制。
3. 检查权限
- 在App端,确保应用有读写存储的权限。
- 在小程序端,确保用户授权了相册访问权限。
4. 调试代码逻辑
- 检查压缩参数是否正确,例如
quality
、bitrate
等。 - 确保压缩后的文件路径有效,且文件保存成功。
示例代码:
uni.chooseVideo({
success: (res) => {
uni.compressVideo({
src: res.tempFilePath,
quality: 'low',
success: (compressedRes) => {
console.log('压缩成功:', compressedRes.tempFilePath);
},
fail: (err) => {
console.log('压缩失败:', err);
}
});
}
});