我正在编写代码以从元数据中获取视频创建日期和时间,我使用以下代码来获取创建日期
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(path_to_video);
String date = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE);
它在除三星Galaxy S7之外的所有设备上都很完美,它只返回" YYYY MM DD"格式,没有时间戳我需要日期和时间戳。
非常感谢这方面的任何帮助。
答案 0 :(得分:1)
对于打印视频的元数据信息,FFMPEG是最佳选择,
ffmpeg -i input_video -f ffmetadata metadata.txt
此命令可帮助我获取所需信息。
答案 1 :(得分:1)
我遇到了类似的问题。我处理了两种日期格式如下:
//pass date fetched from MetadataRetriever class to below method.
public static String formatMediaDate(String date){
String formattedDate = "";
try {
Date inputDate = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.getDefault()).parse(date);
formattedDate = new SimpleDateFormat("dd MMMM yyyy", Locale.getDefault()).format(inputDate);
}
catch (Exception e){
Log.w(TAG, "error parsing date: ", e);
try {
Date inputDate = new SimpleDateFormat("yyyy MM dd", Locale.getDefault()).parse(date);
formattedDate = new SimpleDateFormat("dd MMMM yyyy", Locale.getDefault()).format(inputDate);
} catch (Exception ex) {
Log.e(TAG, "error parsing date: ", ex);
}
}
return formattedDate;
}