本文主要是介绍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 typeBodyContentHandler handler = new BodyContentHandler();Metadata metadata = new Metadata();FileInputStream inputstream = new FileInputStream(new File("example.mp4"));ParseContext pcontext = new ParseContext();//Html parserMP4Parser 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
//原文出自【易百教程】,商业转载请联系作者获得授权,非商业转载请保留原文链接:https://www.yiibai.com/tika/tika_extracting_mp4_files.html
这篇关于TIKA提取mp4文件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!