- TIKA 教程
- TIKA - 首頁
- TIKA - 概述
- TIKA - 架構
- TIKA - 環境
- TIKA - 引用 API
- TIKA - 檔案格式
- TIKA - 文件型別檢測
- TIKA - 內容提取
- TIKA - 元資料提取
- TIKA - 語言檢測
- TIKA - 圖形使用者介面
- TIKA 有用資源
- TIKA - 快速指南
- TIKA - 有用資源
- TIKA - 討論
TIKA - 提取 mp4 檔案
下面是提取 mp4 檔案內容和元資料所需的程式 -
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 Mp4Parse {
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("example.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));
}
}
}
將上述程式碼另存為 JpegParse.java,並使用以下命令在命令提示符下對其進行編譯 -
javac Mp4Parse.java java Mp4Parse
下面是 Example.mp4 檔案的屬性摘要。
執行上述程式後,你將會得到以下輸出 -
輸出 -
Contents of the document: Metadata of the document: dcterms:modified: 2014-01-06T12:10:27Z meta:creation-date: 1904-01-01T00:00:00Z meta:save-date: 2014-01-06T12:10:27Z Last-Modified: 2014-01-06T12:10:27Z dcterms:created: 1904-01-01T00:00:00Z date: 2014-01-06T12:10:27Z tiff:ImageLength: 360 modified: 2014-01-06T12:10:27Z Creation-Date: 1904-01-01T00:00:00Z tiff:ImageWidth: 640 Content-Type: video/mp4 Last-Save-Date: 2014-01-06T12:10:27Z
廣告