简体   繁体   中英

Converting a stereo channel audio file to left channel only, through command line

Say I have a bunch of mp3 files. How would I go about using an audio software command-line tool to decrease the volume completely on one side of the audio file (right), leaving on the left side of the audio file complete? I would then like to save this file to a new mp3 file. This needs to be done entirely over the command line.

As an another approach. Is it possible to use a command line audio file tool to convert a stereo mp3 file to mono, then to merge this mono file with a "silent" track of the same length, creating a left-headphone track with sound and a right-headphone track with silence?

In this SO question, there seems to be a number of approaches to a rather eccentric end goal. In the first possible solution, I just want to decrease the volume of the right side. In the second possible solution, I want to combine a few more common steps to achieve the same end result.

The problems here are that:

  • I can't find a good command-line tool for modifying audio files, even to do the second approach which should be a more common request.
  • I'm expecting that I'll first need to convert the mp3 file to wav, using a similar or second tool
  • This query is eccentric so there aren't many links about it on the web.

Thanks for any help. Audacity would be my go-to normally, but it appears to be GUI only.

SoX lets you do this very easily.
The first case, muted right channel:

sox test.mp3 test-rmuted.mp3 remix 1 0

The second case, summed mono on left channel:

sox test.mp3 test-lmono.mp3 remix 1,2 0

To batch process you could just do a simple for loop.
Muted right channel:

for f in *.mp3
do
  basename="${f%.*}"
  echo "$basename"
  sox "$f" -t wav - remix 1 0 | \
    lame --preset standard - "00-${basename}-rmute".mp3
done

Summed mono on left channel only:

for f in *.mp3
do
  basename="${f%.*}"
  echo "$basename"
  sox "$f" -t wav - remix 1,2 0 | \
    lame --preset standard - "00-${basename}-lmono".mp3
done

You can forgo LAME and do the encoding with SoX as in the first two examples, but I find this method simpler and more flexible.

As suggested in a comment you should be able to use FFmpeg to process your audio files. Dropping one channel completely would produce a different result than doing conversion to mono first. However, I think either could be achieved with the pan filter in FFMpeg.

https://trac.ffmpeg.org/wiki/AudioChannelManipulation

https://ffmpeg.org/ffmpeg-filters.html#pan

Attenuation of one channel

  • Decode mp3 file to wav
  • Create a new stereo wav file using the pan filter 100% to one channel
  • Encode the resulting wav file to mp3

Mixing both channels evenly in one channel, then attenuating the other channel

  • Decode mp3 file to wav
  • Create a new wav file using the pan filter with one channel 50% from left and 50% right, and the other channel with 0 gain
  • Encode the resulting wav file to mp3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM