Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Camera Plugin Landscape Video on iPhone

Video does not capture in the right orientation when running the Camera Plugin example app on my iPhone X in Landscape. It works well in Portrait.

enter image description here

pubspec.yaml

version: 1.0.0+1
environment:
  sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.2
  camera: ^0.4.2
  path_provider: ^0.5.0
  video_player: ^0.10.0
  firebase_core: ^0.2.5

flutter doctor

[✓] Flutter (Channel unknown, v1.1.0, on Mac OS X 10.14.3 18D109, locale en-AU)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.2)
[✓] Connected device (1 available)
like image 770
Dave Lister Avatar asked Nov 04 '25 04:11

Dave Lister


1 Answers

Till support lands in the official package, I have had success with flutter_ffmpeg to set proper metadata.


const int AV_LOG_ERROR = 16;

final FlutterFFmpeg _flutterFFmpeg = new FlutterFFmpeg();
_flutterFFmpeg.setLogLevel(AV_LOG_ERROR);

/// The :s:v:0 after -metadata is the stream specifier,
/// which just tells ffmpeg to which stream it should add the metadata.
/// :s stands for the streams of the input file,
/// :v selects video streams and the number is the stream index,
/// zero-based - so this will select the first video stream.
/// The -c option specifies the codec
/// to be used, with copy for just copying the streams, without re-encoding.
final String looselessConversion = '-i $videoPath.mp4 -c copy -metadata:s:v:0 rotate=90 $videoPath-processed.mp4';

try {
  final int returnCode = await _flutterFFmpeg.execute(looselessConversion);

  if(returnCode == 0) {
    // delete the origina video file
    await File('$videoPath.mp4').delete();
  } else {
    throw _flutterFFmpeg.getLastCommandOutput();
  }
} catch (e) {
  print('video processing error: $e);
}

Because I am not encoding the video (just editing metadata) the process completes in less than 10ms for any length of a video file.

like image 81
nilobarp Avatar answered Nov 07 '25 08:11

nilobarp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!