Editing metadata against video files
Asked Answered
M

1

7

I'm attempting to write a utility for inserting my own information against recorded videos, however it seems there isn't a library out there for accomplishing this.

In my latest attempt at doing this, I made use of the TagLib Sharp library, but this seems out suited for audio files:

private void ApplyTags(string p_sFilePath, Result p_Result)
{
    TagLib.File f = TagLib.File.Create(p_sFilePath);

    f.Tag.Title = p_Result.title;
    f.Tag.Year = Convert.ToUInt32(p_Result.year);

    f.Save();
}

While filling out the title and year do work for video files, items such as "Rating", "Contributing Artists", "Directors" etc. do not appear to be supported by TagLib Sharp.

So my question is, is there another library out there with a wider range of support for video files? If not, how would I go about doing this manually for MP4 or AVI?

Midgett answered 1/3, 2017 at 16:3 Comment(4)
Alternate (fact) way: #15301067 A dupe with no answers: #11183593 And this is the best solution imho: #11706549Salts
I generally use ffmpeg for anything related to video, it can do what you need too. There are wrappers for .NET for it but I generally prefer to just call it externally.Baecher
Wiki showed this: "As a derivative of the Resource Interchange File Format (RIFF), AVI files are commonly tagged with metadata in the INFO chunk. In addition, AVI files can embed Extensible Metadata Platform (XMP)." Looking for RIFF INFO libraries: exiv2.org/doc/classExiv2_1_1RiffVideo.htmlBonaventure
What do you want to do this with this MD? Do you want it to be there only for you (so your other application can read this), or you want this to appear in the file details?Strikebreaker
J
5

There are several ways to store different kinds of extended data.
All solution I describe here are taken from the links provided in the text. You can find details and some more information following the links.

Essentially there are three possibilities for you I found where to put your meta data depending on what information you want to set and what programs you might want to show them. From your question I am not sure what you are exactly looking for so I'll take a guess:

apple tag
From your question you might most likely be looking for this one to add certain values. It looks to me that this is something separate to EXIF but I might be wrong (see below for EXIF):
Example found here https://stackoverflow.com/a/21997119 writing a Producer information with "value". I copied it for convenience. Credited to @hannan-hossain. It should at least work for mp4 files:

TagLib.File videoFile = TagLib.File.Create("test.mp4");
TagLib.Mpeg4.AppleTag customTag = (TagLib.Mpeg4.AppleTag)f.GetTag(TagLib.TagTypes.Apple);
customTag.SetDashBox("Producer","Producer1", "value");
f.Save();
f.Dispose();
var tokenValue = customTag.GetDashBox("Producer", "Producer1");

shell properties of the files
This is something that is possible for all files and not just related to video files. But some information in the web points to this way of adding video related information as well.
see: https://stackoverflow.com/a/2096315 on how to read these extended properties.

EXIF data
TagLib-Sharp writes EXIF data. If you are missing values and are actually looking for them you might take a look at this code project to see how to code new values or maybe make taglib-sharp support them: https://www.codeproject.com/Articles/27242/ExifTagCollection-An-EXIF-metadata-extraction-libr

More Info
This question has a nice set of answers summarizing even more possibilities to access meta data with various libraries: Accessing audio/video metadata with .NET
But I would say that TagLib-Sharp should meet your needs.

A good summary of links is also in this answer here: https://stackoverflow.com/a/26770986

The most often mentioned ones I stumbled across were TagLib-Sharp and DirectShowNet. So your TagLib-Sharp should solve most tags you want to set. Maybe you can give more details of example video files with the information you want to set. An EXIF viewer (if it is exif) could possibly show what tag you are looking for.

Jorgenson answered 7/3, 2017 at 14:19 Comment(1)
To expand on this I'll also be using FFMPEG to write data to the files as recommended by Evk.Midgett

© 2022 - 2024 — McMap. All rights reserved.