Answers.Body: <p>FFmpeg assumes that the input's 5.1 channel mapping is the same as the one it uses. To correct that, use the channelmap filter to remap, add:</p>
  
  <pre><code>-af "channelmap=4|0|1|2|3|5:5.1"
  </code></pre>
  
  <p>(I based it off the channel labels on the right in your images)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T00:28:43.320Z
Answers.Text: I found working for my purposes: -af "channelmap=0|1|4|5|2|3:5.1"
Answers.UserDisplayName: user3450548
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T00:32:46.240Z
Answers.Text: Just a question, what I wonder is.. Why with ffmpeg I have to specify the channel order manually when instead a player like VLC that is based on libavcodec is able to determine it automatically ? Shouldn't ffmpeg do the same ? I can understand specifying manually the 5.1 channel flavour for the output but not for the input..
Answers.UserDisplayName: user3450548
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T06:08:39.577Z
Answers.Text: The channel layout is signaled by the demuxer to the decoder and VLC uses its own. In ffmpeg, the QT demuxer does recognize the layout in your MOV but ffmpeg internally has a single designation for 5.1, so it does not reorder when sending to encoder.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-04T11:07:07.000Z
Answers.Text: I see, this makes sense. There's no any kind of way to auto assign them so? Or at least a command with ffprobe to read the internal channel layout so that I could make a multi pass script ?
Answers.UserDisplayName: user3450548
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-03T20:03:26.803Z
Answers.LastActivityDate: 2018-01-03T20:03:26.803Z
Answers.UserDisplayName: Gyan
Body: <p>I need to transcode some high res videos (prores or dnxhd files with 5.1 uncompressed 48kHz audio in MOV container) to their low res h264 with AAC keeping the audio still in 5.1 preserving their channel mapping.</p>
  
  <p>In order to do so I tried to use this command:</p>
  
  <pre><code>ffmpeg -y -i input.mov -c:v libx264 -preset ultrafast -b:v 10000k -c:a libfdk_aac -afterburner 1 -cutoff 20000 -filter:v "scale=-1:720" output.mp4
  </code></pre>
  
  <p>The version I'm using is <strong><code>ffmpeg version N-87584-g47d6b02f6c-Reino</code></strong> a pretty new one.</p>
  
  <p>What happens is that even if video processing is ok, for the audio part my channels are mapped incorrectly.. to better explain what happens I made a screenshot of before and after waveforms in Adobe Audition.</p>
  
  <p>These are the waveform of the <strong>input</strong> file:</p>
  
  <p><a href="https://i.sstatic.net/7tkfk.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/7tkfk.png" alt="waveforms in my origin video"></a></p>
  
  <p>These instead are the waveforms of the <strong>transcoded</strong> file:</p>
  
  <p><a href="https://i.sstatic.net/4FwZT.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4FwZT.png" alt="waveforms changed after transcoding"></a></p>
  
  <p>Again let me post the ffprobe parts related to the audio:</p>
  
  <p>input file:</p>
  
  <pre><code>Stream #0:1(eng): Audio: pcm_s24le (lpcm / 0x6D63706C), 48000 Hz, 5.1, s32 (24 bit), 6912 kb/s (default)
  Metadata:
    creation_time   : 2018-01-02T09:48:58.000000Z
    handler_name    : Apple Alias Data Handler
    timecode        : 00:00:00:00
  </code></pre>
  
  <p>transcoded file:</p>
  
  <pre><code>Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 488 kb/s (default)
  Metadata:
    handler_name    : SoundHandler
  </code></pre>
  
  <p>and for finish MediaInfo Lite</p>
  
  <p>original file:</p>
  
  <pre><code>Audio
  ID                          : 2
  Format                      : PCM
  Format settings             : Little / Signed
  Format settings, Endianness : Little
  Format settings, Sign       : Signed
  Codec ID                    : lpcm
  Duration                    : 1 h 30 min
  Bit rate mode               : Constant
  Bit rate                    : 6 912 kb/s
  Channel(s)                  : 6 channels
  Channel positions           : Front: L C R, Back: L R, LFE
  Sampling rate               : 48.0 kHz
  Bit depth                   : 24 bits
  Stream size                 : 4.35 GiB (5%)
  Language                    : English
  Encoded date                : UTC 2018-01-02 09:48:58
  Tagged date                 : UTC 2018-01-02 10:16:46
  </code></pre>
  
  <p>transcoded file:</p>
  
  <pre><code>Audio
  ID                          : 2
  Format                      : AAC
  Format/Info                 : Advanced Audio Codec
  Format profile              : LC
  Codec ID                    : mp4a-40-2
  Duration                    : 1 h 30 min
  Duration_LastFrame          : -8 ms
  Bit rate mode               : Constant
  Bit rate                    : 489 kb/s
  Channel(s)                  : 2 channels
  Channel(s)_Original         : 6 channels
  Channel positions           : Front: L C R, Side: L R, LFE
  Sampling rate               : 48.0 kHz
  Frame rate                  : 46.875 FPS (1024 SPF)
  Compression mode            : Lossy
  Stream size                 : 315 MiB (5%)
  Language                    : English
  Default                     : Yes
  Alternate group             : 1
  </code></pre>
  
  <p>If you play the mp4 file with VLC you clearly hear that something is swapped badly.</p>
  
  <p>I'm open to a solution ;)</p>
  
Tags: <ffmpeg><audio><conversion><transcoding>
Title: Transcode 5.1 audio in ffmpeg leads to incorrect audio mapping in output
UserDisplayName: user3450548
ThreadText: # Transcode 5.1 audio in ffmpeg leads to incorrect audio mapping in output
  
  (Asked by: username_0 on 2018-01-03)
  
  I need to transcode some high res videos (prores or dnxhd files with 5.1 uncompressed 48kHz audio in MOV container) to their low res h264 with AAC keeping the audio still in 5.1 preserving their channel mapping.
  
  In order to do so I tried to use this command:
  
  ```
  ffmpeg -y -i input.mov -c:v libx264 -preset ultrafast -b:v 10000k -c:a libfdk_aac -afterburner 1 -cutoff 20000 -filter:v "scale=-1:720" output.mp4
  
  ```
  
  The version I'm using is **`ffmpeg version N-87584-g47d6b02f6c-Reino`** a pretty new one.
  
  What happens is that even if video processing is ok, for the audio part my channels are mapped incorrectly.. to better explain what happens I made a screenshot of before and after waveforms in Adobe Audition.
  
  These are the waveform of the **input** file:
  
  [![waveforms in my origin video](https://i.sstatic.net/7tkfk.png)](https://i.sstatic.net/7tkfk.png)
  
  These instead are the waveforms of the **transcoded** file:
  
  [![waveforms changed after transcoding](https://i.sstatic.net/4FwZT.png)](https://i.sstatic.net/4FwZT.png)
  
  Again let me post the ffprobe parts related to the audio:
  
  input file:
  
  ```
  Stream #0:1(eng): Audio: pcm_s24le (lpcm / 0x6D63706C), 48000 Hz, 5.1, s32 (24 bit), 6912 kb/s (default)
  Metadata:
    creation_time   : 2018-01-02T09:48:58.000000Z
    handler_name    : Apple Alias Data Handler
    timecode        : 00:00:00:00
  
  ```
  
  transcoded file:
  
  ```
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 488 kb/s (default)
  Metadata:
    handler_name    : SoundHandler
  
  ```
  
  and for finish MediaInfo Lite
  
  original file:
  
  ```
  Audio
  ID                          : 2
  Format                      : PCM
  Format settings             : Little / Signed
  Format settings, Endianness : Little
  Format settings, Sign       : Signed
  Codec ID                    : lpcm
  Duration                    : 1 h 30 min
  Bit rate mode               : Constant
  Bit rate                    : 6 912 kb/s
  Channel(s)                  : 6 channels
  Channel positions           : Front: L C R, Back: L R, LFE
  Sampling rate               : 48.0 kHz
  Bit depth                   : 24 bits
  Stream size                 : 4.35 GiB (5%)
  Language                    : English
  Encoded date                : UTC 2018-01-02 09:48:58
  Tagged date                 : UTC 2018-01-02 10:16:46
  
  ```
  
  transcoded file:
  
  ```
  Audio
  ID                          : 2
  Format                      : AAC
  Format/Info                 : Advanced Audio Codec
  Format profile              : LC
  Codec ID                    : mp4a-40-2
  Duration                    : 1 h 30 min
  Duration_LastFrame          : -8 ms
  Bit rate mode               : Constant
  Bit rate                    : 489 kb/s
  Channel(s)                  : 2 channels
  Channel(s)_Original         : 6 channels
  Channel positions           : Front: L C R, Side: L R, LFE
  Sampling rate               : 48.0 kHz
  Frame rate                  : 46.875 FPS (1024 SPF)
  Compression mode            : Lossy
  Stream size                 : 315 MiB (5%)
  Language                    : English
  Default                     : Yes
  Alternate group             : 1
  
  ```
  
  If you play the mp4 file with VLC you clearly hear that something is swapped badly.
  
  I'm open to a solution ;)
  
  **Tags:** ffmpeg, audio, conversion, transcoding
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-01-03. Score: 3 | Accepted answer
  
  FFmpeg assumes that the input's 5.1 channel mapping is the same as the one it uses. To correct that, use the channelmap filter to remap, add:
  
  ```
  -af "channelmap=4|0|1|2|3|5:5.1"
  
  ```
  
  (I based it off the channel labels on the right in your images)
  
  > **Comments:**
  > **username_0**: I found working for my purposes: -af "channelmap=0|1|4|5|2|3:5.1"  
  > **username_0**: Just a question, what I wonder is.. Why with ffmpeg I have to specify the channel order manually when instead a player like VLC that is based on libavcodec is able to determine it automatically ? Shouldn't ffmpeg do the same ? I can understand specifying manually the 5.1 channel flavour for the output but not for the input..  
  > **username_1**: The channel layout is signaled by the demuxer to the decoder and VLC uses its own. In ffmpeg, the QT demuxer does recognize the layout in your MOV but ffmpeg internally has a single designation for 5.1, so it does not reorder when sending to encoder.  
  > **username_0**: I see, this makes sense. There's no any kind of way to auto assign them so? Or at least a command with ffprobe to read the internal channel layout so that I could make a multi pass script ?  
  
  ---
  
  