开发者

Android app to search mp4 videos by metadata

开发者 https://www.devze.com 2023-04-09 03:56 出处:网络
I have a set of mp4 files that I need to load onto an SD Card and read in my Android app. The app needs to be able to search the videos by category, so my plan was to add some category info in the mp

I have a set of mp4 files that I need to load onto an SD Card and read in my Android app.

The app needs to be able to search the videos by category, so my plan was to add some category info in the mp4 metadata before loading them (probably in the "descript开发者_如何学运维ion" field) and then use a ManagedQuery on the MediaStore.Video.Media.EXTERNAL_CONTENT_URI to find them.

I have updated the "description" field using Adobe Bridge, but when I look at the tags returned by a search, the "description" field is always null. Clearly, the data I'm writing to the mp4 files is not being picked up when Android looks at the video file.

Is there another way I should be writing/searching video metadata?


You should probably look at MediaStore.Video.VideoColumns.DESCRIPTION.

You can query the MediaStore.Video.Media.EXTERNAL_CONTENT_URI as you would any other content provider: http://developer.android.com/guide/topics/providers/content-providers.html#querying


You can add/delete/lookup metadata fields in MP4 files using JCodec's MetadataEditor class.

If you want to add metadata field to MP4 file you can use:

MetadataEditor mediaMeta = MetadataEditor.createFrom(new
    File("file.mp4"));
Map<String, MetaValue> meta = mediaMeta.getKeyedMeta();
meta.put("com.android.capture.fps", MetaValue.createFloat(25.));
mediaMeta.save(false); // fast mode is off

Alternatively the same can be done from the command line with the CLI tool (MetadataEditorMain):

./metaedit -sk com.android.capture.fps,float=25.0 file.mp4

In the Java code you can get the list of metadata like so:

MetadataEditor mediaMeta = MetadataEditor.createFrom(new
    File("file.mp4"));
Map<String, MetaValue> meta = mediaMeta.getKeyedMeta();
for (String key : meta.keySet()) {
    System.out.println(key + ": " + meta.get(key));
}

OR from the command line:

./metaedit <file.mp4>

Read more about it: http://jcodec.org/docs/working_with_mp4_metadata.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号