如何无缝连接MP3流? [英] How do I seamlessly concatenate MP3 streams?

查看:105
本文介绍了如何无缝连接MP3流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用能够广播目标广告的流服务器.基本上,听众听到的是相同的音乐,但是每隔30分钟就会出现一个广告块,每个听众都有自己的音乐块.实现这样的流服务器会带来各种问题,这个问题只是其中之一.

I'm working on a streaming server that will be capable of broadcasting targetted ads. Basically listeners hear the same music, but every, say, 30 minutes comes a block of ads and every listener has his/her own block. Implementing such streaming server poses various problems and this question is about one of them.

服务器将以类似于Icecast的方式工作,即它将通过网络从某个流生成器读取流并将其中继给每个侦听器.在广播广告时,服务器停止从生成器中获取流,从文件中读取广告,并将其插入每个侦听器的缓冲区中,进行传输,并继续中继来自生成器的流.

The server will work in a manner similar to Icecast, i.e. it will read the stream over the network from some stream generator and relay it to every listener. When it's time to broadcast ads, the server stops fetching the stream from the generator, reads ads from files and inserts them into each listener's buffer, transmits them and resumes on relaying stream from the generator.

当服务器从中继流切换到广播广告时,它必须连接两个MP3流(我们在MP3中广播).我担心的是,简单地将一个数据接一个添加可能会产生一些可听见的失真.可以无缝完成吗?

When the server switches from relaying stream to broadcasting ads, it has to concatenate two MP3 streams (we broadcast in MP3). My concern is that simply appending one piece of data after another may produce some audible artifacts. Can it be done seamlessly?

我已经弄清楚了: -我可以使服务器知道MP3帧,以避免同步错误. -我正在考虑在流中的MP3帧之后添加广告文件中的MP3帧. -由于广告是从正确编码的MP3文件中加载的,因此我避免了字节存储的问题,因为文件中的第一帧无法使用它.

I've already figured out this: - I can make the server be aware of MP3 frames to avoid sync errors. - I'm thinking about appending MP3 frames from the ad file after MP3 frames from the stream. - Since ad is loaded from properly encoded MP3 file, I circumvent the problem of byte reservoir, because the first frame from the file can't use it.

但是我担心的是MDCT的工作方式.侦听器不知道我的服务器将执行什么操作,因此它们的MP3解码器可能会产生一些伪像,因为不正确的MDCT数据将在下载的流中一个接一个地放置.广告在文件开头的零填充是否可以弥补这一点?

But my concern is the way MDCT works. Listeners have no idea of what my server will do, so their MP3 decoders may produce some artifacts because incorrect MDCT data will be placed one after another in the stream they download. Will zero-padding at the beginning of the file with the ad compensate for this?

您是否知道可以无缝连接两个MP3文件而不解压缩的任何库/工具(如果可能,则为开源)?

Do you know any libraries/tools (open source if possible) that can seamlessly join two MP3 files without decompressing them?

您能指出描述MP3格式的任何有用资源吗?我在互联网上进行了很多搜索,发现了很多信息,但是我仍然错过了总体情况.

Can you point any good resources describing MP3 format? I searched Internet a lot, found lots of information, but I still miss the overall picture.

也许您知道,如果我使用其他编解码器(例如OGG/Vorbis,AAC)会更容易?

Maybe you know that this would be easier if I used another codec like OGG/Vorbis, AAC?

PS.此问题不是>什么是最佳方法的重复项合并mp3文件?. mp3wrap和其他工具都不适合我.

PS. This question is not a duplicate of What is the best way to merge mp3 files?. mp3wrap and tools alike are not an option for me.

推荐答案

您应该能够连接CBR和VBR格式的mp3文件. MP3文件没有主标头(忽略ID3和Xing).音频数据存储为块,其中每个块都包含其自己的标头.标头包含用于解码该块中音频数据的必要信息(比特率,采样频率,立体声等).

You should be able to concatenate mp3 files of both CBR and VBR formats. MP3 files do not have a main header (disregarding ID3 and Xing). The audio data is stored as chunks where every chunk includes its own header. The header contains the necessary information (bitrate, sample frequency, stereo, etc) for the decoding of the audio data in that chunk.

这是很难确定mp3文件持续时间的原因之一.

This is one of the reasons why it is difficult to determine the duration of a mp3 file.

另一种查看方法是,如果将CBR MP3文件与VBR文件连接在一起,则最终结果与一个长VBR文件相同,且音频的第一部分的比特率恒定.

Another way of looking at it is, if you concatenate a CBR MP3 file with a VBR file, the end result is the same as one long VBR file with the first section of Audio at a constant bitrate.

问题是某些MP3播放器可能很严格,并且期望VBR MP3文件具有Xing标头.但是,这从来不是MP3格式的规范,但现在假定它是正确的.

The issue is that some MP3 players may be strict and expect a Xing header for a VBR MP3 file. This however was never the specification for the MP3 format but it is now assumed to be true.

这篇关于如何无缝连接MP3流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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