首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >获取mp4文件的长度/持续时间

获取mp4文件的长度/持续时间
EN

Stack Overflow用户
提问于 2022-07-22 19:05:58
回答 2查看 188关注 0票数 0

我很难从mp4文件中读取元数据。我想知道视频会持续多长时间。

这个文件位于资产下/确切地说,路径是资产/test.mp4

代码语言:javascript
运行
复制
  int getLength() {
    var file = File('./assets/test.mp4');

    // get the length
    var length;

    return length;
  }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-07-22 21:37:02

您可以使用视频播放器插件并使用以下代码

播放器

代码语言:javascript
运行
复制
VideoPlayerController controller = VideoPlayerController.file('fileNameHere');
await controller.initialize();

print(controller.value.duration);
票数 0
EN

Stack Overflow用户

发布于 2022-07-23 05:25:21

使用这个插件ffmpeg:^0.4.2

print("Duration: ${info.getMediaProperties()['duration']}");

代码语言:javascript
运行
复制
final FlutterFFprobe _flutterFFprobe = new FlutterFFprobe();

 _flutterFFprobe.getMediaInformation("<file path or uri>").then((info) {
     print("Media Information");

     print("Path: ${info.getMediaProperties()['filename']}");
     print("Format: ${info.getMediaProperties()['format_name']}");
     print("Duration: ${info.getMediaProperties()['duration']}");
     print("Start time: ${info.getMediaProperties()['start_time']}");
     print("Bitrate: ${info.getMediaProperties()['bit_rate']}");
     Map<dynamic, dynamic> tags = info.getMediaProperties()['tags'];
     if (tags != null) {
         tags.forEach((key, value) {
             print("Tag: " + key + ":" + value + "\n");
         });
     }

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

         if (streams.length > 0) {
             for (var stream in streams) {
                 print("Stream id: ${stream.getAllProperties()['index']}");
                 print("Stream type: ${stream.getAllProperties()['codec_type']}");
                 print("Stream codec: ${stream.getAllProperties()['codec_name']}");
                 print("Stream full codec: ${stream.getAllProperties()['codec_long_name']}");
                 print("Stream format: ${stream.getAllProperties()['pix_fmt']}");
                 print("Stream width: ${stream.getAllProperties()['width']}");
                 print("Stream height: ${stream.getAllProperties()['height']}");
                 print("Stream bitrate: ${stream.getAllProperties()['bit_rate']}");
                 print("Stream sample rate: ${stream.getAllProperties()['sample_rate']}");
                 print("Stream sample format: ${stream.getAllProperties()['sample_fmt']}");
                 print("Stream channel layout: ${stream.getAllProperties()['channel_layout']}");
                 print("Stream sar: ${stream.getAllProperties()['sample_aspect_ratio']}");
                 print("Stream dar: ${stream.getAllProperties()['display_aspect_ratio']}");
                 print("Stream average frame rate: ${stream.getAllProperties()['avg_frame_rate']}");
                 print("Stream real frame rate: ${stream.getAllProperties()['r_frame_rate']}");
                 print("Stream time base: ${stream.getAllProperties()['time_base']}");
                 print("Stream codec time base: ${stream.getAllProperties()['codec_time_base']}");

                 Map<dynamic, dynamic> tags = stream.getAllProperties()['tags'];
                 if (tags != null) {
                   tags.forEach((key, value) {
                     print("Stream tag: " + key + ":" + value + "\n");
                   });
                 }
             }
         }
     }
 });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73085041

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档