【问题标题】:How can I extract the date from the "Media Created" column of a video file?如何从视频文件的“媒体创建”列中提取日期?
【发布时间】:2012-01-11 05:02:24
【问题描述】:

我需要使用 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);

【问题讨论】:

  • 1. 208 而不是 Windows 10 上的 191。 2. 代码应该在单线程单元 (STA) 中启动。使用 [STAThread] 属性或带有 ApartmentState.STA 的线程
  • 如果你用的是Python,可以试试Getting metadata for MOV video
  • 感谢编辑,请问 ShellClass 类的程序集/命名空间是什么?

标签: c# .net video extract


【解决方案1】:

扩展文件属性可以通过Folder.GetDetailsOf()方法获取。 根据thread媒体创建日期可以使用属性 id 177 检索。

【讨论】:

  • 效果很好,除了一些事情。属性 id 是 191。我猜它与操作系统有关(我在 Windows 7 64 位上)。那里还有一些奇怪的字符无法正确解析为 DateTime: (char)8206 (char)8207 但是一旦它们被剥离,它就完美地工作了!非常感谢!
  • 有一个解释here如何获得正确的ID和避免幻数。
【解决方案2】:

还有另一种检索数据的方法,使用 Microsoft.WindowsAPICodePack.Shell 命名空间。

ShellObject shell = ShellObject.FromParsingName(path);

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

【讨论】:

  • 好点。对于 Gopro MP4 文件,“System.Media.DateEncoded”属性返回媒体的创建日期。
猜你喜欢
  • 2015-10-09
  • 1970-01-01
  • 1970-01-01
  • 2012-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多