簡體   English   中英

如何從視頻文件的“媒體創建”列中提取日期?

[英]How can I extract the date from the “Media Created” column of a video file?

我需要使用 C# 從“媒體創建”列(在下面的示例照片中以綠色突出顯示)中提取日期。

在我的示例中,“媒體創建”和“日期”列完全相同。 但是,也有一些情況並非如此。 “媒體創建”列包含實際錄制視頻的正確日期。

看到這個專欄了嗎?

這是我用來獲取它的函數。 感謝 Aziz 為我指明了正確的方向:

Shell shell = new ShellClass();
Folder folder = shell.NameSpace(_File.DirectoryName);
FolderItem file = folder.ParseName(_File.Name);

// These are the characters that are not allowing me to parse into a DateTime
char[] charactersToRemove = new char[] {
    (char)8206,
    (char)8207
};

// Getting the "Media Created" label (don't really need this, but what the heck)
string name = folder.GetDetailsOf(null, 191);

// Getting the "Media Created" value as a string
string value = folder.GetDetailsOf(file, 191).Trim();

// Removing the suspect characters
foreach (char c in charactersToRemove)
    value = value.Replace((c).ToString(), "").Trim();

// If the value string is empty, return DateTime.MinValue, otherwise return the "Media Created" date
return value == string.Empty ? DateTime.MinValue : DateTime.Parse(value);

可以使用Folder.GetDetailsOf()方法獲取擴展文件屬性。 根據此線程,可以使用 177 的屬性 ID 檢索媒體創建日期

還有另一種檢索數據的方法,即使用Microsoft.WindowsAPICodePack.Shell命名空間。

ShellObject shell = ShellObject.FromParsingName(path);

var data = shell.Properties.System.Media.DateEncoded;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM