我很难从mp4文件中读取元数据。我想知道视频会持续多长时间。
这个文件位于资产下/确切地说,路径是资产/test.mp4
int getLength() {
var file = File('./assets/test.mp4');
// get the length
var length;
return length;
}
发布于 2022-07-22 21:37:02
您可以使用视频播放器插件并使用以下代码
VideoPlayerController controller = VideoPlayerController.file('fileNameHere');
await controller.initialize();
print(controller.value.duration);
发布于 2022-07-23 05:25:21
使用这个插件ffmpeg:^0.4.2
print("Duration: ${info.getMediaProperties()['duration']}");
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");
});
}
}
}
}
});
https://stackoverflow.com/questions/73085041
复制相似问题