2

I have multiple MOV files and each file has different numbers of audio tracks. I want to convert those files to MOV and combine the audio into a single 12-channel audio track.

For example, I have a source file with 4 single-channel audio tracks, and that file has to be output to a file with a single 12-channel audio track. The 1st audio track from the source file must be output to the 1st channel; the 2nd track to the 2nd channel; the 3rd track to the 3rd channel; the 4th track to the 4th channel; and channels 5–12 in the output file will be left without audio.

Another example: If the source file has 6 single-channel audio tracks, then these 6 tracks will be mapped to channels 1-6 channels in the output file and channels 7-12 will be left without audio.

Below is my FFmpeg command. It completes the video transcode without issue and also outputs a single 12-channel audio track. The problem is that all the audio tracks from the source file are being combined in the 1st channel, and channels 2-12 have no audio. I'm using Switch Telestream Player to QC the files.

ffmpeg -i <input>.mp4 -c:v prores_ks -profile:v 0 -quant_mat 2 -c:a pcm_s16le -b:a 512K -filter_complex "[0:a]pan=mono|c0=c0[a0];[0:a]pan=mono|c0=c1[a1];[0:a]pan=mono|c0=c2[a2];[0:a]pan=mono|c0=c3[a3];[0:a]pan=mono|c0=c4[a4];[0:a]pan=mono|c0=c5[a5];[0:a]pan=mono|c0=c6[a6];[0:a]pan=mono|c0=c7[a7];[0:a]pan=mono|c0=c8[a8];[0:a]pan=mono|c0=c9[a9];[0:a]pan=mono|c0=c10[a10];[0:a]pan=mono|c0=c11[a11];[a0][a1][a2][a3][a4][a5][a6][a7][a8][a9][a10][a11]amerge=inputs=12[aout]" -map 0:v -map "[aout]" <out>.mov

I'm using FFAStrans and its included ffmpeg executable to automate the movement and transcode of every file that has been placed in its watchfolder. Can you help me build the correct ffmpeg command?

9
  • I would include a linked minimal source file for testing purposes and also edit the question to include the output of your ffmpeg command.
    – Blindspots
    Commented May 10, 2023 at 14:26
  • 1
    Thanks for editing my question to make it more clear. Commented May 11, 2023 at 1:42
  • Hi sorry for the late reply, I'm thinking of a way on how to share the sample files I have. I didn't notice that sooner that the source files I was testing is a MOV file and not Mp4. Commented May 15, 2023 at 2:04
  • this is the sample file drive.google.com/file/d/1DzPl5oa5ZHz-_TKhbnndzKcAuH1gulat/… Commented May 16, 2023 at 0:41
  • Did this solve your problem?
    – Blindspots
    Commented May 20, 2023 at 5:23

2 Answers 2

1

In the formula below I included only the code related to mapping the mono tracks into a 12-channel track.

ffmpeg -i test_file.mov -filter_complex "[0:a:0]pan=mono|c0=c0[a0];[0:a:1]pan=mono|c0=c0[a1];[0:a:2]pan=mono|c0=c0[a2];[0:a:3]pan=mono|c0=c0[a3];[0:a:0]pan=mono|c0=c1[a4];[0:a:0]pan=mono|c0=c1[a5];[0:a:0]pan=mono|c0=c1[a6];[0:a:0]pan=mono|c0=c1[a7];[0:a:0]pan=mono|c0=c1[a8];[0:a:0]pan=mono|c0=c1[a9];[0:a:0]pan=mono|c0=c1[a10];[0:a:0]pan=mono|c0=c1[a11];[a0][a1][a2][a3][a4][a5][a6][a7][a8][a9][a10][a11]amerge=inputs=12[aout]" -map 0:v -map "[aout]" -c:a pcm_s24le -c:v copy output_file.mov

In your original code, only [a0] contains sound after mixing. You weren't, as you thought, mixing/combining the four mono tracks/channels into the same c0 of the 12-channel track. [a1]-[a11] were mixed from mono channels that didn't exist (anything other than c0) and that's why the channels they were mapped to were silent. It was hard to pick up on this initially because your test file contains 4 identical mono tracks, so one can't distinguish by ear if mono tracks were being mixed together or simply lost.

The issue with your code is shown in the tables below that compare the original with the new. Note that using [0:a] for audio track 0 is interpreted by FFmpeg as equivalent to [0:a:0]

Original Code

