Using SoX to change the volume level of a range of time in an audio file

后端 未结 2 1719
南方客
南方客 2021-02-15 12:24

I’d like to change the volume level of a particular time range/slice in an audio file using SoX.

Right now, I’m having to:

  1. Trim the original file three tim
2条回答
  •  别那么骄傲
    2021-02-15 13:13

    Okay, with ffmpeg and filters it's all quite simple.

    Imagine that you have 2 tracks, A and B. And you want to crop ones and do something about the volume. So the solution would be:

    ffmpeg -y -i 1.mp3 -i 2.mp3 i f454495482c151aea8761dda.mp3 -i f5544954796af4a171f11b57.mp3 -i f754495448788e35e6123679.mp3 -i f754495448788e35e6123679.mp3 -i f85449545e646dea98e5dd19.mp3 \
    -filter_complex "[0]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume='if(between(t,129.00,129.20),0.15000*(t - 129.00) + 0.03,1)':eval=frame,volume='if(between(t,129.20,181.50),-0.00057*(t - 129.20) + 0.06,1)':eval=frame,volume='if(between(t,181.50,181.60),0.40000*(t - 181.50) + 0.03,1)':eval=frame,volume='if(between(t,181.60,183.50),-0.03684*(t - 181.60) + 0.07,1)':eval=frame,volume='if(between(t,183.50,188.00),0.00000*(t - 183.50) + 0.00,1)':eval=frame,atrim=0.00:56.00,adelay=129000|129000|129000|129000,apad[0:o];[1]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume='if(between(t,0.00,134.00),0.00000*(t - 0.00) + 0.06,1)':eval=frame,atrim=0.00:134.00,apad[1:o];[0:o][1:o]amix=inputs=28,atrim=duration=185.00" -shortest -ac 2 output.mp3
    

    which will take 2 input files, transform both of the streams to the appropriate aformat and then apply volume filters.

    The syntax for volume is simple: if time t is between some start and end time - then apply the volume filter, based on the desired start volume level plus by some coefficient multiplied by difference between the start time and current time t.

    This will increase the volume linearly from initial volume to desired value on a range.

    atrim will trim the audio chunk after the volume has been adjusted on all ranges.

    ffmpeg is just amazing, the expressions could be very complex and many of math functions may be used in the expressions.

提交回复
热议问题