Ffmpeg Audio Stereo to Mono using only left channel
I use the following command to extract video parts of an '.MTS' record (video).
ffmpeg -i 00402.MTS -s 1280x720 -r 25 -ss 0:00:05.38608 -vcodec libxvid -qscale:v 2 -acodec ac3 -ar 48000 -ab 256k -t 0:00:06.613917 m001_mono.avi
The audio stream is stereo but the right channel only recorded noise. Here are the input informations:
Stream #0.0[0x1011]: Video: h264 (High), yuv420p, 1440x1080 [PAR 4:3 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 50 tbc
Stream #0.1[0x1100]: Audio: ac3, 48000 Hz, stereo, s16, 256 kb/s
I would like the output's audio stream to be mono (with the original left channel only). I already made tests using '-ac 1' option, but in this case the two channels are merged and I lose ~6dB of gain.
What option should I use to discard right channel and output with mono audio stream ?
EDIT: ffmpeg output with map_channel option
/home/eric/buildsys/ffmpeg-2.0.1/ffmpeg -i 00402.MTS -s 1280x720 -r 25 -ss 0:00:05.38608 -vcodec libxvid -qscale:v 2 -acodec ac3 -ar 48000 -ab 256k -t 0:00:06.61391 -map_channel -1 -map_channel 0.1.0 m001_test.avi
ffmpeg version 2.0.1 Copyright (c) 2000-2013 the FFmpeg developers
built on Sep 24 2013 05:31:18 with gcc 4.8 (Debian 4.8.1-10)
configuration: --extra-cflags=-I../static/include --extra-ldflags='-L../static/lib -static' --enable-gpl --enable-version3 --enable-static --disable-shared --disable-debug --enable-runtime-cpudetect --enable-libmp3lame --enable-libx264 --enable-libspeex --enable-libvorbis --enable-libvpx --enable-libfreetype --enable-libxvid --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-gray --enable-libopenjpeg --disable-ffserver
libavutil 52. 38.100 / 52. 38.100
libavcodec 55. 18.102 / 55. 18.102
libavformat 55. 12.100 / 55. 12.100
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 79.101 / 3. 79.101
libswscale 2. 3.100 / 2. 3.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 3.100 / 52. 3.100
Input #0, mpegts, from '00402.MTS':
Duration: 00:01:18.25, start: 0.455556, bitrate: 12217 kb/s
Program 1
Stream #0:0[0x1011]: Video: h264 (High) (HDMV / 0x564D4448), yuv420p, 1440x1080 [SAR 4:3 DAR 16:9], 25 fps, 50 tbr, 90k tbn, 50 tbc
Stream #0:1[0x1100]: Audio: ac3 (AC-3 / 0x332D4341), 48000 Hz, stereo, fltp, 256 kb/s
File 'm001_test.avi' already exists. Overwrite ? [y/N] y
-map_channel is forwarded to lavfi similarly to -af pan=0x3:c1=c0.
[pan @ 0x248a560] This syntax is deprecated. Use '|' to separate the list items.
[pan @ 0x248a560] Pure channel mapping detected: M 0
Output #0, avi, to 'm001_test.avi':
Metadata:
ISFT : Lavf55.12.100
Stream #0:0: Video: mpeg4 (libxvid) (xvid / 0x64697678), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 25 tbn, 25 tbc
Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, fltp, 256 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> libxvid)
Stream #0:1 -> #0:1 (ac3 -> ac3)
Press [q] to stop, [?] for help
frame= 166 fps= 23 q=2.0 Lsize= 4012kB time=00:00:06.64 bitrate=4950.3kbits/s
video:3787kB audio:207kB subtitle:0 global headers:0kB muxing overhead 0.464949%
Solution 1:
You can modify a video file directly without having to re-encode the video stream. However the audio stream will have to be re-encoded.
Left channel to mono:
ffmpeg -i video.mp4 -map_channel 0.1.0 -c:v copy mono.mp4
Left channel to stereo:
ffmpeg -i video.mp4 -map_channel 0.1.0 -map_channel 0.1.0 -c:v copy stereo.mp4
If you want to use the right channel, write 0.1.1
instead of 0.1.0
.
Working with ffmpeg version 3.1.3.
Solution 2:
The following is a confirmed working example with ffmpeg version 2.4.1-tessus:
ffmpeg -i stereo.wav -map_channel 0.0.0 left.wav
More info on FFMPEG's Audio Channel Page.
Solution 3:
Using the -map_channel
option as suggested here did not work for me on 4.3.1, using a video from my mobile phone:
mapchan: stream #0.1 is not an audio stream
Solution (working with ffmpeg 4.3.1)
The ffmpeg wiki article Manipulating audio channels recommends using the pan
audio filter as the shortest option for this:
ffmpeg -i video.mp4 -af "pan=mono|c0=FL" mono.mp4
To get the right channel included as mono, replace FL
with FR
.
Solution 4:
Manipulating audio channels with ffmpeg
Chapter Mute a channel
This example will mute the first channel (the left channel) but keep the second channel as is:
ffmpeg -i stereo.wav -map_channel -1 -map_channel 0.0.1 output.wav
in your case its need to mute right channel. right?
Solution 5:
I solved the problem using the last version of Ffmpeg (2.0.1). The following command line makes the work:
/home/eric/buildsys/ffmpeg-2.0.1/ffmpeg -i 00402.MTS -s 1280x720 -ss 0:00:05.38608 -vcodec libxvid -qscale:v 2 -acodec ac3 -ar 48000 -ab 256k -t 0:00:06.61391 -af pan=1:c0=c0 m001_mono.avi
Btw, this post was very instructive!