Windows/Linux/Android/iOS平臺RTMP功能元件EasyRTMP-Android,推流H264到SRS無法播放原因是什麼?

TSINGSEE發表於2020-11-03

SRS伺服器是定位於網際網路直播伺服器叢集的開源框架,TSINGSEE青犀視訊研發團隊也會拿SRS伺服器來進行流媒體服務的研發和對比。我們可以推送RTMP到SRS、推送RTSP/UDP/FLV到SRS、拉取流到SRS,同時SRS還支援將接入的RTMP流進行各種變換,譬如將RTMP流轉碼。

136.png

研發人員用EasyRTMP-Android測試伺服器推流功能時,選擇了推流到SRS伺服器,但是視訊流播放不了,並且出現如下圖的報錯:

58.png

分析問題:

因為RTMP協議的原因,推流庫在只推流視訊時,預設會加上無聲的音訊,取樣率是8000HZ,但是SRS伺服器處理不了這個取樣率的音訊,所以需要改成44.1kHZ的音訊,SRS伺服器才能處理。

解決問題:

原來的音訊格式是這樣的:

// 取樣率8k的音訊資料
private final char[] gAACMuteData = {
    0xFF, 0xF9, 0x6C, 0x40, 0x21, 0x5F, 0xFC, 0x01, 0x04, 0x34, 0x28, 0xAC, 0xE4, 0x69,
0x21, 0xBF, 0x1A, 0xD5, 0xEA, 0xE1, 0x49, 0x50, 0x54, 0x2A, 0x00, 0x02, 0x01, 0x96,
0x0C, 0x75, 0xD5, 0xBD, 0x53, 0x86, 0xEA, 0x9E, 0x03, 0x78, 0x92, 0xFE, 0xD1, 0xB0,
0x9D, 0x73, 0xFE, 0xCC, 0x42, 0xC2, 0xE4, 0xCD, 0x4A, 0x18, 0x8B, 0x01, 0xB0, 0xD5,
0xB9, 0x22, 0xD9, 0x93, 0x6C, 0x81, 0x5B, 0x2C, 0xA6, 0xD9, 0x9F, 0x85, 0x54, 0xC9,
0xB2, 0xEE, 0xC2, 0x9E, 0xB5, 0xDD, 0x75, 0x35, 0x57, 0xC9, 0x28, 0x97, 0x19, 0x4E,
0xCB, 0x98, 0x19, 0xEB, 0x29, 0x81, 0x34, 0x28, 0x65, 0x2E, 0x39, 0xD0, 0xD4, 0x02,
0x55, 0x30, 0x23, 0xDD, 0xA6, 0xF0, 0x79, 0xEA, 0x4C, 0x06, 0x93, 0x26, 0xB6, 0xFA,
0x21, 0x1F, 0x5A, 0x40, 0x19, 0x53, 0x03, 0x3D, 0x19, 0x5B, 0x81, 0xF4, 0xDF, 0x8B,
0x97, 0xAC, 0xF7, 0x93, 0x76, 0xE2, 0xF1, 0x42, 0x06, 0x97, 0xB9, 0x8B, 0xD2, 0x2B,
0x5F, 0x08, 0x71, 0xFE, 0x01, 0xB8, 0x04, 0x14, 0x0D, 0xF1, 0x44, 0xA5, 0x8E, 0xBC,
0x35, 0x31, 0x06, 0xAD, 0x4F, 0x2B, 0x18, 0xAF, 0x7E, 0x8B, 0x09, 0xEC, 0x84, 0xBA,
0x72, 0x79, 0x79, 0x5C, 0x91, 0x2B, 0x02, 0x0E, 0x54, 0x31, 0xEA, 0xA1, 0x48, 0x32,
0x1C, 0x98, 0x2C, 0xF9, 0x67, 0x2C, 0x74, 0xE0, 0x7C, 0xBD, 0x4F, 0x1D, 0x77, 0xDD,
0xB5, 0x61, 0x86, 0x34, 0x66, 0xB0, 0xC1, 0x01, 0x66, 0xC4, 0x9C, 0x02, 0xFD, 0xA3,
0x2A, 0xD0, 0xD7, 0x3C, 0x8D, 0x78, 0x2C, 0xC8, 0x01, 0x46, 0x80, 0xC1, 0x69, 0xBE,
0xA3, 0x95, 0x6B, 0x3A, 0xD2, 0x2A, 0x44, 0x97, 0x03, 0x05, 0x05, 0x01, 0xF8, 0x13,
0x81, 0xD5, 0xBB, 0x09, 0xAE, 0x6E, 0xAD, 0x75, 0xA0, 0xBA, 0x59, 0xE9, 0x96, 0x61,
0x18, 0x23, 0xFB, 0x76, 0xC1, 0x63, 0xA6, 0x8D, 0x6C, 0x80, 0xF7, 0xB0, 0x20, 0x70
};

即在aacThread執行緒中推流的預設音訊需要改成這樣:

// 取樣率44.1k的音訊資料
private final char[] gAACMuteData1 = {
0x21, 0x0A, 0xCF, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF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