问题描述
首先,我有最新版本的 TagLibSharp,2.2.0.0。读取和更新 mkv 文件中的标签(例如标题和评论)工作正常。还有其他标签需要更新。这些是视频曲目和音轨标题。
在 Visual Studio 2015 中调试时,将鼠标悬停在创建的变量上,文件:
TagLib.File file = TagLib.File.Create(_path);
可以看到所有的标签。即使是 SimpleTag。但 SimpleTag 是一个集合。查看此集合,我要更新的标签就在那里,并且它们的值符合预期。
我已经尝试解决这个问题好几天了,但没有成功。下面是一些包含失败尝试的代码。
TagLib.File file = TagLib.File.Create(_path);
TagLib.Matroska.SimpleTag smpl = new TagLib.Matroska.SimpleTag();
TagLib.Matroska.File f = (TagLib.Matroska.File)TagLib.File.Create(_path);
var tst = file.GetTag(TagLib.TagTypes.Matroska);
//Possible solution from this link???
//https://github.com/mono/taglib-sharp/blob/4340975d298ddb3748d508fbff866f07c1cb997d/src/TaglibSharp.Tests/FileFormats/MkvFormatTest.cs#L218
var mtag = (TagLib.Matroska.Tag)file.GetTag(TagLib.TagTypes.Matroska);
var mtags = mtag.Tags;
var collectag = new TagLib.Matroska.Tag(mtags,TagLib.Matroska.targettype.COLLECTION);
var tracks = mtag.Tags.Tracks;
//need to remove track_name and subtitles
//but this won't do it. So close...
for (int i = 0; i < tracks.Count; i++)
{
// Remove Audio tags
var audiotag = mtag.Tags.Get(tracks[i]);
if (audiotag != null)
{
audiotag.Comment = "";
audiotag.Tags.Clear();
tracks[i].Description.ToString();
//Assert.NotNull(audiotag); //NUnit.Framework;
audiotag.SimpleTags.Clear();
audiotag.Clear();
}
}
//no,this just creates
//TagLib.Matroska.MatroskaID id = new TagLib.Matroska.MatroskaID();
//TagLib.Matroska.EBMLelement el = new TagLib.Matroska.EBMLelement(id);
//no,these just read
//TagLib.Matroska.EBMLreader r = new TagLib.Matroska.EBMLreader(f,0);
//TagLib.Matroska.VideoTrack vTrack = new TagLib.Matroska.VideoTrack(f,r);
//TagLib.Matroska.AudioTrack aTrack = new TagLib.Matroska.AudioTrack(f,r);
//TagLib.Matroska.SubtitleTrack subTrack = new TagLib.Matroska.SubtitleTrack(f,r);
//foreach (TagLib.Matroska.SimpleTag s in ??????????)
//{
//}
//smpl = (TagLib.Matroska.Tag)f.GetTag(TagLib.TagTypes.Matroska); //does not work
//smpl = (TagLib.Matroska.SimpleTag)file.GetTag(TagLib.TagTypes.Matroska); // does not work.
//the lines below work with other formats but this will be an mkv file.
//TagLib.Id3v2.Tag tag = (TagLib.Id3v2.Tag)file.GetTag(TagLib.TagTypes.Id3v2);
//TagLib.Mpeg4.AppleTag customTag = (TagLib.Mpeg4.AppleTag)file.GetTag(TagLib.TagTypes.Apple);
类 TagLib.Matroska.SimpleTag 说明: TagName 属性不是 SimpleTag 的一部分。 一个 TagLib.Matroska.Tag 对象可能包含多个 TagLib.Matroska.SimpleTag。一种 TagLib.Matroska.SimpleTag 对象可能包含多个 TagLib.Matroska.SimpleTag。
我在这里不知所措,可以使用一些输入。甚至可以在 mkv 文件中更新这些标签吗?
谢谢...
编辑:找到此链接。没有太大帮助,但确实有所帮助。
编辑:我知道这是一种可能性,因为 MKVToolNix 可以删除字幕和曲目名称。唯一的问题是它一次只处理一个文件。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)