INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: ffmpeg : How to mux 2 Mono Audio Streams to 1 Stereo Stream?  (Read 5206 times)

jmone

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 14267
  • I won! I won!
ffmpeg : How to mux 2 Mono Audio Streams to 1 Stereo Stream?
« on: February 24, 2018, 03:57:32 pm »

I have a new Canon XF400 and when recording in LPCM mode it creates a MP4 with 5 Streams (1 x X264, 4 x LPCM, 1 x Time Code). 

I'm looking for a simple way of batch re-muxing the output so that the separate Left and Right Mono Streams are mapped to a single Stereo Stream (with Left and Right channels).  I found this explanation over at ffmpeg but my scenario is actually as attached and I'm hoping someone with better ffmpeg skills than me can decipher the command line required!

Also happy if there is some other utility that can batch convert a bunch of files one step that would be great!
Logged
JRiver CEO Elect

jmone

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 14267
  • I won! I won!
Re: ffmpeg : How to mux 2 Mono Audio Streams to 1 Stereo Stream?
« Reply #1 on: February 24, 2018, 04:06:44 pm »

The issue is in the raw form these files will just play with one channel of audio in MC as they are just single mono streams.  You can switch to another mono stream but then you just get that one.

Also here is the Media Info of the file:
Code: [Select]
General
Complete name                            : M:\Media\Video\Test\MVI_0017.MP4
Format                                   : MPEG-4
Format profile                           : Base Media / Version 2
Codec ID                                 : mp42 (mp42/avc1/CAEP)
File size                                : 312 MiB
Duration                                 : 17 s 280 ms
Overall bit rate                         : 151 Mb/s
Encoded date                             : UTC 2018-02-24 06:44:12
Tagged date                              : UTC 2018-02-24 06:44:12

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : High@L5.2
Format settings                          : 2 Ref Frames
Format settings, CABAC                   : No
Format settings, RefFrames               : 2 frames
Format settings, GOP                     : M=3, N=24
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 17 s 280 ms
Bit rate                                 : 148 Mb/s
Width                                    : 3 840 pixels
Height                                   : 2 160 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 50.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.357
Stream size                              : 305 MiB (98%)
Language                                 : English
Encoded date                             : UTC 2018-02-24 06:44:12
Tagged date                              : UTC 2018-02-24 06:44:12
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709

Audio #1
ID                                       : 2
Format                                   : PCM
Format settings                          : Big / Signed
Codec ID                                 : twos
Duration                                 : 17 s 280 ms
Bit rate mode                            : Constant
Bit rate                                 : 768 kb/s
Channel(s)                               : 1 channel
Sampling rate                            : 48.0 kHz
Bit depth                                : 16 bits
Stream size                              : 1.58 MiB (1%)
Language                                 : English
Encoded date                             : UTC 2018-02-24 06:44:12
Tagged date                              : UTC 2018-02-24 06:44:12

Audio #2
ID                                       : 3
Format                                   : PCM
Format settings                          : Big / Signed
Codec ID                                 : twos
Duration                                 : 17 s 280 ms
Bit rate mode                            : Constant
Bit rate                                 : 768 kb/s
Channel(s)                               : 1 channel
Sampling rate                            : 48.0 kHz
Bit depth                                : 16 bits
Stream size                              : 1.58 MiB (1%)
Language                                 : English
Encoded date                             : UTC 2018-02-24 06:44:12
Tagged date                              : UTC 2018-02-24 06:44:12

Audio #3
ID                                       : 4
Format                                   : PCM
Format settings                          : Big / Signed
Codec ID                                 : twos
Duration                                 : 17 s 280 ms
Bit rate mode                            : Constant
Bit rate                                 : 768 kb/s
Channel(s)                               : 1 channel
Sampling rate                            : 48.0 kHz
Bit depth                                : 16 bits
Stream size                              : 1.58 MiB (1%)
Language                                 : English
Encoded date                             : UTC 2018-02-24 06:44:12
Tagged date                              : UTC 2018-02-24 06:44:12

Audio #4
ID                                       : 5
Format                                   : PCM
Format settings                          : Big / Signed
Codec ID                                 : twos
Duration                                 : 17 s 280 ms
Bit rate mode                            : Constant
Bit rate                                 : 768 kb/s
Channel(s)                               : 1 channel
Sampling rate                            : 48.0 kHz
Bit depth                                : 16 bits
Stream size                              : 1.58 MiB (1%)
Language                                 : English
Encoded date                             : UTC 2018-02-24 06:44:12
Tagged date                              : UTC 2018-02-24 06:44:12

Other
ID                                       : 6
Type                                     : Time code
Format                                   : QuickTime TC
Duration                                 : 17 s 280 ms
Time code of first frame                 : 00:02:40:16
Time code, striped                       : Yes
Language                                 : English
Encoded date                             : UTC 2018-02-24 06:44:12
Tagged date                              : UTC 2018-02-24 06:44:12
Bit rate mode                            : CBR

Logged
JRiver CEO Elect

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3961
Re: ffmpeg : How to mux 2 Mono Audio Streams to 1 Stereo Stream?
« Reply #2 on: February 24, 2018, 04:57:03 pm »

It sounds like this example - https://ffmpeg.org/ffmpeg-filters.html#Examples-8

With more description -https://stackoverflow.com/questions/43219810/ffmpeg-convert-video-file-with-8-audio-channels-to-multichannel-wav/43220868
Logged

jmone

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 14267
  • I won! I won!
Re: ffmpeg : How to mux 2 Mono Audio Streams to 1 Stereo Stream?
« Reply #3 on: February 24, 2018, 06:20:35 pm »

Thanks - This works but it re-encodes the video and drops the meta data (not sure I need the meta data anyway):
ffmpeg -i "M:\Media\Video\Test\CanonXF400 4K LPCM.MP4" -filter_complex "[0:1][0:2] amerge=inputs=2" -c:a pcm_s16le output.mkv

I'll keep playing to see how to not re-encode...

Logged
JRiver CEO Elect

jmone

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 14267
  • I won! I won!
Re: ffmpeg : How to mux 2 Mono Audio Streams to 1 Stereo Stream?
« Reply #4 on: February 24, 2018, 06:33:13 pm »

 ;D - I "think" this is right, need to test but thanks for the tip Matt

ffmpeg -i "M:\Media\Video\Test\CanonXF400 4K LPCM.MP4" -map 0:0 -c:v copy -filter_complex "[0:1][0:2] amerge=inputs=2" -c:a pcm_s16le output.mkv
Logged
JRiver CEO Elect

mattkhan

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3961
Re: ffmpeg : How to mux 2 Mono Audio Streams to 1 Stereo Stream?
« Reply #5 on: February 24, 2018, 06:35:52 pm »

I was about to say I think you need -c:v copy :)
Logged

jmone

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 14267
  • I won! I won!
Re: ffmpeg : How to mux 2 Mono Audio Streams to 1 Stereo Stream?
« Reply #6 on: February 24, 2018, 06:50:15 pm »

Got to do a bit of testing to see I've mapped the audio the the correct L/R!
Logged
JRiver CEO Elect

jmone

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 14267
  • I won! I won!
Re: ffmpeg : How to mux 2 Mono Audio Streams to 1 Stereo Stream?
« Reply #7 on: February 24, 2018, 07:48:47 pm »

Yup - all good!  Made a little batchfile that will do a whole directory at a time.  Super quick.  Thanks again.
Logged
JRiver CEO Elect
Pages: [1]   Go Up