Jitesh Mohite
Jitesh Mohite

Reputation: 34250

Flutter: How to read data from video using ffmpeg

I am trying to fetch the metadata from the video for that using lib https://pub.dev/packages/flutter_ffmpeg,

Below code is not working with 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));

How could I resolve the above one?

Upvotes: 0

Views: 1973

Answers (1)

Jitesh Mohite
Jitesh Mohite

Reputation: 34250

File required storage access first and then given path is accessible to ffmpeg lib

Add Storage Permission

permission_handler: ^5.0.1 // in pubspec.yaml file

Ask for runtime permission before accessing video

    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. 
          }

Finally, use it with ffmpeg with storage path like

          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

Upvotes: 1

Related Questions