C#Net7mma H264 / PCMU流媒体

我在创建一个包含音频和视频音频和视频的流时遇到问题 . 我正在为rtsp服务器使用net7mma库 . 我正在播放视频给wowza . 我得到了H264 / AVC视频流和PCMU 44,1k采样率视频流 . 这就是我这样做的方式:首先我创建媒体:

RFC6184Media newMedia = new RFC6184Media(704, 480, camName);

然后,当视频帧出现时,我做:

var newFrame = new RFC6184Media.RFC6184Frame(96);
newFrame.Packetize(buff);
media.AddFrame(newFrame);

对于这个步骤一切正常,视频看起来不错 . 问题是当我想添加音频时 . 从我的设备我收到 raw PCMU 8k 采样率所以我需要使用NAudio库重新采样到44100:

var provider = new RawSourceWaveStream(new MemoryStream(buff), new WaveFormat(8000, 1));
provider.ToSampleProvider();

var outFormat = new WaveFormat(44100, provider.WaveFormat.Channels);
var resampler = new WaveFormatConversionStream(outFormat, provider);

MemoryStream memStr = new MemoryStream();

WaveFileWriter.CreateWaveFile("pcm", resampler);
var audioBytes = File.ReadAllBytes("pcm");

var newFrame = PacketizeBufer(audioBytes);
media.AddFrame(newFrame);

我的打包方法如下:

private RtpFrame PacketizeBufer(byte[] messageBuffer)
    {
        var newFrame = new RtpFrame(96);
        int countOfArray = messageBuffer.Length / 1500;
        if (messageBuffer.Length % 1500 > 0)
            countOfArray++;
        RtpPacket packet;
        for (int i = 0; i < countOfArray; i++)
        {
            byte[] tempToSend = messageBuffer.Skip(i * 1500).Take(1500).ToArray();
            if (i == countOfArray - 1)
            {
                packet = new RtpPacket(2, false, false, true, 0, 0, 0, i, 0, tempToSend);
                newFrame.Add(packet);
                break;
            }
            packet = new RtpPacket(2, false, false, false, 0, 0, 0, i, 0, tempToSend);
            newFrame.Add(packet);
        }
        return newFrame;
    }

SDP看起来像这样:

v=0
o=ASTI-Media-Server 15943110217466738919 -2503633856242812693 IN IP4 [ip_addr]
s=ASTI-Streaming-Session-stream-name
a=sendonly
a=type:broadcast
a=rtpmap:0 PCMU/44100
a=fmtp:0 packetization-mode=1;profile-level-id=64001F;sprop-parameter-sets=Z0LAHtkDxWhAAAADAEAAAAwDxYuS,aMuMsg==
a=fmtp:96 packetization-mode=1;profile-level-id=64001F;sprop-parameter-sets=Z0LAHtkDxWhAAAADAEAAAAwDxYuS,aMuMsg==
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=control:/live/b8f38900-b1ba-4dda-b00c-2ccd6f847c61/video
m=audio 0 RTP/AVP 0
a=control:/live/b8f38900-b1ba-4dda-b00c-2ccd6f847c61/audio
Session=> 2359fd8e-f449-4db7-a19e-48ca78cc3422

关于这一点的奇怪之处在于,当我将视频和音频保存到一个文件时,它将无法正常工作 . 当我单独保存视频和音频(视频为h264,音频为wav)视频gest音频时 .

回答(0)