Command Input
Track
Input
Channel
Input Audio Note                   Mapped
Sound?
[0:a]pan=mono|c0=c0[a0] [0:a:0] c0 Mono track 0 - c0 has audio c0: Yes
[0:a]pan=mono|c0=c1[a1] [0:a:0] c1 Mono track 0 - c1 isn't valid c1:
[0:a]pan=mono|c0=c2[a2] [0:a:0] c2 Mono track 0 - c2 isn't valid c2:
[0:a]pan=mono|c0=c3[a3] [0:a:0] c3 Mono track 0 - c3 isn't valid c3:
[0:a]pan=mono|c0=c4[a4] [0:a:0] c4 Mono track 0 - c4 isn't valid c4:
[0:a]pan=mono|c0=c5[a5] [0:a:0] c5 Mono track 0 - c5 isn't valid c5:
[0:a]pan=mono|c0=c6[a6] [0:a:0] c6 Mono track 0 - c6 isn't valid c6:
[0:a]pan=mono|c0=c7[a7] [0:a:0] c7 Mono track 0 - c7 isn't valid c7:
[0:a]pan=mono|c0=c8[a8] [0:a:0] c8 Mono track 0 - c8 isn't valid c8:
[0:a]pan=mono|c0=c9[a9] [0:a:0] c9 Mono track 0 - c9 isn't valid c9:
[0:a]pan=mono|c0=c10[a10] [0:a:0] c10 Mono track 0 - c10 isn't valid c10:
[0:a]pan=mono|c0=c11[a11] [0:a:0] c11 Mono track 0 - c11 isn't valid c11:

New Code

Command Input
Track
Input
Channel
Input Audio Note                 Mapped
Sound?
[0:a:0]pan=mono|c0=c0[a0] [0:a:0] c0 Mono track 0 - c0 has audio c0: Yes
[0:a:1]pan=mono|c0=c0[a1] [0:a:1] c0 Mono track 1 - c0 has audio c1: Yes
[0:a:2]pan=mono|c0=c0[a2] [0:a:2] c0 Mono track 2 - c0 has audio c2: Yes
[0:a:3]pan=mono|c0=c0[a3] [0:a:3] c0 Mono track 3 - c0 has audio c3: Yes
[0:a:0]pan=mono|c0=c1[a4] [0:a:0] c1 Mono track 0 - c1 isn't valid c4:
[0:a:0]pan=mono|c0=c1[a5] [0:a:0] c1 Mono track 0 - c1 isn't valid c5:
[0:a:0]pan=mono|c0=c1[a6] [0:a:0] c1 Mono track 0 - c1 isn't valid c6:
[0:a:0]pan=mono|c0=c1[a7] [0:a:0] c1 Mono track 0 - c1 isn't valid c7:
[0:a:0]pan=mono|c0=c1[a8] [0:a:0] c1 Mono track 0 - c1 isn't valid c8:
[0:a:0]pan=mono|c0=c1[a9] [0:a:0] c1 Mono track 0 - c1 isn't valid c9:
[0:a:0]pan=mono|c0=c1[a10] [0:a:0] c1 Mono track 0 - c1 isn't valid c10:
[0:a:0]pan=mono|c0=c1[a11] [0:a:0] c1 Mono track 0 - c1 isn't valid c11:
0

I did some bash script, but I dont know how it helps you

#!/bin/bash
f="input 4.mp4"
if [ ! -f "$f" ]; then
ffmpeg -lavfi "
testsrc[v];
aevalsrc=sin(440*2*PI*t):s=8000[a];
aevalsrc=sin(880*2*PI*t)|sin(1760*2*PI*t):s=16000[b];
" -map "[v]" -map "[a]" -map "[b]" -t 5 "$f" -hide_banner -y
fi

AUD=($(ffprobe -v 0 -select_streams a -show_entries stream=channels -of csv=p=0 "$f"))
MRG=""
CNT=0
INP=0
for a in ${AUD[@]}; do
  echo "channels=$a"
  MRG+="[0:a:${CNT}]"
  ((CNT+=$a))
  ((INP++))
done
SIL=""
while (( $CNT < 12 )); do
  SIL+="aevalsrc=0[a${CNT}];"
  MRG+="[a${CNT}]"
  ((CNT++))
  ((INP++))
done

ffmpeg -i "$f" -filter_complex "
${SIL}
${MRG}amerge=inputs=${INP}[a]
" -map 0:v -map "[a]" -c:v copy -c:a pcm_s16le /tmp/out.mov -hide_banner -y

ffplay -f lavfi "amovie='/tmp/out.mov',asplit[a][out0];[a]showspectrum=s=540x1080:mode=separate:legend=1[out1]" -hide_banner -autoexit

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .