Reputation: 4487
I am using the Camera package for Flutter to record videos
The problem is that the resulted video output is not mirrored like the preview when the app is recording using the front camera
Any thoughts on how to flip/mirror the resulted video when its recorded using the front camera?
Upvotes: 1
Views: 2154
Reputation: 4836
If you're using this camera plugin this option doesn't seem to exist yet.
Solution 1 - Use a package like flutter_ffmpeg to flip the file once the video is recorded. The following snippet works :
saveVideo().then((XFile? file) async {
if (file != null) {
await _flutterFFmpeg.execute("-y -i " +
"${file.path} " +
"-filter:v \"hflip\" " +
"${file.path}_flipped.mp4").then((_) => _doWhateverYouWant());
}
});
Note that it takes some time and that the video is persisted once in cache with the Camera plugin, and a second time when you flip the whole video.
Solution 2 - Flip the camera preview using the Transform
widget
import 'dart:math' as math;
//...
Transform(
alignment: Alignment.center,
transform: Matrix4.rotationY(math.pi),
child: CameraPreview(controller),
)
//...
This way the rendering will match the preview.
Of course, don't forget to handle it only if your user is using the Front Camera.
Upvotes: 2