Android:读取和写入.mp4元数据-Tag [英] Android: Read and Write .mp4 metadata -Tag
问题描述
我想读取和编辑(写入)mp4元数据.特别是我想在Android中读取/写入 Tag 元数据,如下图所示.
I want to read and edit(Write) the mp4 metadata. Particularly I want to read/write Tag metadata in android as shown in below picture.
我在互联网上搜索了此文件,并找到了mp4Parser,但我认为mp4Parser不会写标题关键字.
I searched for this on internet and found mp4Parser, but I think mp4Parser don't write Title Keyword.
对于.jpg文件,我们使用XPKeyword元数据表示标题. 以同样的方式对.mp4文件执行相同的操作.
For .jpg file we use XPKeyword metadata which represents title. So same way how to do same for .mp4 file.
推荐答案
Android SDK包含类 此处.
The Android SDK contains the class MediaMetadataRetriever to retrieve all the metadata values inside your file, you can read more about MetaData values here.
public void readMetaData() {
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"/Android/data/myfile.mp4");
if (file.exists()) {
Log.i(TAG, ".mp4 file Exist");
//Added in API level 10
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(file.getAbsolutePath());
for (int i = 0; i < 1000; i++){
//only Metadata != null is printed!
if(retriever.extractMetadata(i)!=null) {
Log.i(TAG, "Metadata :: " + retriever.extractMetadata(i));
}
}
} catch (Exception e) {
Log.e(TAG, "Exception : " + e.getMessage());
}
} else {
Log.e(TAG, ".mp4 file doesn´t exist.");
}
}
要编辑/写入元数据,Android SDK没有任何方法(可能是版权问题),但是您可以使用以下选项:
To edit/write metadata, Android SDK doesn´t have any method, probably by copyright issues, but you can use options like:
https://github.com/sannies/mp4parser
http://multimedia.cx/eggs/supplying-ffmpeg-with-元数据/
这篇关于Android:读取和写入.mp4元数据-Tag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!