skip to Main Content

I was using video_player to do the rest of the metadata extraction I need but I didn’t find a way to get the resolution with this package.

2

Answers


  1. VideoPlayerController is a ValueNotifier<VideoPlayerValue> and the VideoPlayerValue has a size property that reports the size of the video.

    https://github.com/flutter/packages/blob/f5a45177034bff79d7df07a85077218774aa4a80/packages/video_player/video_player/lib/video_player.dart#L42

    You can add a listener to the VideoPlayerController and be notified when the value changes. Depending on the source, the size of the video can change too (for example if it’s a HLS stream with multiple variants).

    Login or Signup to reply.
  2. dependencies:
    flutter_ffmpeg: ^0.4.1
    
    import 'package:flutter_ffmpeg/flutter_ffmpeg.dart';
    import 'package:flutter_ffmpeg/media_information.dart';
    
    Future<String> getVideoResolution(String videoPath) async {
    final FlutterFFprobe _flutterFFprobe = FlutterFFprobe();
    MediaInformation mediaInformation;
    try {
    mediaInformation = await _flutterFFprobe.getMediaInformation(videoPath);
    if (mediaInformation != null &&
        mediaInformation.getStreams() != null &&
        mediaInformation.getStreams().isNotEmpty) {
      // Assuming the first stream contains the video
      final videoStream = mediaInformation.getStreams()[0];
      if (videoStream != null && videoStream.getAllProperties() != null) {
        final width = videoStream.getAllProperties()['width'];
        final height = videoStream.getAllProperties()['height'];
        return '$width x $height';
          }
        }
       } catch (e) {
         print('Error getting video resolution: $e');
      }
      return 'Unknown';
     }
    
    String resolution = await getVideoResolution('/path/to/your/video.mp4');
    print('Video resolution: $resolution');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search