본문 바로가기
Back-end/JAVA & Spring

[JAVA] mp4 parser metadata 확인 (mp4 info 확인)

by 꼬바리 2021. 11. 30.

mp4 파일들의 메타 데이터를 확인하는 소스 입니다.

해당 mp4에서 정보를 확인 하는 소스 입니다. (라이브러리에 첨부되어있는 jar 파일을 추가해 주세요.)

tika-core-1.8
0.51MB
aspectjrt-1.7
0.11MB
tika-parsers-1.8
0.60MB
isoparser-1.0
0.81MB

메이븐 디펜던시 추가시

<!-- https://mvnrepository.com/artifact/org.apache.tika/tika-core -->
<dependency>
    <groupId>org.apache.tika</groupId>
    <artifactId>tika-core</artifactId>
    <version>1.8</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjrt -->
<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjrt</artifactId>
    <version>1.7.3</version>
</dependency>


<!-- https://mvnrepository.com/artifact/org.apache.tika/tika-parsers -->
<dependency>
    <groupId>org.apache.tika</groupId>
    <artifactId>tika-parsers</artifactId>
    <version>1.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.googlecode.mp4parser/isoparser -->
<dependency>
    <groupId>com.googlecode.mp4parser</groupId>
    <artifactId>isoparser</artifactId>
    <version>1.0.6</version>
</dependency>

마지막 추가된 디펜던지 isoparser 는 첨부된 파일과 버전이 다르다.
1.0.7.1버전이 소멸.. 한거같다

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.mp4.MP4Parser;
import org.apache.tika.sax.BodyContentHandler;

import org.xml.sax.SAXException;

public class MovieParser {

	public static void main(final String[] args) throws IOException,SAXException, TikaException {

		//detecting the file type
		BodyContentHandler handler = new BodyContentHandler();
		Metadata metadata = new Metadata();
		FileInputStream inputstream = new FileInputStream(new File("C:/tmp/movie/204950.fullhd.mp4"));
		ParseContext pcontext = new ParseContext();

		//Html parser
		MP4Parser MP4Parser = new MP4Parser();
		MP4Parser.parse(inputstream, handler, metadata,pcontext);
		//System.out.println("Contents of the document:  :" + handler.toString());
		System.out.println("Metadata of the document:");
		String[] metadataNames = metadata.names();

		for(String name : metadataNames) {
			System.out.println(name + ": " + metadata.get(name));
		}
	}  
}


[결과]


728x90
반응형

댓글