📜 ⬆️ ⬇️

Decoding / cutting / encoding audio files

published at the request of the wonderful username catdog

Background:

It is hardly possible now to find a programmer who does not know how to take screenshots using mencoder and use them as a preview for a video file. However, I have not yet seen such solutions for audio files, it is understandable why: here, as a rule, you can either give the file completely or pinch the console converters to the digestible format completely.

And everything would be fine, but when you have an average track length of 6 minutes, you have to think how to make a cut, thus reducing the size of thumbnails and making it easier for the user to listen to the material. Once upon a time I used a set of POC utilities for this, they worked only with mp3 and were able to quickly count the length, cut / glue by time. Then I quickly wrote a wrapper around this disgrace and for a while forgot about it.
')
However, new times came and the people began to download music in flac-e, monkey audio and other lossless formats. Yes, the mp3 itself has evolved over time and often began to add album images to it, which became a big problem and the cause of frequent POC fragments.

It was then that I decided to write an application that would incorporate the entire set of POC utilities for cutting gluing, and would have an encoder for mp3 plus.

And now about what happened:


recoded is a console utility for Linux / * BSD / Mac OS using libav (ffmpeg) for decoding / cutting / encoding audio files. It integrates perfectly into any scripts to convert:
you just need to feed the file for cutting and tell where to put the finished thumbnail.
Through the use of libav, support is achieved for almost all audio formats that have distribution (mp3, ogg, flac, ape, wav and others).

Cutting is carried out according to the following algorithm:


Where to get:

Beta release:
myau.su/recoded-0.1.3.tgz
svn co svn: //myau.su/recoded/tags/0.1.3 recoded

trunk from svn:
svn co svn: //myau.su/recoded/trunk recoded

How to collect:

The first thing you need to do is make sure that you have libav (it is advisable to take it from the sfn-project of ffmpeg, due to the fact that in distributions it is usually quite old and the architecture of the library has changed since then).
Small recommendation on building ffmpeg and libav:
./configure --prefix=/usr --enable-shared --enable-static --enable-libmp3lame --enable-nonfree --enable-gpl
On the one hand, this will include nonfree and gpl components (! Sic, after which the library will become non-proliferative) and allow the assembly with lame, which is needed for encoding mp3.

Then you can go to the assembly of the application itself (under * nix systems, you need cmake, under mac os - xcode)

For mac os:
open the project file in the root and press cmd + b.

For * nix systems:
cmake .
make


As a result, get the recoded binary which we need.

Command line options and exit codes:

Command line options:

Exit codes:


Using:

For example, you can do this:
./recoded -f input_file.ogg -t out.mp3 -v

As output, you will get some information about the thread (if any) and the exit code:
Front ring size: 38393856
Samples decoded: 19196928
Samples bytesize: 76787712
Channels: 2
Codec name: MP3 (MPEG audio layer 3)
Sample format: 1
Sample rate: 44100


The input can be any audio (video + audio) file, the file can be without an extension at all (the format is guessed by the libav library by titles and contents)
The output is always mp3 44100, joined stereo, 96kbps. (regardless of what the sample rate and bitrate was, this is done because mp3 in the flash is selective for food)

Comments and comments of the author:

This is the first release, not even beta or alpha, something else pre-release rather. Laid out solely in order to speed up development. So if someone has an idea or desire to delve into the code, then you are welcome.

Source: https://habr.com/ru/post/62720/


All Articles