Beispiel #1
0
        public string GetFrame(string inputFile, int timeInSeconds, FrameSize frameSize, string outputFile)
        {
            //ffmpeg -ss 01:23:45 -i input -vframes 1 -q:v 2 output.jpg

            var arguments = " -v quiet -stats " +
                            "-ss " + timeInSeconds +
                            " -i " + "\"" + inputFile + "\"" +
                            " -frames:v 1" +
                            _arguments.GetValue(frameSize.ToString()) +
                            " -q:v 2 " +
                            " -y " + "\"" + outputFile + "\"";



            return(arguments);
        }
Beispiel #2
0
        void ConfigureASFWriter(WMAsfWriter asf_filter, WTVStreamingVideoRequest strq, FrameSize SourceFrameSize)
        {
            int hr;

            // Now it's added to the graph, configure it with the selected WM Profile
            SendDebugMessage("Getting WM profile with quality of " + strq.Quality.ToString(), 0);
            WindowsMediaLib.IWMProfileManager profileManager;
            WMUtils.WMCreateProfileManager(out profileManager);
            IWMProfile wmProfile;
            string     txtPrxProfile = getPRXProfileForQuality(strq.Quality);

            if (!(string.IsNullOrEmpty(txtPrxProfile)))
            {
                SendDebugMessage("Adjusting WM profile to fit video within designated frame size", 0);
                // SET VIDEO SIZE TO FIT WITHIN THE RIGHT FRAME
                SendDebugMessage("Source video size is " + SourceFrameSize.ToString(), 0);
                FrameSize containerSize = frameSizeForStreamRequest(strq);
                SendDebugMessage("Container size is " + containerSize.ToString(), 0);
                FrameSize newVideoSize = new FrameSize(SourceFrameSize, containerSize);
                SendDebugMessage("Output size is " + newVideoSize.ToString(), 0);
                SetProfileFrameSize(ref txtPrxProfile, newVideoSize);
                SetProfileCustomSettings(ref txtPrxProfile, ref strq); // returns immediately if not custom quality
                SendDebugMessage("Configuring ASF Writer with profile", 0);
                profileManager.LoadProfileByData(txtPrxProfile, out wmProfile);
                WindowsMediaLib.IConfigAsfWriter configWriter = (WindowsMediaLib.IConfigAsfWriter)asf_filter;
                configWriter.ConfigureFilterUsingProfile(wmProfile);
                configWriter.SetIndexMode(true);  // yes index - DEFAULT

                /* Additional config  - TEST
                 * //DirectShowLib.IConfigAsfWriter2 configAsfWriter2 = (DirectShowLib.IConfigAsfWriter2)asf_filter;
                 * //configAsfWriter2.SetParam(ASFWriterConfig.AutoIndex, 0, 0);  // IT IS DEFAULT */



                // (NOT WORKING)
                // SET ANAMORPHIC VIDEO MARKERS WITHIN STREAM (ASPECT RATIO) *******************************
                UInt32 uiAspectX = (UInt32)SourceFrameSize.Width;
                byte[] bAspectX  = BitConverter.GetBytes(uiAspectX);
                UInt32 uiAspectY = (UInt32)SourceFrameSize.Height;
                byte[] bAspectY  = BitConverter.GetBytes(uiAspectY);

                DirectShowLib.IServiceProvider pServiceProvider;  // http://msdn.microsoft.com/en-us/library/dd390985%28VS.85%29.aspx
                pServiceProvider = (DirectShowLib.IServiceProvider)asf_filter;
                DsGuid dsgIWMHeaderinfo = DsGuid.FromGuid(new Guid(GUIDs.IWMWriterAdvanced2));
                object o3 = null;
                hr = pServiceProvider.QueryService(dsgIWMHeaderinfo, dsgIWMHeaderinfo, out o3);  // FAILS IN A STA THREAD
                DsError.ThrowExceptionForHR(hr);
                IWMHeaderInfo headerinfo = (IWMHeaderInfo)o3;

                // Get access to WMwriterAdvanced2 object using pServiceProvider  (poss not futureproof)  (see http://groups.google.com/group/microsoft.public.win32.programmer.directx.video/browse_thread/thread/36b154d41cb76ffd/c571d6ef56de11af?#c571d6ef56de11af )
                DsGuid dsgWMwriterAdvanced2 = DsGuid.FromGuid(new Guid(GUIDs.IWMWriterAdvanced2));
                object o = null;
                hr = pServiceProvider.QueryService(dsgWMwriterAdvanced2, dsgWMwriterAdvanced2, out o);  // FAILS IN A STA THREAD
                DsError.ThrowExceptionForHR(hr);
                IWMWriterAdvanced2 WMWriterAdvanced2 = null;
                WMWriterAdvanced2 = (IWMWriterAdvanced2)o;

                // Get Access to IWMHeaderInfo3 through WMWriterAdvanced2
                object o2 = null;
                //pServiceProvider = (DirectShowLib.IServiceProvider)WMWriterAdvanced2;
                DsGuid dsgIWMHeaderInfo3 = DsGuid.FromGuid(new Guid(GUIDs.IWMHeaderInfo3));
                hr = pServiceProvider.QueryService(dsgWMwriterAdvanced2, dsgIWMHeaderInfo3, out o2); // LET'S SEE
                DsError.ThrowExceptionForHR(hr);
                IWMHeaderInfo3 WMHeaderInfo3 = null;
                WMHeaderInfo3 = (IWMHeaderInfo3)o2;
                short pwIndex;

                // Add Aspect Ratio information
                WMHeaderInfo3.AddAttribute(2, "AspectRatioX", out pwIndex, AttrDataType.DWORD, 0, bAspectX, bAspectX.Length);
                WMHeaderInfo3.AddAttribute(2, "AspectRatioY", out pwIndex, AttrDataType.DWORD, 0, bAspectY, bAspectY.Length);

                // Try with other interface too
                headerinfo.SetAttribute(2, "AspectRatioX", AttrDataType.DWORD, bAspectX, Convert.ToInt16(bAspectX.Length));
                headerinfo.SetAttribute(2, "AspectRatioY", AttrDataType.DWORD, bAspectY, Convert.ToInt16(bAspectY.Length));



                // ************ DEINTERLACE (experimental)
                if (strq.DeInterlaceMode > 0)
                {
                    DeInterlaceModes dimode = DeInterlaceModes.WM_DM_NOTINTERLACED;
                    // Deinterlace Mode
                    if (strq.DeInterlaceMode == 1)
                    {
                        dimode = DeInterlaceModes.WM_DM_DEINTERLACE_NORMAL;
                    }
                    else if (strq.DeInterlaceMode == 2)
                    {
                        dimode = DeInterlaceModes.WM_DM_DEINTERLACE_HALFSIZE;
                    }

                    // Index of video pin
                    int pinIndex = FilterGraphTools.FindPinIndexByMediaType(currentOutputFilter, PinDirection.Input, MediaType.Video, MediaSubType.Null);



                    byte[] bDiMode = BitConverter.GetBytes((int)dimode);
                    short  szOf    = (short)bDiMode.Length;

                    // Set to use deinterlace mode
                    try
                    {
                        WMWriterAdvanced2.SetInputSetting(pinIndex, g_wszDeinterlaceMode, AttrDataType.DWORD, bDiMode, szOf);
                    }
                    catch (Exception ex)
                    {
                        SendDebugMessageWithException("Could not set interlace mode:", ex);
                    }
                }
            }
            else
            {
                SendDebugMessage("Warning - PRX Profile string was empty; using default WM config.");
            }
        }
        void ConfigureASFWriter(WMAsfWriter asf_filter, WTVStreamingVideoRequest strq, FrameSize SourceFrameSize)
        {
            int hr;

            // Now it's added to the graph, configure it with the selected WM Profile
            SendDebugMessage("Getting WM profile with quality of " + strq.Quality.ToString(), 0);
            WindowsMediaLib.IWMProfileManager profileManager;
            WMUtils.WMCreateProfileManager(out profileManager);
            IWMProfile wmProfile;
            string txtPrxProfile = getPRXProfileForQuality(strq.Quality);
            if (!(string.IsNullOrEmpty(txtPrxProfile)))
            {
                SendDebugMessage("Adjusting WM profile to fit video within designated frame size", 0);
                // SET VIDEO SIZE TO FIT WITHIN THE RIGHT FRAME
                SendDebugMessage("Source video size is " + SourceFrameSize.ToString(), 0);
                FrameSize containerSize = frameSizeForStreamRequest(strq);
                SendDebugMessage("Container size is " + containerSize.ToString() , 0);
                FrameSize newVideoSize = new FrameSize(SourceFrameSize, containerSize);
                SendDebugMessage("Output size is " + newVideoSize.ToString(), 0);
                SetProfileFrameSize(ref txtPrxProfile, newVideoSize);
                SetProfileCustomSettings(ref txtPrxProfile, ref strq); // returns immediately if not custom quality
                SendDebugMessage("Configuring ASF Writer with profile", 0);
                profileManager.LoadProfileByData(txtPrxProfile, out wmProfile);
                WindowsMediaLib.IConfigAsfWriter configWriter = (WindowsMediaLib.IConfigAsfWriter)asf_filter;
                configWriter.ConfigureFilterUsingProfile(wmProfile);
                configWriter.SetIndexMode(true);  // yes index - DEFAULT
                /* Additional config  - TEST
                //DirectShowLib.IConfigAsfWriter2 configAsfWriter2 = (DirectShowLib.IConfigAsfWriter2)asf_filter;
                //configAsfWriter2.SetParam(ASFWriterConfig.AutoIndex, 0, 0);  // IT IS DEFAULT */

                // (NOT WORKING)
                // SET ANAMORPHIC VIDEO MARKERS WITHIN STREAM (ASPECT RATIO) *******************************
                UInt32 uiAspectX = (UInt32)SourceFrameSize.Width;
                byte[] bAspectX = BitConverter.GetBytes(uiAspectX);
                UInt32 uiAspectY = (UInt32)SourceFrameSize.Height;
                byte[] bAspectY = BitConverter.GetBytes(uiAspectY);

                DirectShowLib.IServiceProvider pServiceProvider;  // http://msdn.microsoft.com/en-us/library/dd390985%28VS.85%29.aspx
                pServiceProvider = (DirectShowLib.IServiceProvider)asf_filter;
                DsGuid dsgIWMHeaderinfo = DsGuid.FromGuid(new Guid(GUIDs.IWMWriterAdvanced2));
                object o3 = null;
                hr = pServiceProvider.QueryService(dsgIWMHeaderinfo, dsgIWMHeaderinfo, out o3);  // FAILS IN A STA THREAD
                DsError.ThrowExceptionForHR(hr);
                IWMHeaderInfo headerinfo = (IWMHeaderInfo)o3;

                // Get access to WMwriterAdvanced2 object using pServiceProvider  (poss not futureproof)  (see http://groups.google.com/group/microsoft.public.win32.programmer.directx.video/browse_thread/thread/36b154d41cb76ffd/c571d6ef56de11af?#c571d6ef56de11af )
                DsGuid dsgWMwriterAdvanced2 = DsGuid.FromGuid(new Guid(GUIDs.IWMWriterAdvanced2));
                object o = null;
                hr = pServiceProvider.QueryService(dsgWMwriterAdvanced2, dsgWMwriterAdvanced2, out o);  // FAILS IN A STA THREAD
                DsError.ThrowExceptionForHR(hr);
                IWMWriterAdvanced2 WMWriterAdvanced2 = null;
                WMWriterAdvanced2 = (IWMWriterAdvanced2)o;

                // Get Access to IWMHeaderInfo3 through WMWriterAdvanced2
                object o2 = null;
                //pServiceProvider = (DirectShowLib.IServiceProvider)WMWriterAdvanced2;
                DsGuid dsgIWMHeaderInfo3 = DsGuid.FromGuid(new Guid(GUIDs.IWMHeaderInfo3));
                hr = pServiceProvider.QueryService(dsgWMwriterAdvanced2, dsgIWMHeaderInfo3, out o2); // LET'S SEE
                DsError.ThrowExceptionForHR(hr);
                IWMHeaderInfo3 WMHeaderInfo3 = null;
                WMHeaderInfo3 = (IWMHeaderInfo3)o2;
                short pwIndex;

                // Add Aspect Ratio information
                WMHeaderInfo3.AddAttribute(2, "AspectRatioX", out pwIndex, AttrDataType.DWORD, 0, bAspectX, bAspectX.Length);
                WMHeaderInfo3.AddAttribute(2, "AspectRatioY", out pwIndex, AttrDataType.DWORD, 0, bAspectY, bAspectY.Length);

                // Try with other interface too
                headerinfo.SetAttribute(2, "AspectRatioX", AttrDataType.DWORD, bAspectX, Convert.ToInt16(bAspectX.Length));
                headerinfo.SetAttribute(2, "AspectRatioY", AttrDataType.DWORD, bAspectY, Convert.ToInt16(bAspectY.Length));

                // ************ DEINTERLACE (experimental)
                if (strq.DeInterlaceMode > 0)
                {
                    DeInterlaceModes dimode = DeInterlaceModes.WM_DM_NOTINTERLACED;
                    // Deinterlace Mode
                    if (strq.DeInterlaceMode == 1)
                        dimode = DeInterlaceModes.WM_DM_DEINTERLACE_NORMAL;
                    else if (strq.DeInterlaceMode == 2)
                        dimode = DeInterlaceModes.WM_DM_DEINTERLACE_HALFSIZE;

                    // Index of video pin
                    int pinIndex = FilterGraphTools.FindPinIndexByMediaType(currentOutputFilter, PinDirection.Input, MediaType.Video, MediaSubType.Null);

                    byte[] bDiMode = BitConverter.GetBytes((int)dimode);
                    short szOf = (short)bDiMode.Length;

                    // Set to use deinterlace mode
                    try
                    {
                        WMWriterAdvanced2.SetInputSetting(pinIndex, g_wszDeinterlaceMode, AttrDataType.DWORD, bDiMode, szOf);
                    }
                    catch (Exception ex)
                    {
                        SendDebugMessageWithException("Could not set interlace mode:", ex);
                    }

                }

            }
            else
            {
                SendDebugMessage("Warning - PRX Profile string was empty; using default WM config.");
            }
        }