首页 > 解决方案 > iPhone上的Flutter Camera Plugin横向视频

问题描述

在我的 iPhone X 上横向运行相机插件示例应用程序时,视频没有以正确的方向捕获。它在肖像中效果很好。

在此处输入图像描述

发布规范.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 (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)

标签: fluttervideo-capture

解决方案


直到官方包中的支持登陆,我已经成功flutter_ffmpeg设置了正确的元数据。


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);
}

因为我没有对视频进行编码(只是编辑元数据),所以对于任何长度的视频文件,该过程在不到 10 毫秒的时间内完成。


推荐阅读