FFmpeg – How to Delete Empty Audio Channels from MOV File

audioffmpegvideo

I have to work with video files obviously recorded with somekind of 5.1 setup where only two channels got filled with mono signals from two separate microphones. My idea is to use ffmpeg to delete the four empty channels but am lost.

I managed to delete all audio streams, but after hours of try and error usinf -map, -filter, etc., I did not manage to delete the empty channels within the audio stream. Channels 3 & 4 do contain the audio that I'd like to have as separate mono tracks. Channels 1,2,5,6 should be deleted and the video stream should just be copied.

This is the output of ffprobe:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '2.MOV':
  Metadata:
    major_brand     : qt
    minor_version   : 537199360
    compatible_brands: qt
    creation_time   : 2022-01-21T04:37:49.000000Z
    make            : Atomos
    make-eng        : Atomos
    encoder         : ShogunInferno - 9.11
    encoder-eng     : ShogunInferno - 9.11
    com.atomos.hdr.gamut: Rec709
    com.atomos.hdr.gamma: SLog2
    com.atomos.hdr.camera: Sony
    com.apple.proapps.image.{TIFF}.Make: Atomos
    com.apple.proapps.image.{TIFF}.Model: ShogunInferno
    com.apple.proapps.image.{TIFF}.Software: 9.11
    timecode        : 05:11:39:13
  Duration: 00:01:14.78, start: 0.000000, bitrate: 1064887 kb/s
  Stream #0:0[0x1](eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 6 channels, s32 (24 bit), 6912 kb/s (default)
    Metadata:
      creation_time   : 2022-01-21T04:37:49.000000Z
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](eng): Video: prores (Standard) (apcn / 0x6E637061), yuv422p10le(tv, bt709/bt709/unknown, progressive), 4096x2160, 1057968 kb/s, SAR 1:1 DAR 256:135, 50 fps, 50 tbr, 5k tbn (default)
    Metadata:
      creation_time   : 2022-01-21T04:37:49.000000Z
      vendor_id       : appl
      encoder         : Apple ProRes 422
  Stream #0:2[0x3](eng): Data: none (tmcd / 0x64636D74) (default)
    Metadata:
      creation_time   : 2022-01-21T04:37:49.000000Z
      timecode        : 05:11:39:13

Thanks for help…

Best Answer

I am not really sure about the channel layout, you may try the following syntax:

ffmpeg -y -i six_channels.mp4 -filter_complex "[0:a]channelsplit=channel_layout=5.1[FL][FR][FC][LFE][BL][BR];[FC][LFE]amix=inputs=2[a];[FL]anullsink;[FR]anullsink;[BL]anullsink;[BR]anullsink" -map 0:v -map "[a]" -vcodec copy -acodec aac -ar 48000 -ac 2 stereo.mov


  • [0:a]channelsplit=channel_layout=5.1[FL][FR][FC][LFE][BL][BR] - split the 5.1 layout into 6 audio channels with temporary the names [FL],[FR],[FC],[LFE],[BL],[BR].
  • [FC][LFE]amix=inputs=2[a] - merges channels [FC] and [LFE] to temporary name [a].
  • [FL]anullsink;[FR]anullsink;[BL]anullsink;[BR]anullsink - ignores the redundant audio channels.
  • -vcodec copy -acodec aac -ar 48000 -ac 2 - select audio codec, sample rate and number of output channels.

Creating the a input six_channels.mp4 (for testing):

ffmpeg -y -f lavfi -i testsrc=size=192x108:rate=1 -f lavfi -i sine=frequency=1000 -f lavfi -i sine=frequency=1000 -f lavfi -i sine=frequency=300 -f lavfi -i sine=frequency=400 -f lavfi -i sine=frequency=1000 -f lavfi -i sine=frequency=1000 -filter_complex "join=inputs=6:channel_layout=5.1:map=0.0-FL|1.0-FR|2.0-FC|3.0-LFE|4.0-BL|5.0-BR" -acodec aac -ar 48000 -ac 6 -t 10 six_channels.mp4


Update:

Two separate mono tracks and PCM24 codec:

Command line example:

ffmpeg -y -i six_channels.mp4 -filter_complex "[0:a]channelsplit=channel_layout=5.1[FL][FR][FC][LFE][BL][BR];[FL]anullsink;[FR]anullsink;[BL]anullsink;[BR]anullsink" -map 0:v -map "[FC]" -map "[LFE]" -vcodec copy -acodec pcm_s24le -ar 48000 -ac 1 two_mono_tracks.mov

Related Question