java 提取图片与视频的元数据

代码

jar包:https://download.csdn.net/download/qq_40971752/10925501

Exif支持的格式有,这是github里的项目介绍,有兴趣可以看看https://github.com/drewnoakes/metadata-extractor

官网:https://drewnoakes.com/code/exif/

java 提取图片与视频的元数据_第1张图片

 这是ImageMetadataReader类里面的源码,只需要用这个类就能读取其他格式文件的元数据

 

java 提取图片与视频的元数据_第2张图片

import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;

import com.drew.imaging.ImageProcessingException;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;

import com.drew.imaging.ImageMetadataReader;

@SpringBootTest
public class ExifTest {

	@Test
	public void test() throws ImageProcessingException, IOException {
		// File file = new
		// File("C:/Users/yunxun/Desktop/测试文档/format/66_635142_271cb2f6a8550e7.raw");
		// File file = new File("C:/Users/yunxun/Desktop/测试文档/format/1.bmp");
		// File file = new File("C:/Users/yunxun/Desktop/测试文档/format/1.gif");
		// File file = new File("C:/Users/yunxun/Desktop/测试文档/format/1.tif");
		// File file = new File("C:/Users/yunxun/Desktop/测试文档/format/1.png");
			File file = new File("C:/Users/yunxun/Desktop/测试文档/format/1.jpg");
        //File file = new
        //File("C:/Users/yunxun/Desktop/测试文档/format/chichen.mp4");
		//File file = new File("C:/Users/yunxun/Desktop/测试文档/format/D54A57D5BFA88B517F04776EB4122250.avi");
		// File file = new
		// File("C:/Users/yunxun/Desktop/测试文档/format/SampleVideo_320x240_30mb.3gp");
		// // 失败

		Metadata data = ImageMetadataReader.readMetadata(file);
		// Mp4MetadataReader.readMetadata(file);
		for (Directory di : data.getDirectories()) {
			for (com.drew.metadata.Tag tag : di.getTags()) {
				if (tag.getTagName().contains("Unknown")) {
					System.err.println("未知标签" + tag.getTagName());
				} else {
					System.out.println(tag.toString());
				}
			}
		}
	}
}

下面是读取出来的结果

[JPEG] Compression Type - Baseline
[JPEG] Data Precision - 8 bits
[JPEG] Image Height - 300 pixels
[JPEG] Image Width - 480 pixels
[JPEG] Number of Components - 3
[JPEG] Component 1 - Y component: Quantization table 0, Sampling factors 2 horiz/2 vert
[JPEG] Component 2 - Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert
[JPEG] Component 3 - Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert
[JFIF] Version - 1.1
[JFIF] Resolution Units - inch
[JFIF] X Resolution - 72 dots
[JFIF] Y Resolution - 72 dots
[JFIF] Thumbnail Width Pixels - 0
[JFIF] Thumbnail Height Pixels - 0
[Exif IFD0] Image Description - title
[Exif IFD0] Artist - 黑土
[Exif IFD0] Rating - 5
[Exif IFD0] Copyright - 黑土工作室
未知标签Unknown tag (0x4749)
[Exif IFD0] Windows XP Title - title
[Exif IFD0] Windows XP Comment - 开会
[Exif IFD0] Windows XP Author - 黑土
[Exif IFD0] Windows XP Keywords - 没得标记
[Exif IFD0] Windows XP Subject - 蓝色主题
[Exif IFD0] Padding - [1996 values]
[Exif SubIFD] Exposure Program - Manual control
[Exif SubIFD] ISO Speed Ratings - 2
[Exif SubIFD] Date/Time Original - 2019:01:14 16:38:44
[Exif SubIFD] Date/Time Digitized - 2019:01:14 16:38:44
[Exif SubIFD] Metering Mode - Average
[Exif SubIFD] White Balance - Daylight
[Exif SubIFD] Flash - Flash did not fire
[Exif SubIFD] Sub-Sec Time Original - 80
[Exif SubIFD] Sub-Sec Time Digitized - 80
[Exif SubIFD] Padding - [2060 values]
[XMP] XMP Value Count - 20
[Huffman] Number of Tables - 4 Huffman tables
[File Type] Detected File Type Name - JPEG
[File Type] Detected File Type Long Name - Joint Photographic Experts Group
[File Type] Detected MIME Type - image/jpeg
[File Type] Expected File Name Extension - jpg
[File] File Name - 1.jpg
[File] File Size - 39623 bytes
[File] File Modified Date - 星期一 一月 14 16:51:05 +08:00 2019

 

 

 

你可能感兴趣的:(Java)