2014-03-25 100 views
2

我試圖播放來自Red5服務器的AAC音頻直播流,因此解碼我使用Javacv-ffmpeg的音頻數據。數據被接收爲一個字節的數據包[] 這裏是我試圖在Android上使用javacv-ffmpeg解碼來自red5服務器的AAC音頻流

public Frame decodeAudio(byte[] adata,long timestamp){ 
    BytePointer audio_data = new BytePointer(adata); 
    avcodec.AVCodec codec1 = avcodec.avcodec_find_decoder(avcodec.AV_CODEC_ID_AAC);// For AAC 
    if (codec1 == null) { 
    Log.d("showit","avcodec_find_decoder() error: Unsupported audio format or codec not found: " + audio_c.codec_id() + "."); 
    } 
    audio_c = null; 

    audio_c = avcodec.avcodec_alloc_context3(codec1); 
    audio_c.sample_rate(44100); 
    audio_c.sample_fmt(3); 
    audio_c.bits_per_raw_sample(16); 
    audio_c.channels(1); 
    if ((ret = avcodec.avcodec_open2(audio_c, codec1, (PointerPointer)null)) < 0) { 
    Log.d("showit","avcodec_open2() error " + ret + ": Could not open audio codec."); 
    } 

    if ((samples_frame = avcodec.avcodec_alloc_frame()) == null) 
    Log.d("showit","avcodec_alloc_frame() error: Could not allocate audio frame."); 

    avcodec.av_init_packet(pkt2); 

    samples_frame = avcodec.avcodec_alloc_frame(); 
    avcodec.av_init_packet(pkt2); 
    pkt2.data(audio_data); 
    pkt2.size(audio_data.capacity()); 
    pkt2.pts(timestamp); 
    pkt2.pos(0); 

    int len = avcodec.avcodec_decode_audio4(audio_c, samples_frame, got_frame, pkt2); 
} 

但是len個解碼返回-1爲第一幀,然後-22總是後。
第一分組是這樣總是

AF 00 12 08 56 E5 00 

此外分組是像

AF 01 01 1E 34 2C F0 A4 71 19 06 00 00 95 12 AE AA 82 5A 38 F3 E6 C2 46 DD CB 2B 09 D1 00 78 1D B7 99 F8 AB 41 6A C4 F4 D2 40 51 17 F5 28 51 9E 4C F6 8F 15 39 49 42 54 78 63 D5 29 74 1B 4C 34 9B 85 20 8E 2C 0E 0C 19 D2 E9 40 6E 9C 85 70 C2 74 44 E4 84 9B 3C B9 8A 83 EC 66 9D 40 1B 42 88 E2 F3 65 CF 6D B3 20 88 31 29 94 29 A4 B4 DE 26 B0 75 93 3A 0C 57 12 8A E3 F4 B9 F9 23 9C 69 C9 D4 BF 9E 26 63 F2 78 D6 FD 36 B9 32 62 01 91 19 71 30 2D 54 24 62 A1 20 1E BA 3D 21 AC F3 80 33 3A 1A 6C 30 3C 44 29 F2 A7 DC 9A FF 0F 99 F2 38 85 AB 41 FD C7 C5 40 5C 3F EE 38 70 

無法找出其中的問題,無論是在設置avcodec中上下文audio_c或用於譯碼器設定包。

任何幫助表示讚賞。提前致謝。

回答

0

第一個數據包(config)描述了流數據,如果我沒有弄錯數據的後續是編碼音頻。您不能假定採樣率等。如上所述,您需要從配置數據中標記出「AF 00」。

+0

你會建議從哪裏s我應該考慮將數據提供給解碼器,從開始AF 00的數據...還是隻忽略AF。 –

+0

我看到了關於SO的acc數據的更好細目,但是我找不到它。我將不得不向你指出這些文章來幫助你:http://wiki.multimedia.cx/index.php?title=Understanding_AAC#Packaging.2FEncapsulation_And_Setup_Data和http://wiki.multimedia.cx/index.php ?title = MPEG-4_Audio –

+1

經過很多天..我發現丟棄數據包中的第一個** AF 00 **數據,並設置正確的通道數(在我的情況下爲2)以及通道佈局和配置文件類型音頻上下文使解碼器工作正常... –

0

我有類似的問題。我已經截獲使用Wireshark的數據包,這裏是它告訴我: AF是AAC幀的控制字節,並將其解碼爲以下位:

1010 .... = Format: HE-AAC 
.... 11.. = Sample rate: 44kHz (allthough FFMPEG shows me 48kHz and I would lean to believe it more) 
.... ..1. = Sample size: 16 bit 
.... ...1 = Channels: stereo 

我仍然無法弄清楚如何普遍解碼這些數據。

編輯: 哈!我有東西:) 我想前2個字節是RTMP特定的字節。第二個似乎表明,無論是配置(0)還是實際有效負載(1) - 我沒有發現確認的來源,這只是我的假設。 然後,第一,短包,這裏描述的AAC配置描述: http://thompsonng.blogspot.com/2010/03/aac-configuration.html

在我的情況是:

11 90 

這是二進制:

0001 0001 1001 0000 

和解碼,以:

0001 0... .... .... = 2 = AAC LC 
.... .001 1... .... = 3 = 48 kHz 
.... .... .001 0... = 2 = 2 channels (stereo) 
.... .... .... .0.. = 0 = 1024 sample length 
.... .... .... ..0. = 0 = doesn't depends on core code (?) 
.... .... .... ...0 = 0 = extension flag 
相關問題