通过
react-native-syan-image-picker
选择视频,得到视频的路径
调用react-native-compressor
对视频进行压缩
📢 视频路径需要file://
开头
import * as Compressor from 'react-native-compressor';
async function CompressorVideo(){
console.log('videoURI==',videoURI);
let result = await Compressor.Video.compress(
videoURI,
{
compressionMethod: Platform.OS == 'ios' ? 'manual' : 'auto',
minimumFileSizeForCompress:3, // 3M以内不进行压缩
bitrate: 49152 // 48K 可以修改
},
(progress) => {
console.log('Compression Progress: ', progress);
}
)
if (Platform.OS == 'android'){
result = result.replace('file://','file:///')
}
console.log('CoompressorVideo===',result);
// 上传
}
亲测 120M一分钟的视频 ios 5.6M android 3.5M
网友评论