static void Main() { string path = "Q:\\XXX\\ZZ\\201014 众\\2020.10.14_104356.mov"; var directories = ImageMetadataReader.ReadMetadata(path); FileSystemInfo file = new FileInfo(path); var mi = new MediaInfo(); mi.Open(file.FullName); Console.WriteLine(mi.Inform()); mi.Close(); mi.Dispose(); foreach (var directory in directories) { foreach (var tag in directory.Tags) { Console.WriteLine($"[{directory.Name}] {tag.Name} = {tag.Description}"); } if (directory.HasError) { foreach (var error in directory.Errors) { Console.WriteLine($"ERROR: {error}"); } } } Console.ReadKey(); }
private static Dictionary <string, string> VidDtQuery(FileSystemInfo file) { string strDt; var mi = new MediaInfo(); mi.Open(file.FullName); try { strDt = mi.Get(StreamKind.Video, 0, "Encoded_Date"); if (string.IsNullOrEmpty(strDt)) { strDt = mi.Get(StreamKind.Video, 0, "Tagged_Date"); } if (string.IsNullOrEmpty(strDt)) { strDt = mi.Get(StreamKind.General, 0, "Recorded_Date"); } else if (string.IsNullOrEmpty(strDt)) { return(null); } mi.Close(); } catch (Exception) { mi.Close(); return(null); } mi.Dispose(); const string strDtFormat = "yyyy.MM.dd_HHmmss"; var strTz = strDt.Substring(0, 3); strDt = strDt.Replace(strTz + " ", ""); var dtDt = DateTime.ParseExact(strDt, "yyyy-MM-dd HH:mm:ss", CultureInfo.CurrentCulture); dtDt = ConvertTimeFromUtc(dtDt, Local); var startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0, 0)); var timestamp = (dtDt.Ticks - startTime.Ticks) / 10000; var dictDt = new Dictionary <string, string> { { "datetime", dtDt.ToString(strDtFormat) }, { "timestamp", timestamp + "" } }; return(dictDt); }
private void MetadateQuery(FileInfo file) { Text = "RainySummer/MediaInfo+" + " - " + file.FullName; treeView.BeginUpdate(); treeView.Nodes.Clear(); treeView.Nodes.Add(file.FullName); try { var mi = new MediaInfo(); mi.Open(file.FullName); int fileType = 0; // Default is Other File Type string miFile = mi.Inform(); string[] miFiles = miFile.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (var miLine in miFiles) { if (miLine == "Image") { fileType = 1; break; } else if (miLine == "Video" || miLine == "Audio") { fileType = 2; break; } } if (fileType == 1) { // Picture File mi.Close(); var directories = ImageMetadataReader.ReadMetadata(file.FullName); int index = 0; foreach (var directory in directories) { string directoryName = directory.Name; Console.WriteLine(directoryName); treeView.Nodes[0].Nodes.Add(directoryName); for (var j = 0; j < directory.TagCount; j++) { string tagName = directory.Tags[j].ToString(); tagName = tagName.Replace("[" + directoryName + "] ", ""); tagName = tagName.Replace(" - ", ": "); treeView.Nodes[0].Nodes[index].Nodes.Add(tagName); } index++; } } else if (fileType == 2) { // Video or Audio File string mediaInfo = mi.Inform(); string[] miParameters = mediaInfo.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); int index = -1; foreach (var miOutput in miParameters) { if (miOutput == "General" || miOutput == "Video" || miOutput == "Audio" || miOutput == "Text") { treeView.Nodes[0].Nodes.Add(miOutput); index++; } else { string tagName = Regex.Replace(miOutput, "\\s{2,}:", ":"); treeView.Nodes[0].Nodes[index].Nodes.Add(tagName); } } } else { // string mediaInfo = mi.Inform(); string[] miParameters = mediaInfo.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); int index = -1; foreach (var miOutput in miParameters) { if (miOutput == "General" || miOutput == "Text") { treeView.Nodes[0].Nodes.Add(miOutput); index++; } else { string tagName = Regex.Replace(miOutput, "\\s{2,}:", ":"); treeView.Nodes[0].Nodes[index].Nodes.Add(tagName); } } treeView.Nodes[0].Nodes.Add("System"); index++; treeView.Nodes[0].Nodes[index].Nodes.Add("Extension: " + file.Extension); treeView.Nodes[0].Nodes[index].Nodes.Add("File Length: " + file.Length + " bytes"); string isReadOnly = file.IsReadOnly ? "Yes" : "No"; treeView.Nodes[0].Nodes[index].Nodes.Add("Read Only: " + isReadOnly); treeView.Nodes[0].Nodes[index].Nodes.Add("Creation Time: " + file.CreationTime); treeView.Nodes[0].Nodes[index].Nodes.Add("Creation Time Utc: " + file.CreationTimeUtc); treeView.Nodes[0].Nodes[index].Nodes.Add("Last Access Time: " + file.LastAccessTime); treeView.Nodes[0].Nodes[index].Nodes.Add("Last Access Time Utc: " + file.LastAccessTimeUtc); treeView.Nodes[0].Nodes[index].Nodes.Add("Last Write Time: " + file.LastWriteTime); treeView.Nodes[0].Nodes[index].Nodes.Add("Last Write TimeUtc: " + file.LastWriteTimeUtc); } mi.Dispose(); } catch (Exception) { treeView.EndUpdate(); return; } treeView.ExpandAll(); treeView.EndUpdate(); treeView.Nodes[0].EnsureVisible(); treeView.Visible = true; copyToolStripMenuItem.Visible = true; closeToolStripMenuItem.Visible = true; closeToolStripMenuItem1.Visible = true; }
private static void CloseMediaInfo() { minstance?.Dispose(); minstance = null; }