Ted Gueniche
Ted Gueniche

Reputation: 813

AAC RTP timestamps and synchronization

I am currently streaming audio (AAC-HBR at 8kHz) and video (H264) using RTP. Both feeds works fine individually, but when put together they get out of sync pretty fast (lass than 15 sec).

I am not sure how to increment the time stamp on the audio RTP header, I thought it should be the time difference between two RTP packets (around 127ms) or a constant increment of 1/8000 (0.125 ms). But neither worked, instead I managed to find a sweet spot. When I increment the time stamp by 935 for each packet It stays synchronized for about a minute.

Upvotes: 0

Views: 4023

Answers (3)

Ritesh
Ritesh

Reputation: 1847

Bit late, but thought of putting up my answer.

Timestamp on Audio RTP packet == the number of audio samples contained in RTP packet.

For AAC, each frame consist of 1024 samples, so timestamp on RTP packet should increase by 1024.

Difference between the clocktime of 2 RTP packets = (1/8000)*1024 = 128ms, i.e sender should send the rtp packets with difference of 128 ms.

Bit more information from other sampling rates:

Now AAC sampled at 44100hz means 44100 sample of signal in 1 sec. So 1024 samples means (1000ms/44100)*1024 = 23.21995 ms So the timestamp between 2 RTP packets = 1024, but The difference of clock time between 2 RTP packets in rtp session should be 23.21995ms.

Trying to correlate with other example:

For example for G711 family (PCM, PCMU, PCMA), The sampling frequency = 8k. So the 20ms packet should have samples == 8000/50 == 160. And hence RTP timestamps are incremented by 160. The difference of clock time between 2 RTP packets should be 20ms.

Upvotes: 1

Cynichniy Bandera
Cynichniy Bandera

Reputation: 6103

IMHO video and audio de-sync in android is difficult to fight if they are taken from different media recorders. They just capture different start frames and there is no way (as it seems) to find out how big de-sync is and adjust it with audio or video timestamps on flight.

Upvotes: 0

Danijel
Danijel

Reputation: 8616

AAC frame size is 1024 samples. Try to increment by (1/8000) * 1024 = 128 ms. Or a multiple of that in case your packet has multiple AAC frames.

Does that help?

Upvotes: 1

Related Questions