Question

I'm trying to trim silence from a mp3 file, and parse the progress details:

G:\testing\test>sox -S trim.mp3 trim2.mp3 reverse silence 1 0.1 0.1% reverse

Input File     : 'trim.mp3'
Channels       : 2
Sample Rate    : 44100
Precision      : 16-bit
Duration       : 00:04:24.06 = 11644870 samples = 19804.2 CDDA sectors
Sample Encoding: MPEG audio (layer I, II or III)

In:100%  00:04:23.96 [00:00:00.09] Out:11.6M [      |      ] Hd:0.0 Clip:400
sox sox: trim2.mp3: output clipped 400 samples; decrease volume?
Done.

G:\testing\test>

I should be able to parse this data, while taking the Out:11.6M data as my progress, however this file's filesize is actually 4.03MB. Perhaps this data is not about the output filesize?

How can I correctly conclude the progress of the encoding task?

Was it helpful?

Solution

You are right, the Out value is not about the file size, but the number of samples. It’s approximately the 11644870 samples that are mentioned in the Duration field: about 264 seconds times 44100 samples per second. For uncompressed output, the file size is mostly proportional to the number of samples (e.g. at 16 bits stereo, 4 bytes per sample, plus the header size). For compressed output, the relationship is less strict.

The Out value is not necessarily a good progress indicator, though. In your case, due to the reversals, SoX will have processed all audio already before it starts writing anything.

Note also that SoX works by first converting the input into an internal (PCM) representation, then processing it, then newly converting it into the output format. Since you are processing files that are already lossily compressed, the sound quality may suffer slightly, and more so if you re-process the results (generation loss).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top