简体   繁体   中英

Change volume of audio file to be merged with video using ffmpeg

Change volume of audio file to be merged with video using ffmpeg

I am using this command to merge audio into a video file

String[] complexCommand = {"-ss", "" + startMs / 1000, "-y", "-i", videopath, "-i", audiopath, "-t", "" + (endMs - startMs) / 1000, "-s", "320x240", "-vcodec", "mpeg4", "-b:v", "2097152", "-b:a", "48000", "-ac", "2", "-ar", "22050", filePath};

How can we control the volume of audio to be merged

I am not sure how/if this can be done directly with ffmpeg - in the past I used sox ( http://sox.sourceforge.net ) to achieve this, but that may have been due to the particular platform/solution rather than a limitation of ffmpeg.

Either way, the sox command in case you need it that worked for me was:

$command = "sox -m -v ".$videoVol." ./temp/videoAudio.mp3 -v ".$musicVol." ./temp/tempMusic.mp3 ./temp/mixedAudio.mp3 2>&1";

The $videoVol variable is a value between 0 and 10.

The full sequence of steps was:

  • extract audio track(s) from video container
  • merge with volume adjust using sox
  • add resulting audio track to video container

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