3

I'm trying to determine the resolution of video files using Shell32 in C#, but the properties return empty strings, although Windows shell displays the information just fine.

Please note that I cannot incorporate any 3rd party libraries for this task (DirectShow or others).

This behavior persists for different video files. Sadly, none of the answers provided in here have been helpful.

I am using the following code to extract the information:

Shell32.Shell shell = new Shell32.Shell();
Shell32.Folder objFolder;

objFolder = shell.NameSpace(Path.GetDirectoryName(videoFile.FullName));
FolderItem objFile = objFolder.ParseName(videoFile.Name);

List<string> arrHeaders = new List<string>();
for (int i = 0; i < 1000; i++) {
  string header = objFolder.GetDetailsOf(null, i);
  if (String.IsNullOrEmpty(header))
    continue;
  arrHeaders.Add(header);
}

var length = objFolder.GetDetailsOf(
  objFile, arrHeaders.FindIndex(h => h == "Length"));
var resWidth = objFolder.GetDetailsOf(
  objFile, arrHeaders.FindIndex(h => h == "Frame width"));
var resHeight = objFolder.GetDetailsOf(
  objFile, arrHeaders.FindIndex(h => h == "Frame height"));

For the following file, I expect resWidth to have the value "1920" and resHeight to have the value "1080" but they both hold empty strings. Both properties exist in arrHeaders, specifically in indexes 301 and 303 on my system.

Hearthstone.mp4 file properties

As a side note, the Length property works as expected.

Gildon
  • 51
  • 6

1 Answers1

0

Wow, sorry about that. I seem to have totally skipped over the fact that I enumerate the indexes incorrectly since I skip empty headers. Problem solved!

Gildon
  • 51
  • 6