Charlih Chen

My Photo
Name:
Location: Cupertino, California, United States

I'm orignal from Taiwan.

Sunday, January 15, 2023

Perfect KTV track#2 mixing ffmpeg command

 Here is the ffmpeg command to create Karaoke video file with vocal & music on FL(Left channel) and No Vocal music on FR(Right channel):

 ffmpeg -i KTV_MVwithVocal.mp4 -i NoVocal.wav -map 0:v -filter_complex "[0:a][1:a]amerge=inputs=2,pan=stereo|c0<c0+c1|c1<c2+c3[a]" -map "[a]" PerfectKTV.mp4

ffmpeg -i KTV_MVwithVocal.mp4 -i NoVocal.mp3 -map 0:v -filter_complex "[0:a][1:a]amerge=inputs=2,pan=stereo|c0<c0+c1|c1<c2+c3[a]" -map "[a]" PerfectKTV.mkv

To swap from above NoVocal channel to Vocal chhanel by using the folliwng command:

 ffmpeg -i KTV_MVwithVocal.mp4 -i NoVocal.wav -map 0:v -filter_complex "[1:a][0:a]amerge=inputs=2,pan=stereo|c0<c0+c1|c1<c2+c3[a]" -map "[a]" PerfectKTV.mp4

ffmpeg -i KTV_MVwithVocal.mp4 -i NoVocal.mp3 -map 0:v -filter_complex "[1:a][0:a]amerge=inputs=2,pan=stereo|c0<c0+c1|c1<c2+c3[a]" -map "[a]" PerfectKTV.mkv

Source: https://trac.ffmpeg.org/wiki/AudioChannelManipulation#Remapchannels

Note: To save .mkv file size by MKVToolNix. It is better to convert from .wav to .m4a while doing 2nd channel multiplexing.

Others ffmpeg commands:

1. Output with video only:
ffmpeg -i Input.mp4 -vcodec copy -an OutputNoAudio.mp4
ffmpeg -i Input.mp4 -an -c:a copy OutputNoAudio.mp4

2. Output with audio only:
ffmpeg -i Input.mp4 -nv -c:a copy outputNoVideo.mp4

3. Extract audio to wave format:
ffmpeg -i Input.mp4 -map 0:a Output.wav

4. Eatract audio to m4a or wav format:
ffmpeg -i Input.mp4 -map 0:a Output.m4a
ffmpeg -i Input.mp4 -map 0:a Output.wav

5. Merge mp4 with audio:
ffmpeg -i OutputNoAudio.mp4 -i output.m4a -c:v copy -c:a copy merged.mp4

6. Extract 2nd track audio:
ffmpeg -i Input.mkv -map 0:2 Output.m4a

https://stackoverflow.com/questions/11779490/how-to-add-a-new-audio-not-mixing-into-a-video-using-ffmpeg