コード例 #1
0
        private void Config()
        {
            WMUtils.WMCreateWriter(IntPtr.Zero, out writer);
            writer.SetProfileByID(g);

            WMUtils.WMCreateWriterNetworkSink(out sink);
            m_clientConns = (IWMClientConnections2)sink;

            IWMWriterAdvanced advWriter = (IWMWriterAdvanced)writer;

            advWriter.AddSink(sink);
            sink.Open(ref port);

            int urlLen = 0;

            sink.GetHostURL(null, ref urlLen);
            sbUrl = new StringBuilder(urlLen);
            sink.GetHostURL(sbUrl, ref urlLen);

            writer.BeginWriting();

            WMUtils.WMCreateReader(IntPtr.Zero, Rights.Playback, out reader);
            reader.Open(sbUrl.ToString(), this, new IntPtr(123));

            lock (m_openLock)
            {
                Monitor.Wait(m_openLock);
            }

            reader.Start(0, 0, 1.0f, new IntPtr(321));

            lock (m_openLock)
            {
                Monitor.Wait(m_openLock);
            }
        }
コード例 #2
0
ファイル: Helpers.cs プロジェクト: tmpkus/openvss
        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();
            }
        }
コード例 #3
0
ファイル: WmaWriter.cs プロジェクト: lipilipii/trackvideo
        /// <summary>
        /// Create the writer indicating Metadata information
        /// </summary>
        /// <param name="output"><see cref="System.IO.Stream"/> Where resulting WMA string will be written</param>
        /// <param name="format">PCM format of input data received in <see cref="WmaWriter.Write"/> method</param>
        /// <param name="profile">IWMProfile that describe the resulting compressed stream</param>
        /// <param name="MetadataAttributes">Array of <see cref="Yeti.WMFSdk.WM_Attr"/> structures describing the metadata information that will be in the result stream</param>
        public WmaWriter(Stream output, WaveFormat format, IWMProfile profile, WM_Attr[] MetadataAttributes)
            : base(output, format)
        {
            m_Writer = WM.CreateWriter();
            IWMWriterAdvanced wa = (IWMWriterAdvanced)m_Writer;

            wa.AddSink((IWMWriterSink)this);
            m_Writer.SetProfile(profile);
            uint inputs;

            m_Writer.GetInputCount(out inputs);
            if (inputs == 1)
            {
                IWMInputMediaProps InpProps;
                Guid type;
                m_Writer.GetInputProps(0, out InpProps);
                InpProps.GetType(out type);
                if (type == MediaTypes.WMMEDIATYPE_Audio)
                {
                    WM_MEDIA_TYPE mt;
                    mt.majortype            = MediaTypes.WMMEDIATYPE_Audio;
                    mt.subtype              = MediaTypes.WMMEDIASUBTYPE_PCM;
                    mt.bFixedSizeSamples    = true;
                    mt.bTemporalCompression = false;
                    mt.lSampleSize          = (uint)m_InputDataFormat.nBlockAlign;
                    mt.formattype           = MediaTypes.WMFORMAT_WaveFormatEx;
                    mt.pUnk     = IntPtr.Zero;
                    mt.cbFormat = (uint)Marshal.SizeOf(m_InputDataFormat);

                    GCHandle h = GCHandle.Alloc(m_InputDataFormat, GCHandleType.Pinned);
                    try
                    {
                        mt.pbFormat = h.AddrOfPinnedObject();
                        InpProps.SetMediaType(ref mt);
                    }
                    finally
                    {
                        h.Free();
                    }
                    m_Writer.SetInputProps(0, InpProps);
                    if (MetadataAttributes != null)
                    {
                        WMHeaderInfo info = new WMHeaderInfo((IWMHeaderInfo)m_Writer);
                        foreach (WM_Attr attr in MetadataAttributes)
                        {
                            info.SetAttribute(attr);
                        }
                        info = null;
                    }
                    m_Writer.BeginWriting();
                    m_Profile = profile;
                }
                else
                {
                    throw new ArgumentException("Invalid profile", "profile");
                }
            }
            else
            {
                throw new ArgumentException("Invalid profile", "profile");
            }
        }
コード例 #4
0
ファイル: WMVCopy.cs プロジェクト: gchudov/WindowsMediaLib
        //------------------------------------------------------------------------------
        // Name: CWMVCopy::Copy()
        // Desc: Copies the input file to the output file. The script stream is moved
        //       to the header if fMoveScriptStream is true.
        //------------------------------------------------------------------------------
        public void Copy(
            string pwszInputFile,
            string pwszOutputFile,
            long qwMaxDuration,
            bool fMoveScriptStream)
        {
            //
            // Initialize the pointers
            //
            m_hEvent            = null;
            m_pReader           = null;
            m_pReaderAdvanced   = null;
            m_pReaderHeaderInfo = null;
            m_pReaderProfile    = null;
            m_pWriter           = null;
            m_pWriterAdvanced   = null;
            m_pWriterHeaderInfo = null;

            m_dwStreamCount   = 0;
            m_pguidStreamType = null;
            m_pwStreamNumber  = null;

            if (null == pwszInputFile || null == pwszOutputFile)
            {
                throw new COMException("Missing input or output file", E_InvalidArgument);
            }

            m_fMoveScriptStream = fMoveScriptStream;
            m_qwMaxDuration     = qwMaxDuration;

            //
            // Event for the asynchronous calls
            //
            m_hEvent = new AutoResetEvent(false);

            //
            // Create the Reader
            //
            CreateReader(pwszInputFile);

            //
            // Get profile information
            //
            GetProfileInfo();

            //
            // Create the Writer
            //
            CreateWriter(pwszOutputFile);

            //
            // Copy all attributes
            //
            CopyAttribute();

            //
            // Copy codec info
            //
            CopyCodecInfo();

            //
            // Copy all scripts in the header
            //
            CopyScriptInHeader();

            //
            // Process samples: read from the reader, and write to the writer
            //

            try
            {
                Process();
            }
            catch (Exception e)
            {
                int hr = Marshal.GetHRForException(e);
                //
                // Output some common error messages.
                //
                if (NSResults.E_VIDEO_CODEC_NOT_INSTALLED == hr)
                {
                    Console.WriteLine("Processing samples failed: Video codec not installed");
                }
                if (NSResults.E_AUDIO_CODEC_NOT_INSTALLED == hr)
                {
                    Console.WriteLine("Processing samples failed: Audio codec not installed");
                }
                else if (NSResults.E_INVALID_OUTPUT_FORMAT == hr)
                {
                    Console.WriteLine("Processing samples failed: Invalid output format ");
                }
                else if (NSResults.E_VIDEO_CODEC_ERROR == hr)
                {
                    Console.WriteLine("Processing samples failed: An unexpected error occurred with the video codec ");
                }
                else if (NSResults.E_AUDIO_CODEC_ERROR == hr)
                {
                    Console.WriteLine("Processing samples failed: An unexpected error occurred with the audio codec ");
                }
                else
                {
                    Console.WriteLine(string.Format("Processing samples failed: Error (hr=0x{0:x})", hr));
                }
                throw;
            }

            //
            // Copy all scripts in m_ScriptList
            //
            CopyScriptInList(pwszOutputFile);

            //
            // Copy marker information
            //
            CopyMarker(pwszOutputFile);

            Console.WriteLine("Copy finished.");

            //
            // Note: The output file is indexed automatically.
            // You can use IWMWriterFileSink3::SetAutoIndexing(false) to disable
            // auto indexing.
            //

            Dispose();
        }