To record video using the front camera, you need to enable the mirroring feature. Call enableMirror() to enable or disable mirroring.
Before enabling mirroring, you need to call isMirrorSupported to check whether the device supports mirroring. The sample code is as follows:
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;
}
} After enabling or disabling mirroring, call getVideoRotation and updateRotation to update the rotation angle.
// 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}");
});