S
S
Sergey2014-06-29 01:51:38
C++ / C#
Sergey, 2014-06-29 01:51:38

Audio transcoder as a decorator for streams: what other ideas do you have for a beautiful and convenient wrapper?

Started writing libavcodec+libavformat binding (only audio format support) for D, also implementing binding for libmpg123. low-level bindings work, but I want to make a beautiful and convenient wrapper for audio encoding / decoding. Unfortunately, the problem is banal: my knowledge and experience with such things is clearly not enough to evaluate the pros and cons of individual approaches.
Based on our tasks, for which all this was started, we need the independence of the wrapper from the data source, that is, for good, we must tie decoders and encoders to the InputStream and OutputStream interfaces, respectively (as a profit, the ability to add IO buffering with simple decoration). The advantages of streams are obvious: it can be both a file and an HTTP stream (more precisely, we can encapsulate any logic for working with data into a stream, say, quickly add the ability to decode an HTTP stream) ... Same (although it’s not clear who will do this) , the file may already be in memory.
After some dancing with a tambourine, we managed to get mpg123 and libav to work with streams, but it still looks just like a separate wrapper function that simplifies the initialization process.
For the last couple of hours, the thought of using the decoder as a decorator over streams has been desperately tormenting my head. In fact, we have a stream transcoder. We write to the stream, for example, mp3 and read data from it in a different format (or just PCM, depending on the settings). But so far I have settled on the variant
The problem that I see so far is the inability to get information about the decoded frames "beautifully". For example:

// работает автоопределение формата контейнера, но можно задавать отдельно параметры декодирования
auto input = new Decoder(new File("in.mp3")); 
auto output = new Encoder(new File("out.ogg")); // настройки можно задавать отдельно...
foreach (ubyte[] buffer; input) {
    // делаем с PCM что-либо полезное
    // и сохраняем в новом формате
    output.write(buffer);
}

I can't think of a "beautiful" way to get information about frames yet. Well, I'm not really sure that this option will be convenient.
In a word ... I'm already weakly thinking and I ask you to tell me if anyone has seen and used a convenient implementation of the API for encoding / decoding audio? It can be an implementation in any programming language, it is the idea that matters.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question