默认直接声音不播放任何声音,但视频在捕捉时正在播放

时间:2015-07-21 08:54:21

标签: c# directshow

我使用codeproject示例捕获直播电视,一切正常,但声音无法播放!

This是codeproject url,这是我的代码:

private void BuildVideoAndAudioPins()
    {
        //  Setup video pin media type
        var videoPinType = new AMMediaType
        {
            majorType = MediaType.Video,
            subType = MediaSubType.H264,
            formatType = FormatType.VideoInfo2
        };
        IPin videoPin;
        var hr = ((IMpeg2Demultiplexer)mpeg2Demux).CreateOutputPin(videoPinType, "Video", out videoPin);
        DsError.ThrowExceptionForHR(hr);

        // Setup audio pin media type
        var audioPinType = new AMMediaType
        {
            majorType = MediaType.Audio,
            subType = MediaSubType.Mpeg2Audio,
            sampleSize = 65536,
            temporalCompression = false,
            fixedSizeSamples = true, // or false in MediaPortal //true
            unkPtr = IntPtr.Zero,
            formatType = FormatType.WaveEx
        };

        // We need to set up FormatPtr for proper connection to decoder filter
        var mpeg1WaveFormat = new MPEG1WaveFormat
        {
            wfx = new DirectShowLib.WaveFormatEx
            {

                wFormatTag = 0x0050,
                nChannels = 2,
                nSamplesPerSec = 48000,
                nAvgBytesPerSec = 32000,
                nBlockAlign = 768,
                wBitsPerSample = 0,
                cbSize = 22 // extra size

            },
            fwHeadLayer = AcmMpegHeadLayer.Layer2,
            //dwHeadBitrate = 0x00177000,
            fwHeadMode = AcmMpegHeadMode.SingleChannel,
            fwHeadModeExt = 1,
            wHeadEmphasis = 1,
            fwHeadFlags = AcmMpegHeadFlags.OriginalHome | AcmMpegHeadFlags.IDMpeg1,
            dwPTSLow = 0,
            dwPTSHigh = 0
        };
        audioPinType.formatSize = Marshal.SizeOf(mpeg1WaveFormat);
        audioPinType.formatPtr = Marshal.AllocHGlobal(audioPinType.formatSize);
        Marshal.StructureToPtr(mpeg1WaveFormat, audioPinType.formatPtr, false);

        IPin audioPin;
        hr = ((IMpeg2Demultiplexer)mpeg2Demux).CreateOutputPin(audioPinType, "Audio", out audioPin);
        DsError.ThrowExceptionForHR(hr);
    }

private void AddAudioFilters()
    {
        // Microsoft buitin audio decoder
        audioDecoder = FilterGraphTools.AddFilterByName(graphBuilder, FilterCategory.LegacyAmFilterCategory, "Microsoft DTV-DVD Audio Decoder");
        if (audioDecoder == null)
            throw new Exception("Failed to create audio decoder");
        FilterGraphTools.ConnectFilters(graphBuilder, DsFindPin.ByName(mpeg2Demux, "Audio"), DsFindPin.ByDirection(audioDecoder, PinDirection.Input, 0), true);

        // Standard DirectSound output
        audioRenderer = FilterGraphTools.AddFilterByName(graphBuilder, FilterCategory.AudioRendererCategory, "Default DirectSound Device");
        FilterGraphTools.ConnectFilters(graphBuilder, DsFindPin.ByDirection(audioDecoder, PinDirection.Output, 0), DsFindPin.ByDirection(audioRenderer, PinDirection.Input, 0), false);


    }

我认为问题出在音频标题以及代码项目描述中!

0 个答案:

没有答案