public void Initialize(IWMProfile profile, string filePath) { if (filePath == null || filePath.Length == 0) { throw new ArgumentNullException("filePath", "Invalid string parameter."); } // // assign profile to writer // _writer.SetProfile(profile); Logger.WriteLogMessage("Set profile on writer."); _writer.SetOutputFilename(filePath); Logger.WriteLogMessage("Set output filename [" + filePath + "] for writing."); _writer.GetInputCount(out _writerInputCount); Logger.WriteLogMessage("Found " + _writerInputCount + " writer inputs."); profile.GetStreamCount(out _writerStreamCount); Logger.WriteLogMessage("Found " + _writerStreamCount + " writer streams."); }
private void Config() { WMUtils.WMCreateWriter(IntPtr.Zero, out m_Writer); m_Writer.SetProfileByID(g); m_Writer.SetOutputFilename(sFileName); m_wa3 = m_Writer as IWMWriterAdvanced3; }
private void TestWrite() { Bitmap b = new Bitmap(@"c:\sga.png"); Initialize(b); m_Writer.SetOutputFilename(sFileName); m_Writer.BeginWriting(); INSSBuffer pSample = WriteOne(b); m_Writer.WriteSample(0, 1, SampleFlag.CleanPoint, pSample); m_Writer.Flush(); TestAdvanced(b); m_Writer.EndWriting(); }
private void Test() { Bitmap b = new Bitmap(@"c:\sga.png"); Initialize(b); m_Writer.SetOutputFilename(sFileName); m_Writer.BeginWriting(); INSSBuffer pSample = WriteOne(b); m_Writer.WriteSample(0, 1, SampleFlag.CleanPoint, pSample); m_Writer.Flush(); m_Writer.EndWriting(); Debug.Assert(m_OnHeader && m_IsRealTime && m_AllocateDataUnit && m_OnDataUnit && m_OnEndWriting); }
//------------------------------------------------------------------------------ // Name: CWMVCopy::CreateWriter() // Desc: Creates a writer and sets the profile and output of this writer. //------------------------------------------------------------------------------ protected void CreateWriter(string pwszOutputFile) { int dwInputCount = 0; Console.WriteLine("Creating the Writer..."); // // Create a writer // WMUtils.WMCreateWriter(IntPtr.Zero, out m_pWriter); // // Get the IWMWriterAdvanced interface of the writer // m_pWriterAdvanced = m_pWriter as IWMWriterAdvanced; // // Get the IWMHeaderInfo interface of the writer // m_pWriterHeaderInfo = m_pWriter as IWMHeaderInfo; // // Set the profile of the writer to the reader's profile // m_pWriter.SetProfile(m_pReaderProfile); m_pWriter.GetInputCount(out dwInputCount); // // Set the input property to null so the SDK knows we're going to // send compressed samples to the inputs of the writer. // for (int i = 0; i < dwInputCount; i++) { m_pWriter.SetInputProps(i, null); } // // Set the output file of the writer // m_pWriter.SetOutputFilename(pwszOutputFile); }
private void TestSink() { IWMWriterAdvanced pWriterA; pWriterA = m_Writer as IWMWriterAdvanced; pWriterA.AddSink(this); Bitmap b = new Bitmap(@"c:\sga.png"); Initialize(b); m_Writer.SetOutputFilename(sFileName); m_Writer.BeginWriting(); INSSBuffer pSample = WriteOne(b); m_Writer.WriteSample(0, 1, SampleFlag.CleanPoint, pSample); m_Writer.Flush(); m_Writer.EndWriting(); }
/// <summary> /// Create filename from specified profile using specified framerate /// </summary> /// <param name="lpszFileName">File name to create</param> /// <param name="guidProfileID">WM Profile to use for compression</param> /// <param name="iFrameRate">Frames Per Second</param> public CwmvFile(string lpszFileName, ref Guid guidProfileID, int iFrameRate) { Guid guidInputType; int dwInputCount; IWMProfileManager pWMProfileManager = null; IWMProfile pWMProfile = null; // Initialize all member variables m_iFrameRate = iFrameRate; m_dwVideoInput = -1; m_dwCurrentVideoSample = 0; m_msVideoTime = 0; m_pWMWriter = null; m_pInputProps = null; m_Init = false; try { // Open the profile manager WMUtils.WMCreateProfileManager(out pWMProfileManager); // Convert pWMProfileManager to a IWMProfileManager2 IWMProfileManager2 pProfileManager2 = (IWMProfileManager2)pWMProfileManager; // Specify the version number of the profiles to use pProfileManager2.SetSystemProfileVersion(WMVersion.V8_0); // Load the profile specified by the caller pProfileManager2.LoadProfileByID(guidProfileID, out pWMProfile); // Create a writer. This is the interface we actually write with WMUtils.WMCreateWriter(IntPtr.Zero, out m_pWMWriter); // Set the profile we got into the writer. This controls compression, video // size, # of video channels, # of audio channels, etc m_pWMWriter.SetProfile(pWMProfile); // Find out how many inputs are in the current profile m_pWMWriter.GetInputCount(out dwInputCount); // Assume we won't find any video pins m_dwVideoInput = -1; // Find the first video input on the writer for (int i = 0; i < dwInputCount; i++) { // Get the properties of channel #i m_pWMWriter.GetInputProps(i, out m_pInputProps); // Read the type of the channel m_pInputProps.GetType(out guidInputType); // If it is video, we are done if (guidInputType == MediaType.Video) { m_dwVideoInput = i; break; } } // Didn't find a video channel if (m_dwVideoInput == -1) { throw new Exception("Profile does not accept video input"); } // Specify the file name for the output m_pWMWriter.SetOutputFilename(lpszFileName); } catch { Close(); throw; } finally { // Release the locals if (pWMProfile != null) { Marshal.ReleaseComObject(pWMProfile); pWMProfile = null; } if (pWMProfileManager != null) { Marshal.ReleaseComObject(pWMProfileManager); pWMProfileManager = null; } } }
public static void CopyWmv(string inputFilePath, string outputFilePath, ulong startTime, long duration) { IWMWriterAdvanced writerAdvanced = null; IWMProfile profile = null; IWMStreamConfig streamConfig = null; uint streamCount = 0; uint inputCount = 0; ushort[] streamNumbers = null; WMT_STREAM_SELECTION[] streamSelections = null; ulong sampleTime, sampleDuration; uint flags, outputNum; ushort streamNum; INSSBuffer sample = null; IWMSyncReader reader = Helpers.CreateSyncReader(WMT_RIGHTS.WMT_RIGHT_NO_DRM); IWMWriter writer = Helpers.CreateWriter(); try { reader.Open(inputFilePath); Logger.WriteLogMessage("Opened file [" + inputFilePath + "] for reading."); profile = (IWMProfile)reader; profile.GetStreamCount(out streamCount); streamNumbers = new ushort[streamCount]; streamSelections = new WMT_STREAM_SELECTION[streamCount]; for (uint i = 0; i < streamCount; i++) { profile.GetStream(i, out streamConfig); streamConfig.GetStreamNumber(out streamNumbers[i]); streamSelections[i] = WMT_STREAM_SELECTION.WMT_ON; // // Read compressed samples // reader.SetReadStreamSamples(streamNumbers[i], true); } // // select all streams // reader.SetStreamsSelected((ushort)streamCount, streamNumbers, streamSelections); writer.SetProfile(profile); writer.GetInputCount(out inputCount); for (uint i = 0; i < inputCount; i++) { writer.SetInputProps(i, null); // write compressed samples } writer.SetOutputFilename(outputFilePath); Logger.WriteLogMessage("Set output filename [" + outputFilePath + "] for writing."); writerAdvanced = (IWMWriterAdvanced)writer; // Copy attributes avoided // Copy Codec Info avoided // Copy all scripts in the header avoided writer.BeginWriting(); // // startTime, duration are in 100-nsec ticks // reader.SetRange(startTime, duration); // seek Logger.WriteLogMessage("Set range on reader, startTime [" + startTime + "], duration [" + duration + "]."); for (uint streamsRead = 0; streamsRead < streamCount;) { try { streamNum = 0; reader.GetNextSample(0, out sample, out sampleTime, out sampleDuration, out flags, out outputNum, out streamNum); Logger.WriteLogMessage("Grabbed next video sample, sampleTime [" + sampleTime + "], duration [" + sampleDuration + "], flags [" + flags + "], outputNum [" + outputNum + "], streamNum [" + streamNum + "]."); writerAdvanced.WriteStreamSample(streamNum, sampleTime, 0, sampleDuration, flags, sample); Logger.WriteLogMessage("Wrote sample, sampleTime [" + sampleTime + "], duration [" + sampleDuration + "], flags [" + flags + "], outputNum [" + outputNum + "], streamNum [" + streamNum + "]."); } catch (COMException e) { if (e.ErrorCode == Constants.NS_E_NO_MORE_SAMPLES) { streamsRead++; } else { throw; } } } writer.EndWriting(); } finally { reader.Close(); } }