Exemplo n.º 1
0
        public CaptureSourceDVR(StreamSourceInfo sourceConfig, OpenGraphRequest openGraphRequest)
            : base(sourceConfig, openGraphRequest)
        {
            AppLogger.Message("In CaptureSourceDVR constructor - CurrentProfile is " + CurrentProfile.Name);

            _captureFilter = AddFilterByName(FilterCategory.VideoInputDevice, sourceConfig.Description);

            _videoEncoder = AddFilterByName(FilterCategory.LegacyAmFilterCategory, "LEAD H264 Encoder (4.0)");

//            _transcoder = AddFilterByName(FilterCategory.LegacyAmFilterCategory, "LEAD H264 Transcoder");

            InitializeSink();

            ConnectFilters(_captureFilter, "Capture", _videoEncoder, "XForm In");

//            ConnectFilters(_videoEncoder, "XForm Out", _transcoder, "Input");

//            ConnectFilterToMux(_transcoder, "Output", "Input 01");

            ConnectFilterToMux(_videoEncoder, "XForm Out", "Input 01");

            ConnectMuxToSink();

            _videoEncoderControl = (ILMH264Encoder)_videoEncoder;
            _videoEncoderControl.EnableRateControl = true;
            _videoEncoderControl.BitRate           = CurrentProfile.Video.ConstantBitRate * 1024;
            _videoEncoderControl.OutputFormat      = eH264OUTPUTFORMAT.H264FORMAT_IPOD; // seems to work the best
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructs the remainder of the graph (after the Demuxer) according to the source config and profile.
        /// </summary>
        private void BuildForProfile()
        {
            //Configure for specific codec / transcoding
            //if UseHardwareEncoder is checked, we will simply hand off the Elementry Streams from the Air
            if (SourceConfig.TVTuner.UseHardwareEncoder)
            {
                //connect video
                ConnectFilterToNetMux(mpeg2Demux, "2", "Input 01");
                //connect audio
                ConnectFilterToNetMux(mpeg2Demux, "3", "Input 02");
            }
            else // if they want to use software encoder, we will encode using the default profile
            {
                if (CurrentProfile.Video != null)
                {
                    if (CurrentProfile.Video.CodecType != VideoCodecType.H264)
                    {
                        throw new NotSupportedException("H.264 is the only supported target codec in software transcoding mode!");
                    }

                    if (CurrentProfile.Video.ImageSize != VideoImageSize.Undefined)
                    {
                        throw new NotSupportedException("Resizing is not supported!");
                    }

                    videoEncoder = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "LEAD H264 Encoder (4.0)");
                    if (videoEncoder == null)
                    {
                        throw new Exception("Could not instantiate H264 Encoder!");
                    }
                    h264Encoder = (ILMH264Encoder)videoEncoder;
                    if (h264Encoder == null)
                    {
                        throw new Exception("Could not query for ILMH264Encoder interface!");
                    }

                    FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "Elecard MPEG-2 Video Decoder");

                    FilterGraphTools.ConnectFilters(_graphBuilder, mpeg2Demux, "2", videoEncoder, "XForm In", true);

                    h264Encoder.EncodingThreads = eH264ENCODINGTHREADS.H264THREAD_AUTO;
                    h264Encoder.FrameRate       = -1;
                    h264Encoder.EncodingSpeed   = eH264ENCODINGSPEED.H264SPEED_1;
                    //h264Encoder.EncodingSpeed = eH264ENCODINGSPEED.H264SPEED_2;

                    h264Encoder.EnableRateControl = true;
                    h264Encoder.BitRate           = CurrentProfile.Video.ConstantBitRate * 1024;

                    h264Encoder.EnableSuperCompression = false;
                    h264Encoder.SymbolMode             = eH264SYMBOLMODE.H264SYMBOL_CAVLC;
                    h264Encoder.OutputFormat           = eH264OUTPUTFORMAT.H264FORMAT_STANDARD_H264;

                    h264Encoder.IFrameInterval = CurrentProfile.Video.KeyFrameRate;
                    h264Encoder.PFrameInterval = 0;

                    //connect video
                    ConnectFilterToNetMux(videoEncoder, "XForm Out", "Input 01");
                }
                if (CurrentProfile.Audio != null)
                {
                    if (CurrentProfile.Audio.CodecType != AudioCodecType.DolbyDigital)
                    {
                        throw new NotSupportedException("Audio transcoding is not implemented!");
                    }
                    //connect audio
                    ConnectFilterToNetMux(mpeg2Demux, "3", (CurrentProfile.Video != null) ? "Input 02" : "Input 01");
                }
            }
        }