Corrupted AAC files recorded from online stream

懵懂的女人 提交于 2020-01-06 07:31:13

问题


I'm recording audio from an AAC radio stream the simplest way I know:

r = requests.get('http://someradio.net:someport/stream.aac', stream=True)
self.new_filename()

with open(self.filename, 'wb') as f:
  try:
    for block in r.iter_content(self.chunk_size): f.write(block)
  except KeyboardInterrupt:
    pass 

The resulting audio files are not properly encoded (as I guess) causing Adobe applications like Premiere Pro to treat them a funny way. For instance, they import them as mono while they should be stereo and the worst part is that the first half of the audio is stretched over the whole duration in 2x lower pace and the second half is missing.

So I convert the AAC's to MP3's with FFmpeg and AudioSegment (apparently, it knows how to treat these files) which work just fine with Premiere:

stream = AudioSegment.from_file('output.aac', 'aac')
stream.export('output.mp3', format='mp3')

bur the recordings are long and conversion takes time and resources.

I'm pretty sure something very simple can be done to the original AAC's so they can be read properly by Premiere as they are, I just don't know what it is.


Add 1: I think maybe it has something to do with the fact that I'm recording an ongoing stream from the middle, thus a header or something for the AAC file in not being written properly. Namely something appears to be messed up with mono/stereo property.

Add 2: Problem encountered in Adobe Premiere Pro, After Effects and Media Encoder all of which are of the latest version (CC 2018, April). All other applications like players (MPC, VLC, WMP) and Vegas Pro perceive these AAC's just fine.

Add 3: A similar question (unanswered) involving recording from online stream, AAC and 2x-times slower audio corruption: AAC stream resampled incorrectly


回答1:


The core of the problem seems to be Adobe (AE, PP, ME) failing to properly handle HE-AACv2 format in ADTS container, one apparently being a standard for online radio streams. Wiki notes Adobe Flash Player has issues with it and it seems that all other Adobe products do.

Adobe treats such files as 48000Hz mono's while they are really 24000Hz mono's with additional parametric channel for Parametric Channel decoding (which is HE-AACv2 major feature). Looks like Adobe does something unnatural to this mono channel stretching to make a 48000Hz file with the same duration. But that's just my guess, no idea what exactly does Adobe do.

The natural walkaround is a conversion to another format. For instance, AAC-LC even if in ADTS works just fine with Adobe.


Just for the record:

What sound waves look like.



来源:https://stackoverflow.com/questions/51110860/corrupted-aac-files-recorded-from-online-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!