在我的 iPhone X 上横向运行相机插件示例应用程序时,视频无法以正确的方向捕获。 它在肖像中效果很好。
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 医生
[✓] 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)
最佳答案
在官方包中获得支持之前,我已经成功地使用 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 毫秒的时间内完成。
关于iPhone 上的 Flutter Camera 插件风景视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55329901/