Sudhansu CronJ
Sudhansu CronJ

Reputation: 195

How to extract Dart/Flutter video metadata

I am developing a flutter demo app. I want to use metadata about a video in my phone storage. I am able to extract the path of that video, but don't know how to extract its metadata in dart/flutter.

I need the following metadata:

  1. Duration of video
  2. Name of video
  3. Size of video
  4. When video was taken

Upvotes: 16

Views: 22043

Answers (3)

Kirill Karmazin
Kirill Karmazin

Reputation: 6761

One of the ways to get the creation time of the video in FLutter is to use flutter_ffmpeg plugin.

  1. Add it to the pubspec.yaml:

    dependencies:
       flutter_ffmpeg: ^0.3.0
    
  2. Get the file path of your video, for example with file_picker:

    File pickedFile = await FilePicker.getFile(); 
    
  3. Get meta data of the video by its path using ffmpeg:

     final FlutterFFprobe flutterFFprobe = FlutterFFprobe();
     MediaInformation mediaInformation = await flutterFFprobe.getMediaInformation(pickedFile.path);
     Map<dynamic, dynamic> mp = mediaInformation.getMediaProperties();
     String creationTime = mp["tags"]["creation_time"];
     print("creationTime: $creationTime");
    

And in the console you'll get smth like this:

I/flutter (13274): creationTime: 2020-09-24T17:59:24.000000Z

Along with creation time, there are other useful details: enter image description here

Note: adding this plugin to your app increases the weight of your final apk!

Upvotes: 9

Md Wasim Reza Ali
Md Wasim Reza Ali

Reputation: 11

your code is correct Mazin Ibrahim you just need to initialize it. the future value will return all the details.

Future getVideo() async {

   await MultiMediaPicker.pickVideo(source: ImageSource.gallery).then((video){

     File _video = video;
     VideoPlayerController fileVideocontroller = new VideoPlayerController.file(_video)
     ..initialize().then((_) {

       debugPrint("========"+fileVideocontroller.value.duration.toString());
     });
   });
}

Upvotes: 0

Mazin Ibrahim
Mazin Ibrahim

Reputation: 7889

You can use the VideoPlayerController.file constructor from the official video player plugin (which is maintained by the official google team so you don't have to worry about its future and stability) to access the file and get the following meta after you install the package:

first this is your VideoPlayerController:

 VideoPlayerController controller = new VideoPlayerController.file('');//Your file here
  1. Duration:

    controller.value.duration ;
    
  2. Video Name, this should already be possessed with you as you can reach the file path and pass it to the player constructor.

3.Video Size:

    controller.value.size ;

4.As for when the video was taken I can't help you with this. You have to find another way to figure it out.

Upvotes: 28

Related Questions