uni-app HBuilderX4.76版本ios手机使用compressVideo压缩视频会改变视频的方向
uni-app HBuilderX4.76版本ios手机使用compressVideo压缩视频会改变视频的方向
| 类别 | 信息 |
|---|---|
| 产品分类 | uniapp/App |
| PC开发环境 | Windows |
| PC版本号 | Windows 10 专业版22H2 |
| HBuilderX类型 | 正式 |
| HBuilderX版本号 | 4.76 |
| 手机系统 | iOS |
| 手机系统版本号 | iOS 15 |
| 手机厂商 | 苹果 |
| 手机机型 | iPhone13 |
| 页面类型 | vue |
| vue版本 | vue2 |
| 打包方式 | 云端 |
| 项目创建方式 | HBuilderX |
示例代码:
choosemp4() {
uni.chooseVideo({
maxDuration: 30, //相机拍摄最大时长为60S
sourceType: ['album', 'camera'], //视频来源相册和相机都可以
camera: 'back', //默认摄像头是后置摄像头,
compressed: false, // 压缩视频
success: (res) => {
console.log('chooseVideo res', res);
const tempFilePath = res.tempFilePath;
const size = res.size;
const duration = res.duration;
this.getVideoInfo(tempFilePath)
console.log('选定视频的数据量大小', this.formatFileSize(size));
// 压缩视频
this.videoCompress(tempFilePath);
}
});
},
videoCompress(tempFilePath) {
uni.showLoading({
title: '视频处理中...'
});
uni.compressVideo({
src: tempFilePath,
quality: 'high',
success: (res) => {
console.log('compressVideo res: ', res);
console.log('压缩后视频大小:', this.formatFileSize(res.size));
this.videoUpload(res.tempFilePath);
}
});
}
操作步骤:
- 使用ios拍摄的视频压缩之后都会改变视频方向
预期结果:
- 压缩视频之后不改变视频方向
实际结果:
- 压缩之后视频方向被改变了
bug描述:
- ios选择ios拍摄的视频或直接拍摄视频使用uni.compressVideo压缩之后会改变视频方向
更多关于uni-app HBuilderX4.76版本ios手机使用compressVideo压缩视频会改变视频的方向的实战教程也可以访问 https://www.itying.com/category-93-b0.html
2 回复
奇怪的是录屏的视频不会压缩不会改变方向
更多关于uni-app HBuilderX4.76版本ios手机使用compressVideo压缩视频会改变视频的方向的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这是一个已知的iOS平台视频压缩时的方向问题。问题根源在于iOS设备拍摄的视频包含方向元数据(EXIF Orientation),而压缩处理过程中可能丢失或未正确处理这些元数据。
解决方案:
- 检查视频方向信息:在压缩前通过
plus.io.getVideoInfo获取视频的旋转角度:
plus.io.getVideoInfo({
filePath: tempFilePath,
success: (result) => {
console.log('视频旋转角度:', result.rotation);
// 记录旋转角度供后续处理使用
}
});
- 使用条件编译区分平台处理:iOS平台需要特殊处理方向问题
// #ifdef APP-PLUS
if(plus.os.name === 'iOS') {
// iOS平台特殊处理
this.handleIOSVideo(tempFilePath);
} else {
this.videoCompress(tempFilePath);
}
// #endif

