Search code examples
androidcmdffmpegwavvolume

Changing Audio Volume using FFmpeg Android


As I have understood, the only way to change FFmpeg volume is to do it throught a command line.

This is what should change the volume of the audio :

ffmpeg -i input.wav -filter:a "volume=1.5" output.wav

Now I have used FFmpeg with command line before and it looked like this and gave me no errors:

    String[] cmd = { "-i" , pcmtowavTempFile.toString(), "-i", mp3towavTempFile.toString(), "-filter_complex", "amix=inputs=2:duration=first:dropout_transition=3", combinedwavTempFile.toString()};
    ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
        @Override
        public void onSuccess(String message) {                
            super.onSuccess(message);
            encodeWavToAAC();
        }
        @Override
        public void onFailure(String message) {
            super.onFailure(message);
            onError(message);
        }
    });

But If I try to do it with audio volume in the same method, it just ignores it :

    String[] cmd = { "-i" , pcmtowavTempFile.toString(),  "-filter:a", "volume=1.3", pcmtowavTempFile.toString()};
    ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
        @Override
        public void onSuccess(String message) {
            super.onSuccess(message);
        }
        @Override
        public void onFailure(String message) {
            super.onFailure(message);

        }
    });

I get neither, no success or error message with the last volume change method.

Since the volume is there between " ", I tried adding this :

String[] cmd = { "-i" , pcmtowavTempFile.toString(),  "-filter:a", "\"volume=1.3\"", pcmtowavTempFile.toString()};

But the app started crashing after adding this line.


Solution

  • The error here was that FFmpeg does NOT perform in-place editing which means that I can not overwrite the same File. I tried overwriting by adding command "-y" but that did not also work because of that same rule.

    So the solution was to create a new File as output File.