Flutter:如何使用 ffmpeg 从视频中读取数据

Flutter: How to read data from video using ffmpeg

我正在尝试使用 lib https://pub.dev/packages/flutter_ffmpeg

从视频中获取元数据

以下代码不适用于 ffmpeg

  Directory appDocDir = await getApplicationDocumentsDirectory();
  String appDocPath = appDocDir.path;
  File file = File('{$appDocPath}/folder_name/out.mp4');
  final FlutterFFprobe _flutterFFprobe = new FlutterFFprobe();

 _flutterFFprobe.getMediaInformation(file.path).then((info) => print(info));

如何解决上述问题?

文件需要首先进行存储访问,然后给定路径可供 ffmpeg lib 访问

添加存储权限

permission_handler: ^5.0.1 // in pubspec.yaml file

访问视频前请求运行时权限

    var status = await Permission.storage.status;
          if (status.isUndetermined) {
            // You can request multiple permissions at once.
            Map<Permission, PermissionStatus> statuses = await [
              Permission.storage,
            ].request();
            print(statuses[Permission.storage]); // this must show permission granted. 
          }

最后配合ffmpeg使用,存储路径如

          File file = File('/storage/emulated/0/folder_name/out.mp4');
          final FlutterFFprobe _flutterFFprobe = new FlutterFFprobe();

          _flutterFFprobe
              .getMediaInformation(file.path)
              .then((info) => print(info)); // This should print metadata inside of video