public AsfImageTest() { AsfFile asfFile = new AsfFile(testVideoFileName); AsfFileProperties fileProperties = asfFile.GetAsfObject <AsfFileProperties>(); TimeSpan duration = TimeSpan.FromTicks((long)fileProperties.PlayDuration) - TimeSpan.FromMilliseconds(fileProperties.Preroll); testVideoFileDuration = duration.TotalSeconds; }
public AsfFilePropertiesItem(Stream stream) : base("File Properties Object", AsfGuid.ASF_File_Properties_Object, stream) { AsfFileProperties asfFileProperties = new AsfFileProperties(stream, Configuration); IsSelected = true; Properties.Add("MMS ID", asfFileProperties.FileId.ToString().ToUpper()); Properties.Add("Total Size", asfFileProperties.FileSize); Properties.Add("Creation Time", asfFileProperties.CreationTime); Properties.Add("Packets", asfFileProperties.PacketCount); Properties.Add("Duration", TimeSpan.FromTicks((long)asfFileProperties.PlayDuration).ToString("mm':'ss\\.fff")); Properties.Add("Send Duration", TimeSpan.FromTicks((long)asfFileProperties.SendDuration).ToString("mm':'ss\\.fff")); Properties.Add("Preroll", TimeSpan.FromMilliseconds(asfFileProperties.Preroll).ToString("mm':'ss\\.fff")); Properties.Add("Flags", string.Format("{0:x}", asfFileProperties.Flags)); Properties.Add("Broadcast", asfFileProperties.IsBroadcast); Properties.Add("Seekable", asfFileProperties.IsSeekable); Properties.Add("Max Packet Size", asfFileProperties.MaxPacketSize); Properties.Add("Min Packet Size", asfFileProperties.MinPacketSize); Properties.Add("Maximum Bitrate", asfFileProperties.MaxBitRate); }
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(); } }