iPhone上的Flutter相机插件风景视频

时间:2019-03-25 00:25:02

标签: flutter video-capture

在我的iPhone X的“横向”中运行“相机插件”示例应用程序时,视频无法以正确的方向捕获。 在纵向模式下效果很好。

enter image description here

pubspec.yaml

版本:1.0.0 + 1

环境:   sdk:“> = 2.0.0-dev.68.0 <3.0.0”

依赖性:   扑:     sdk:颤抖

cupertino_icons:^ 0.1.2

相机:^ 0.4.2

path_provider:^ 0.5.0

video_player:^ 0.10.0

firebase_core:^ 0.2.5

颤抖的医生

[✓] Flutter(频道未知,在Mac OS X 10.14.3 18D109上为v1.1.0,语言环境为en-AU)

[✓] Android工具链-为Android设备开发(Android SDK 28.0.3)

[✓] iOS工具链-为iOS设备开发(Xcode 10.1)

[✓] Android Studio(3.2版)

[✓]已连接的设备(1个可用)

2 个答案:

答案 0 :(得分:0)

@Dave,请尝试以下小部件来设置横向预览:


  Widget widTakePhoto2(context) {

       if (!ctlCamera.value.isInitialized) {

          return Container();

        }



    return Stack(

      children: <Widget>[

        RotatedBox(

          quarterTurns: 3,

          child: AspectRatio(

            aspectRatio: ctlCamera.value.aspectRatio,

            child: CameraPreview(ctlCamera),

          ),

        ),

        Center(child: Text(

            (gv.intHomeCameraCountDown > 0) ? gv.intHomeCameraCountDown.toString() : '',

            style: TextStyle(fontSize: sv.dblDefaultFontSize * 3, color: Colors.red, fontWeight: FontWeight.bold)))

      ],

    );

  }

即将小部件的宽高比放入旋转框小部件中,此小部件widtakephoto2应该是脚手架小部件的“主体”。忘记了堆栈小部件,我在拍摄照片或视频之前使用堆栈来显示3、2、1。

答案 1 :(得分:0)

直到获得官方支持后,我才能成功使用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);
}

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