如何识别音频流格式? [英] How to recognize the audio stream format?

查看:255
本文介绍了如何识别音频流格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有用于将音频流记录到文件的代码.问题是我想使用正确的文件扩展名(主要是.mp3和.aac)保存此文件.我该如何实现?

Here I have the code which records a audio stream to file. The problem is I'd like to save this file with correct file extension (mainly .mp3 and .aac). How can I achieve this?

URLConnection conn = new URL(StringUrls[0]).openConnection();
            InputStream in = conn.getInputStream();

            BufferedOutputStream bufOutstream = new BufferedOutputStream(new FileOutputStream(new File(env.getExternalStorageDirectory()+"/temp.file")));

            byte[] buffer = new byte[4096];
            int len = in.read(buffer);
            while (len != -1) {
                bufOutstream.write(buffer, 0, len);
                len = in.read(buffer);

                if (Recorder.this.isCancelled) break;

            }
            bufOutstream.close();

推荐答案

一种方法是在您已经拥有二进制数据的情况下查看它们.根据该文件签名表,MP3和AAC都具有唯一的魔术头:

One way would be to take a look at the binary data while you already have it in your hands. According to this File signatures table both MP3 and AAC have unique magic headers:

    49 44 33用于 MPEG-1音频第3层(MP3)音频文件
  • FF F1用于 MPEG-4高级音频编码(AAC)低复杂度(LC)音频
  • FF F9用于 MPEG-2高级音频编码(AAC)低复杂度(LC)音频
  • 49 44 33 for MPEG-1 Audio Layer 3 (MP3) audio file
  • FF F1 for MPEG-4 Advanced Audio Coding (AAC) Low Complexity (LC) audio
  • FF F9 for MPEG-2 Advanced Audio Coding (AAC) Low Complexity (LC) audio

这篇关于如何识别音频流格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