Flutter ffmpeg can't get width and height

Viewed 25

I'm trying to retrive some info like duration,width and height from videos i pick from the phone gallery. I'm using :

 flutter_ffmpeg: ^0.4.2

this is the code i use :

Future<Map?> getVideoInfo(String VideoPath) async {
    bool errorResult = false;
    FlutterFFprobe fFprobe = FlutterFFprobe();
    String? duration = "0";
    String? width = "0";
    String? height = "0";
    await fFprobe.getMediaInformation(VideoPath).then((info) {
      duration = info.getAllProperties()['duration'].toString();
      width = info.getAllProperties()['width'].toString();
      height = info.getAllProperties()['height'].toString();
    }, onError: (value) {
      errorResult = true;
    }).catchError((error) {
      errorResult = true;
    });

    if (errorResult == true) {
      Map resultmap = {"width": "0", "height": "0", "duration": "0"};
      return resultmap;
    }
    Map resultmap = {"width": width, "height": height, "duration": duration};
    return resultmap;
  }

According to documentation https://pub.dev/packages/flutter_ffmpeg i'm trying to retrive elements in that way:

info.getAllProperties()['width'].toString();

but i can retrive only duration, width and eight are always null. Values are in the getAllProperties dictionary because i can see "width=1920 and height=824" using the Vscode debugger. There is only a difference beetween those voices and "duration" , they are grayed out by the Vscode debugger insted of duration that is "red". Anyway, why i can't access width and eight even if they seems to be accessible?

1 Answers

i have modify the code in that way and now it works:

Future<Map?> getVideoSize(String croppedVideoPath) async {
    bool errorResult = false;
    FlutterFFprobe fFprobe = FlutterFFprobe();
    double? duration;
    String? width = "0";
    String? height = "0";
    await fFprobe.getMediaInformation(croppedVideoPath).then((info) {
      duration = double.tryParse(info.getMediaProperties()!['duration']);

      if (info.getStreams() != null) {
        List<StreamInformation>? streams = info.getStreams();

        if (streams!.length > 0) {
          for (var stream in streams) {
            width = stream.getAllProperties()['width'].toString();
            height = stream.getAllProperties()['width'].toString();
           
          }
        }
      }
    }, onError: (value) {
    
      errorResult = true;
    }).catchError((error) {
     
      errorResult = true;
    });

    if (errorResult == true) {
      Map resultmap = {"width": "0", "height": "0"};
      return resultmap;
    }
    Map resultmap = {"width": width, "height": height};
    return resultmap;
  }

Seems that properties need to accessed calling

info.getStreams()
Related