//====== IRequestHandler public async Task <FileMetadataContainer> Handle(GetMetadataFromFileContentQuery request, CancellationToken cancellationToken) { FileEntity?entity = await context.Entities.Files.FindAsync(request.FileId.Value); if (entity is null) { throw new Exception("File not found: " + request.FileId); // TODO: custom ex } IFileInfo fileInfo = fileReader.SourceFilesReader.Get(new FileName(entity.SourceFileName)); if (fileInfo.Exists == false) { throw new Exception("File not found: " + request.FileId); // TODO: custom ex } using var stream = fileInfo.CreateReadStream(); FileMetadataContainer container = metadataReader.GetMetadata(stream); return(container); }
public static MediaFile GetMediaFile(string filePath) { int duration, fps = 0, height = 0, width = 0; bool hasVideo, hasAudio; string audioCodec = "", videoCodec = ""; MultimediaFactory factory; IMetadataReader reader = null; try{ factory = new MultimediaFactory(); reader = factory.getMetadataReader(); reader.Open(filePath); duration = (int)reader.GetMetadata(MetadataType.Duration); hasVideo = (bool)reader.GetMetadata(MetadataType.HasVideo); hasAudio = (bool)reader.GetMetadata(MetadataType.HasAudio); if (hasAudio) { audioCodec = (string)reader.GetMetadata(MetadataType.AudioEncoderType); } if (hasVideo) { videoCodec = (string)reader.GetMetadata(MetadataType.VideoEncoderType); fps = (int)reader.GetMetadata(MetadataType.Fps); } height = (int)reader.GetMetadata(MetadataType.DimensionX); width = (int)reader.GetMetadata(MetadataType.DimensionY); return(new MediaFile(filePath, duration * 1000, (ushort)fps, hasAudio, hasVideo, videoCodec, audioCodec, (uint)height, (uint)width)); } catch (GLib.GException ex) { throw new Exception(Catalog.GetString("Invalid video file:") + "\n" + ex.Message); } finally { reader.Close(); reader.Dispose(); } }