录像的前置镜头录像,需要开启镜像功能,调用enableMirror()可以启用/关闭镜像录像。
启用镜像录像前需要先通过isMirrorSupported查询是否支持录像镜像功能,示例代码如下:
function testIsMirrorSupported(videoOutput: camera.VideoOutput): boolean {
let isSupported: boolean = videoOutput.isMirrorSupported();
return isSupported;
} import { camera } from '@kit.CameraKit';
import { media } from '@kit.MediaKit';
import { BusinessError } from '@kit.BasicServicesKit';
// ...
function enableMirror(videoOutput: camera.VideoOutput, mirrorMode: boolean): void {
try {
videoOutput.enableMirror(mirrorMode);
} catch (error) {
let err = error as BusinessError;
}
} 启用/关闭录像镜像后,需要通过getVideoRotation以及updateRotation更新旋转角度。
// Flip Angle
@State angle: number = 180;
// Use rotate to control whether the preview stream component XComponent is mirrored
XComponent({
type: XComponentType.SURFACE,
controller: this.mXComponentController,
imageAIOptions: {
types: [ImageAnalyzerType.SUBJECT],
aiController: this.aiController
}
})
.onLoad(() => {
// The aspect ratio of the preview stream must match that of the recording output stream
this.mXComponentController.setXComponentSurfaceRect({
surfaceWidth: this.videoSize.width,
surfaceHeight: this.videoSize.height
});
this.surfaceId = this.mXComponentController.getXComponentSurfaceId()
})
.width(StyleConstants.FULL_WIDTH)
.height(StyleConstants.XCOMPONENT_HEIGHT)
.rotate({ y: 1, angle: this.angle, }) import { FFProgressMessageParser, FFmpeg } from '@sj/ffmpeg';
let commands = ["ffmpeg", "-i", inputPath, "-vf", "hflip", outputPath];
FFmpeg.execute(commands, {
logCallback: (logLevel: number, logMessage: string) => console.log(`[${logLevel}]${logMessage}`),
progressCallback: (message: string) => console.log(`[progress]${JSON.stringify(FFProgressMessageParser.parse(message))}`),
}).then(() => {
console.info("FFmpeg execution succeeded.");
}).catch((error: Error) => {
console.error("FFmpeg execution failed with error: ${error.message}");
});