You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用metadata-extractor-2.19.0读取MP4/MOV等视频文件时为何抛出格式不支持异常?

问题:使用metadata-extractor读取MP4/QT/MOV/3GP文件时抛出格式不支持异常

代码示例

我用metadata-extractor-2.19.0.jar编写了如下代码读取文件元数据:

Metadata metadata = null;

try {
    metadata = ImageMetadataReader.readMetadata( pathSourceFile.toFile() );
} 
catch(ImageProcessingException ipe) {
    System.out.println("The following exception occured while attempting to read metadata from " + pathSourceFile.toString());
    ipe.printStackTrace(System.out);
    throw ipe;
}

异常信息

当输入MP4、QT、MOV或3GP格式文件时,代码抛出ImageProcessingException: File format is not supported异常,示例栈信息如下:

The following exception occured while attempting to read metadata from C:\Test Input\Borg.mp4
com.drew.imaging.ImageProcessingException: File format is not supported
    at com.drew.imaging.ImageMetadataReader.readMetadata(ImageMetadataReader.java:146)
    at com.drew.imaging.ImageMetadataReader.readMetadata(ImageMetadataReader.java:162)
    at com.mbm.mediaorganizer.DirectoryNameBuilder.getTags(DirectoryNameBuilder.java:182)
    at com.mbm.mediaorganizer.DirectoryNameBuilder.getDirectoryName(DirectoryNameBuilder.java:61)
    at com.mbm.mediaorganizer.RelocateFileVisitor.relocateFile(RelocateFileVisitor.java:114)
    at com.mbm.mediaorganizer.RelocateFileVisitor.visitFile(RelocateFileVisitor.java:96)
    at com.mbm.mediaorganizer.RelocateFileVisitor.visitFile(RelocateFileVisitor.java:1)
    at java.base/java.nio.file.Files.walkFileTree(Files.java:2811)
    at java.base/java.nio.file.Files.walkFileTree(Files.java:2882)
    at com.mbm.mediaorganizer.MediaOrganizer.run(MediaOrganizer.java:126)
    at com.mbm.mediaorganizer.MediaOrganizer.main(MediaOrganizer.java:40)

目标文件的MediaInfo信息

General
Complete name                            : C:\Test Input\Borg.mp4
Format                                   : MPEG-4
Format profile                           : Base Media / Version 2
Codec ID                                 : mp42 (mp42/mp41)
File size                                : 171 MiB
Duration                                 : 1 min 40 s
Overall bit rate mode                    : Variable
Overall bit rate                         : 14.3 Mb/s
Encoded date                             : UTC 2017-07-28 20:50:07
Tagged date                              : UTC 2017-07-28 20:50:41
©TIM                                     : 00:00:00:00
©TSC                                     : 30000
©TSZ                                     : 1001

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L4.2
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, RefFrames               : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 1 min 40 s
Bit rate mode                            : Variable
Bit rate                                 : 13.9 Mb/s
Maximum bit rate                         : 16.0 Mb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 29.970 (30000/1001) FPS
Standard                                 : NTSC
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.224
Stream size                              : 167 MiB (98%)
Language                                 : English
Encoded date                             : UTC 2017-07-28 20:50:07
Tagged date                              : UTC 2017-07-28 20:50:07
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709

Audio
ID                                       : 2
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Format profile                           : LC
Codec ID                                 : mp4a-40-2
Duration                                 : 1 min 40 s
Source duration                          : 1 min 40 s
Bit rate mode                            : Variable
Bit rate                                 : 317 kb/s
Maximum bit rate                         : 349 kb/s
Channel(s)                               : 2 channels
Channel positions                        : Front: L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 46.875 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 3.80 MiB (2%)
Source stream size                       : 3.80 MiB (2%)
Language                                 : English
Encoded date                             : UTC 2017-07-28 20:50:07
Tagged date                              : UTC 2017-07-28 20:50:07

原因分析

metadata-extractor 2.19.0版本原生不支持MP4、QT、MOV、3GP这类基于ISO BMFF容器的视频格式。这个库在早期版本的核心定位是处理图片格式(如JPEG、PNG、TIFF等)的元数据读取,对视频格式的支持是后续版本才添加的。

如果需要读取这类视频文件的元数据,你可以:

  • 升级metadata-extractor到2.20.0及以上版本(该版本开始正式支持MP4等视频格式的元数据读取)
  • 换用专门针对视频元数据处理的库

内容的提问来源于stack exchange,提问作者mbmast

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 12:59:56