public void UpdateContentDescriptionPropertiesFluent() { string testBackupFileName = "testContentDescriptionUpdate.wmv"; AsfFile.From(testVideoFileName) .WithFileCreationTime(DateTime.Parse("2/27/2011")) .WithAuthor("Fred Fish") .WithDescription("Some lengthy description of the content") .WithCopyright("Copyright (c) 2011") .WithTitle("Some title") .WithRating("5.0") .Update(testBackupFileName); AsfFile asfFile = new AsfFile(testBackupFileName); var asfFileProperties = asfFile.GetAsfObject <AsfFileProperties>(); Assert.AreEqual(asfFileProperties.CreationTime, DateTime.Parse("2/27/2011")); AsfContentDescriptionObject contentDescription = asfFile.GetAsfObject <AsfContentDescriptionObject>(); Assert.AreEqual(contentDescription.ContentProperties["Author"], "Fred Fish"); Assert.AreEqual(contentDescription.ContentProperties["Copyright"], "Copyright (c) 2011"); Assert.AreEqual(contentDescription.ContentProperties["Title"], "Some title"); Assert.AreEqual(contentDescription.ContentProperties["Description"], "Some lengthy description of the content"); Assert.AreEqual(contentDescription.ContentProperties["Rating"], "5.0"); File.Delete(testBackupFileName); }
public void UpdateContentDescriptionProperties() { string testBackupFileName = "testContentDescriptionUpdate.wmv"; AsfFile asfFile = new AsfFile(testVideoFileName); AsfContentDescriptionObject contentDescription = asfFile.GetAsfObject <AsfContentDescriptionObject>(); contentDescription.ContentProperties["Author"] = "Fred Fish"; contentDescription.ContentProperties["Copyright"] = "Copyright (c) 2011"; contentDescription.ContentProperties["Title"] = "Some title"; contentDescription.ContentProperties["Description"] = "Some lengthy description of the content"; contentDescription.ContentProperties["Rating"] = "5.0"; asfFile.Update(testBackupFileName); asfFile = new AsfFile(testBackupFileName); contentDescription = asfFile.GetAsfObject <AsfContentDescriptionObject>(); Assert.AreEqual(contentDescription.ContentProperties["Author"], "Fred Fish"); Assert.AreEqual(contentDescription.ContentProperties["Copyright"], "Copyright (c) 2011"); Assert.AreEqual(contentDescription.ContentProperties["Title"], "Some title"); Assert.AreEqual(contentDescription.ContentProperties["Description"], "Some lengthy description of the content"); Assert.AreEqual(contentDescription.ContentProperties["Rating"], "5.0"); File.Delete(testBackupFileName); }
public AsfContentDescriptionObjectItem(Stream stream) : base("Content Description Object", AsfGuid.ASF_Content_Description_Object, stream) { ContentDescription = new AsfContentDescriptionObject(stream); EditProperties = new ObservableCollection <EditableContentProperty>(); List <string> editableItems = new List <string> { "Author", "Description", "Copyright", "Title", "Rating" }; foreach (var item in ContentDescription.ContentProperties) { if (!editableItems.Contains(item.Key)) { Properties.Add(item.Key, item.Value); } else { EditProperties.Add(new EditableContentProperty(item.Key, item.Value)); } } }
public static void ExecuteCommands(string fileName, Dictionary <string, object> switches) { try { if (switches.ContainsKey("PrintDuration")) // print file duration { AsfFile asfFile = new AsfFile(fileName); AsfFileProperties fileProperties = asfFile.GetAsfObject <AsfFileProperties>(); Console.WriteLine(string.Format("File {0} has a duration of {1}", fileName, fileProperties.Duration.ToString("mm':'ss\\.fff"))); } else if (switches.ContainsKey("ExtractImage")) //extract an image thumb from a time offset { //create thumb double startOffset = (double)switches["StartOffset"]; string outputFile = (string)switches["OutputFile"]; Bitmap bitmap = AsfImage.FromFile(fileName, startOffset); if (switches.ContainsKey("Width")) { int width = (int)switches["Width"]; int height = (int)(bitmap.Height * ((double)width / bitmap.Width)); Bitmap thumbBitmap = new Bitmap(width, height); using (Graphics g = Graphics.FromImage(thumbBitmap)) { g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.DrawImage(bitmap, 0, 0, width, height); } bitmap = thumbBitmap; } ImageFormat outputFormat = ImageFormat.Bmp; if (outputFile.ToLower().Contains(".jpg")) { outputFormat = ImageFormat.Jpeg; } else if (outputFile.ToLower().Contains(".png")) { outputFormat = ImageFormat.Png; } bitmap.Save(outputFile, outputFormat); } else if (switches.ContainsKey("ExtractAudio")) //extract audio data from a time range { double startOffset = (double)switches["StartOffset"]; double endOffset = (double)switches["EndOffset"]; string outputFile = (string)switches["OutputFile"]; WaveMemoryStream waveStream = WaveMemoryStream.FromFile(fileName, startOffset, endOffset); using (FileStream fs = new FileStream(outputFile, FileMode.Create)) waveStream.WriteTo(fs); } else if (switches.ContainsKey("UpdateProperties")) //update content description properties { AsfFile asfFile = new AsfFile(fileName); AsfContentDescriptionObject contentDescription = asfFile.GetAsfObject <AsfContentDescriptionObject>(); if (contentDescription != null) { string author = switches.ContainsKey("Author") ? (string)switches["Author"] : contentDescription.ContentProperties["Author"]; string copyright = switches.ContainsKey("Copyright") ? (string)switches["Copyright"] : contentDescription.ContentProperties["Copyright"]; string title = switches.ContainsKey("Title") ? (string)switches["Title"] : contentDescription.ContentProperties["Title"]; string description = switches.ContainsKey("Description") ? (string)switches["Description"] : contentDescription.ContentProperties["Description"]; AsfFile.From(fileName) .WithAuthor(author) .WithDescription(description) .WithCopyright(copyright) .WithTitle(title) .Update(); Console.WriteLine(string.Format("Content description properties updated.")); } else { Console.WriteLine(string.Format("No content description properties available.")); } } } catch (Exception) { PrintUsage(); } }