关于视频流格式和如何保存咨询

这里目前实现类视频流数据的获取,获取到buffer,目前想了解的是,这个视频流的buffer是什么格式的 如何保存成图片呢

API10 Devstudio 4.1 华为mate 60pro

HarmonyOS
2024-05-09 22:33:25
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
QW_MA
createImageReceiver(): image.ImageReceiver { 
let receiver: image.ImageReceiver = image.createImageReceiver(cameraWidth, cameraHeight, 2000, 8); 
receiver.on(‘imageArrival’, () => { 
receiver.readNextImage((err: BusinessError, nextImage: image.Image) => { 
if (err || nextImage === undefined) { 
return; 
} 
nextImage.getComponent(image.ComponentType.JPEG, async (err: BusinessError, imgComponent: image.Component) => { 
if (err || imgComponent === undefined) { 
return; 
} 
if (imgComponent.byteBuffer as ArrayBuffer) { 
let sourceOptions : image.SourceOptions = { 
sourceDensity: 120, 
sourcePixelFormat: 8, // NV21 
sourceSize: { 
height: previewProfilesObj3.size.height, 
width: previewProfilesObj3.size.width 
} 
} 
let imageResource=image.createImageSource(imgComponent.byteBuffer,sourceOptions) 
let decodingOptions: image.DecodingOptions = { 
editable: true, 
desiredPixelFormat: 3, 
} 
this.pixma=await imageResource.createPixelMap(decodingOptions) 
const imagePackerApi = image.createImagePacker(); 
let packOpts: image.PackingOption = { format: “image/jpeg”, quality: 98 }; 
const context: Context = getContext(this); 
const path1: string = context.cacheDir + “/pixel_map86695.jpg”; 
imagePackerApi.packing(imageResource, packOpts).then((data: ArrayBuffer) => { 
// data 为打包获取到的文件流,写入文件保存即可得到一张图片 
if (data) { 
let buf: buffer.Buffer = buffer.from(data ); 
let base64Url: string = buf.toString(‘base64url’, 0, buf.length); 
console.log(‘66666’+JSON.stringify(base64Url)) 
 
          let file = fs.openSync(path1, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); 
 
          fs.write(file.fd, data).then(async (writeLen) => { 
            console.info("write data to file succeed and size is:" + writeLen); 
fs.closeSync(file); 
}).catch((err: BusinessError) => { 
console.info("write data to file failed with error message: " + err.message + ", error code: " + err.code); 
}); 
} 
}).catch((error: BusinessError) => { 
console.error('Failed to pack the image. And the error is: ’ + error); 
}) 
this.pixelmap=await imageResource.createPixelMap(); 
} else { 
return; 
} 
}) 
}) 
}) 
return receiver; 
}
分享
微博
QQ
微信
回复
2024-05-10 10:52:20
相关问题
请问视频支持哪些格式
550浏览 • 1回复 待解决
关于如何使用鸿蒙接收视频
3773浏览 • 0回复 待解决
HarmonyOS HarmonyOS的视频操作
78浏览 • 1回复 待解决
HarmonyOS 捕获屏幕视频
63浏览 • 1回复 待解决
HarmonyOS 获取相机的视频
26浏览 • 1回复 待解决
保存自动格式化代码如何配置
477浏览 • 1回复 待解决
HarmonyOS视频缓存框架问题
407浏览 • 1回复 待解决
关于数据缓存问题咨询
301浏览 • 1回复 待解决
HarmonyOS hevc格式视频解码
325浏览 • 1回复 待解决
HarmonyOS 视频数据传输
470浏览 • 1回复 待解决
HarmonyOS GL封装相机预览角度咨询
253浏览 • 1回复 待解决