Search code examples
pythonwavwave

How to re-order the .wav file channels


I need to change the order of channels in .wav file. for example if .wav file contains 16 channel like

"0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"

then need to change this order to

"13 14 15 0 1 2 3 4 5 6 7 8 9 10 11 12"

using any python module.


Solution

  • import subprocess
    
    cmd = 'ffmpeg -i tdm2_no_ch_map_1.wav -af "channelmap=13|14|15|0|1|2|3|4|5|6|7|8|9|10|11|12" -c:a pcm_s32le out.wav'
    
    cmd = subprocess.Popen(cmd)  # , stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    out, err = cmd.communicate()
    print(err)
    

    Prerequisites: ffmpeg - https://m.wikihow.com/Install-FFmpeg-on-Windows#step_2_1

    Note: tested this code on windows machine