Video tags and keywords

I will show you how to write tags to video files so they can be searched from Windows file explorer.

In Fast video cataloger, you can assign tags (keywords) to videos as well as to specific points in time inside of the video files. You can quickly search across all your videos even if the video files are archived away and not accessible. Keywords in Fast video cataloger are stored in the catalog and not in the video files. If you want to be able to use Windows search and have the same tags as in Fast video cataloger you need to transfer the tags to the actual video files. Fortunately, this can be easily be done with the integrated script support in Fast video cataloger.

NOTE: In Fast Video Cataloger Version 7 and later you can store tags in the Windows metadata section for video formats that support this. You find this option in preferences on the metadata tab.

Setting tags to video files

If you don’t care about the details simply copy the script at the bottom of this text into the script window in Fast video cataloger. Select the videos you want to transfer tags to and run the script.

Tags on files in Windows

When you do a search in Windows you search on metadata stored inside files. Windows can build and maintain an index of all this metadata to make searching a bit quicker so that it does not have to access all files every time you search. What metadata you can add to a file depends on the file format. It is not the same for all files and for some file formats it is actually quite limited. For example, not all video file formats support tags. To see what tags are set to a video file, click properties in Explorer and go to the Details tab.

Tags in video file details

Video detail property page

You can also get to the properties from inside Fast video cataloger, just right-click the video in the catalog list and select File/Properties.

If you see a Tags line in the property sheet then the format support Tags. You will also find a rating, title, and a comments field. If the tags field is not there for the file format, that format simply does not support tags. If the format does not support tags then this script will fail when trying to assign tags to it. This is also one of the reasons why Fast video cataloger does not store tags inside of the video files by default.

C# code walkthrough


We will use the "Microsoft.WindowsAPICodePack.Shell" package to write the tags to files. To be able to use that package we need to add a reference to it from our project. If you are copying this code for a normal C# project, i.e. not a Fast video cataloger script you can add the reference in the Visual studio solution (look in references). For a script in Fast video cataloger we don’t have a solution, the way we need to do this is with a special comment. The first line in the script adds that reference: //css_ref Microsoft.WindowsAPICodePack;. Then we also need to add the using lines to bring in the library to the file: using Microsoft.WindowsAPICodePack.Shell;. Now that we have solved the extra dependencies we can use this library to write our tags to the videos.

The code

The beginning of this script is very similar to most other Fast video cataloger sample scripts. We get the id of the selected video(s) and then use that id to the path to the file.

The ConvertToLocalPath(...) is needed in case your catalog has used special folders and will convert these special folders into an absolute path. If the path is already absolute this will do nothing.

Then we need to get a shell reference to the file with ShellFile.FromFilePath. In the Windows shell not all entries are files. The shell API references entries in the shell using pidl and not normal file paths. This API call simply gets the path in the shell to the file.

The next step is to get the function to write to the property page of the shell object. file.Properties.GetPropertyWriter(); give us the interface we need and then we only need to call WriteProperty(..) to write property values of the file. For the calls to succeed the property needs to be supported by the file format as mentioned before and the file needs to be writable.

External references

As all other samples this sample is available on the Fast video cataloger github repository.

Documentation on properties for Windows files can be found here

C# code – Tag to video file

//css_ref Microsoft.WindowsAPICodePack;
using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
using System.Collections.Generic;
using System.Runtime;
using System;
using VideoCataloger;

namespace VideoCataloger
  public class WriteTags
    static public void Run(IScripting scripting, string argument)
        var catalog = scripting.GetVideoCatalogService();
        ISelection selection = scripting.GetSelection();
        List selected = selection.GetSelectedVideos();
        foreach (long video in selected)
            var entry = catalog.GetVideoFileEntry(video);

            IUtilities utilities = scripting.GetUtilities();
            var selected_path = utilities.ConvertToLocalPath(entry.FilePath);

            var file = ShellFile.FromFilePath(selected_path );

            var selected_videos = new long[1];
            selected_videos[0] = video;
            var TagInstances = catalog.GetTagsForVideos(selected_videos);
            List tag_list = new List();
            foreach (var tag in TagInstances)
              tag_list.Add( tag.Name );

            scripting.GetConsole().Write( "Tagging : " + selected_path + " ..." );
            ShellPropertyWriter propertyWriter =  file.Properties.GetPropertyWriter();
            propertyWriter.WriteProperty(SystemProperties.System.Keywords, tag_list.ToArray() );
            int Rating = 0;
            if (entry.Rating==1)
              Rating = 1;
            if (entry.Rating==2)
              Rating = 25;
            if (entry.Rating==3)
              Rating = 50;
            if (entry.Rating==4)
              Rating = 75;
            if (entry.Rating==5)
              Rating = 99;
            propertyWriter.WriteProperty(SystemProperties.System.Rating, Rating );
            propertyWriter.WriteProperty(SystemProperties.System.Comment, entry.Description );

            scripting.GetConsole().WriteLine( "Done " );
          catch (Exception ex)          
            scripting.GetConsole().WriteLine( ex.Message );