none
silverliht 视频声音解码 RRS feed

  • 问题

  • silverlight 用流播放FLV格式的视频,为什么有些的有声音而有些却没有声音呢?

    附上音频解码关键代码

    WaveFormatExtensible wfx = new WaveFormatExtensible();
                wfx.FormatTag = 0x00FF; // AAC=0x00FF; MP3=0x0055; ADPCM=0x5346; PCM=0x0001
                wfx.Channels = 2;
                wfx.BlockAlign = 4;
                wfx.BitsPerSample =16;
                wfx.SamplesPerSec = 44100;
                wfx.AverageBytesPerSecond = wfx.SamplesPerSec * wfx.Channels * wfx.BitsPerSample / wfx.BlockAlign;
                //wfx.AverageBytesPerSecond = 352800;
                wfx.Size = 22;
                wfx.dwChannelMask = 0x00000033;
                wfx.wValidBitsPerSample = 16;
                string codecPrivateData = wfx.ToHexString();

                Dictionary<MediaStreamAttributeKeys, string> audioStreamAttributes = new Dictionary<MediaStreamAttributeKeys, string>();
                audioStreamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = codecPrivateData; // 管线需要正确初始化和呈现的编码解码器数据。对于视频,这是标头信息。对于音频,这是 base16 编码的 WaveFormatEx 结构。
                this.audioStreamDescription = new MediaStreamDescription(MediaStreamType.Audio, audioStreamAttributes); // 详尽描述媒体流,以便初始化 MediaElement 和基础媒体管线。

    2013年5月28日 9:12

答案

  • 你好,

    Silverlight 不支持FLV 视频格式,请参见:http://msdn.microsoft.com/zh-cn/library/cc189080(v=vs.95).aspx

    如何解码 FLV 文件中的 AAC 音频流,我推荐你查看

    http://www.cnblogs.com/scottwong/archive/2010/05/30/1747522.html

    并尝试以下代码看是否有作用

     WaveFormatExtensible wfx = new WaveFormatExtensible();
        wfx.FormatTag = 0x00FF; // AAC=0x00FF; MP3=0x0055; ADPCM=0x5346; PCM=0x0001
        wfx.Channels = 2;
        wfx.BlockAlign = 8;
        wfx.BitsPerSample = 16;
        wfx.SamplesPerSec = 44100;
        wfx.AverageBytesPerSecond = wfx.SamplesPerSec * wfx.Channels * wfx.BitsPerSample / wfx.BlockAlign;
        wfx.Size = 0;
        string codecPrivateData = wfx.ToHexString();
    
        Dictionary<MediaStreamAttributeKeys, string> audioStreamAttributes = new Dictionary<MediaStreamAttributeKeys, string>();
        audioStreamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = codecPrivateData; // 管线需要正确初始化和呈现的编码解码器数据。对于视频,这是标头信息。对于音频,这是 base16 编码的 WaveFormatEx 结构。
        this.audioStreamDescription = new MediaStreamDescription(MediaStreamType.Audio, audioStreamAttributes); // 详尽描述媒体流,以便初始化 MediaElement 和基础媒体管线。

    谢谢!


    Yanping Wang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2013年5月30日 6:27
    版主

全部回复

  • 你好  我移到 silverlight论坛了

    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2013年5月29日 5:32
  • 你好,

    Silverlight 不支持FLV 视频格式,请参见:http://msdn.microsoft.com/zh-cn/library/cc189080(v=vs.95).aspx

    如何解码 FLV 文件中的 AAC 音频流,我推荐你查看

    http://www.cnblogs.com/scottwong/archive/2010/05/30/1747522.html

    并尝试以下代码看是否有作用

     WaveFormatExtensible wfx = new WaveFormatExtensible();
        wfx.FormatTag = 0x00FF; // AAC=0x00FF; MP3=0x0055; ADPCM=0x5346; PCM=0x0001
        wfx.Channels = 2;
        wfx.BlockAlign = 8;
        wfx.BitsPerSample = 16;
        wfx.SamplesPerSec = 44100;
        wfx.AverageBytesPerSecond = wfx.SamplesPerSec * wfx.Channels * wfx.BitsPerSample / wfx.BlockAlign;
        wfx.Size = 0;
        string codecPrivateData = wfx.ToHexString();
    
        Dictionary<MediaStreamAttributeKeys, string> audioStreamAttributes = new Dictionary<MediaStreamAttributeKeys, string>();
        audioStreamAttributes[MediaStreamAttributeKeys.CodecPrivateData] = codecPrivateData; // 管线需要正确初始化和呈现的编码解码器数据。对于视频,这是标头信息。对于音频,这是 base16 编码的 WaveFormatEx 结构。
        this.audioStreamDescription = new MediaStreamDescription(MediaStreamType.Audio, audioStreamAttributes); // 详尽描述媒体流,以便初始化 MediaElement 和基础媒体管线。

    谢谢!


    Yanping Wang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2013年5月30日 6:27
    版主