我尝试过使用 C# (.net core) 中的以下库
我无法从任何这些视频库中检索 GPS 元数据。 但对于图像来说,效果很好。另外,我尝试了 Exif 工具,但没有成功。
以下是我使用的一些代码示例。正在寻求这方面的帮助。
// using metadata extractor
var byteArray = await File.ReadAllBytesAsync("./meta_video.mp4");
Stream stream = new MemoryStream(byteArray);
var directories = QuickTimeMetadataReader.ReadMetadata(stream);
var directories1 = ImageMetadataReader.ReadMetadata("./meta_image1.jpg");
// using tag lib
var tfile = TagLib.File.Create(@"./meta_video.mp4");
// using media tool kit
var inputFile = new MediaToolkit.Model.MediaFile {Filename = @"./meta_video.mp4"};
using (var engine = new Engine())
{
engine.GetMetadata(inputFile);
}
// using media info
string fileNameAndPath = "./video2.mp4";
var myVideo = new MediaFile(fileNameAndPath);
您可以使用外部工具,例如 exiftool.exe(在此处输入链接描述) 示例 C# 代码:
ProcessStartInfo ExifProccess = new();
Process process = new();
ExifProccess.FileName = @"exiftool.exe";
ExifProccess.Arguments = $"-ee -n -api LargeFileSupport=1 -p \"$gpslatitude,$gpslongitude,$gpsaltitude\" \"" + SourecFile + "\"";
ExifProccess.UseShellExecute = false;
ExifProccess.CreateNoWindow = true;
ExifProccess.LoadUserProfile = false;
ExifProccess.RedirectStandardOutput = true;
ExifProccess.RedirectStandardError = true;
process.StartInfo = ExifProccess;
process.Start();
process.WaitForExit(2000);
string? output = process.StandardOutput.ReadLine();
string? error = process.StandardError.ReadLine();
if (output != null)
{
var _gps = output.Split(',');
float lat = float.Parse(_gps[0]);
string? latRef = lat >= 0 ? "North" : "South";
Lat = lat;
float lon = float.Parse(_gps[1]);
string? lonRef = lon >= 0 ? "East" : "West";
Lon = lon;
float alt = float.Parse(_gps[2]);
string? altRef = alt >= 0 ? "Above" : "Below";
Alt = alt;
}
if (error != null)
{
// Do something
}