How to take audio channels from a file and create an audio file with the channels as tracks? - audio

I have an audio file with multiple channels. How can I create a new file which has multiple audio tracks instead?

Your question is a bit imprecise but I assume you mean, break out the channels into separate and distinct audio files that are then combined, end to end in a new file.
For example:
Take a 6 channel file and isolate Front Left, Centre and Front Right using map_channel.
ffmpeg -i 6_Channel_ID.wav -map_channel 0.0.0 F_left.wav
ffmpeg -i 6_Channel_ID.wav -map_channel 0.0.1 F_right.wav
ffmpeg -i 6_Channel_ID.wav -map_channel 0.0.2 Center.wav
Combine them using concat
ffmpeg -y -i F_left.wav -i Center.wav -i F_right.wav -filter_complex "[0][1][2]concat=n=3:v=0:a=1" LCR.wav
I'm sure there must be a way to roll this into a single filter_complex command, using something like the channelsplit command.

This worked for me:
ffmpeg -i in.wav -filter_complex '[a:0]channelsplit=channel_layout=5c[out0][out1][out2][out3][out4]' -ac 1 -map '[out0]' -map '[out1]' -map '[out2]' -map '[out3]' -map '[out4]' out.webm
Reference: https://ffmpeg.org/ffmpeg-filters.html#Examples-21

Related

How merge audio in video with outside audio using ffmpeg?

I have 2 files:
video_orginal.ts,
sound_outside.wav
video_orginal have own sound track. I wants to turn down the volume of the sound from video_orginal and next merge sound_outside.wav with sound in video_orginal to finally get a video with mixed audio. Now I execute 4 working commands:
ffmpeg -i video_orginal.ts -map 0:a -c copy sound_from_video.wav -map 0:v -c copy video_clean.ts --exteract audio and video
ffmpeg -i sound_from_video.wav -filter:a "volume=0.3" sound_from_video_quiet.wav --quiet sound
ffmpeg -i sound_from_video_quiet.wav -i sound_outside.wav -filter_complex amix=inputs=2:duration=longest sound_mixed.wav --merge sounds
ffmpeg -i video_clean.ts -i sound_mixed.wav -c copy video_final.mkv --final merge video and sound
It is possible to execute only one command which will do all these steps with as little encoding as possible?

ffmpeg extract all audio channels

Is there a way in ffmpeg to extract all audio channels giving each a separate name?
The problem is that I don't know in advance how many channels the input file is going to have.
This does splitting into two wav files:
ffmpeg -y -i input.wav -filter_complex
"[0:a]channelsplit=channel_layout=stereo[left][right]" -map "[left]"
left.wav -map "[right]" right.wav
What can be done if the input file contains 3, or 8 channels?
Ideally, I would like to have a way to convert Nchannels.mp4 into Nchannels_1.wav, Nchannels_2.wav, ..., Nchannels_N.wav.
You will have to do this in multiple steps.
Get number of channels with ffprobe:
ffprobe -v error -show_entries stream=channels,channel_layout -of default=nw=1 input.wav
channels=6
channel_layout=5.1
(Optional) Refer to ffmpeg -layouts to get channel names so you know what to name the outputs; as in the example below.
Build ffmpeg command using results from ffprobe:
ffmpeg -i input.wav -filter_complex "channelsplit=channel_layout=5.1[FL][FR][FC][LFE][BL][BR]" -map "[FL]" front_left.wav -map "[FR]" front_right.wav -map "[FC]" front_center.wav -map "[LFE]" low_frequency_effects.wav -map "[BL]" back_left.wav -map "[BR]" back_right.wav

How to extract specific audio track (track 2) from mp4 file using ffmpeg?

I am working on a mp4 file (36017P.mp4) in which I want to extract Track 2 -[English] using ffmpeg.
I tried with the following command on terminal but it seems to extract Track 1 - [English]:
ffmpeg -i 36017P.mp4 filename.mp3
Problem Statement:
I am wondering what changes I need to make in the ffmpeg command above so that it extract Track 2 -[English] from mp4 file.
The -map option will do what you want. Below in -map 0:a:1 the 0 refers to the first (and only) input file. a refers to the audio channels and the next number - 1 here - selects a specific audio stream, starting from 0:
ffmpeg -i 36017P.mp4 -map 0:a:0 filename1.mp3
ffmpeg -i 36017P.mp4 -map 0:a:1 filename2.mp3
ffmpeg -i 36017P.mp4 -map 0:a:2 filename3.mp3
ffmpeg -i 36017P.mp4 -map 0:a:3 filename4.mp3
For further details, see section 5.11 Advanced options in the ffmpeg docs.

audio mapping in ffmpeg

I have a video file with audio in only one channel, left.
I'd like to use the ffmpeg -map_channel option to map that audio so that it appears in both the L&R channels.
what would the ffmpeg command for that look like?
ffmpeg -i INPUT.mov -c:v copy -c:a copy -map_channel 0.1.0 -map_channel 0.1.0 OUTPUT.mov
isn't working. The audio is still in the left channel only.
Remove -c:a copy. -map_channel is just another way of using the pan filter, but you can't stream copy (-c:a copy) and filter at the same time.
If you want to use pan instead:
ffmpeg -i input -filter_complex "pan=stereo|FL=c0:FR=c0" -c:v copy output

ffmpeg merge silent video with another video+audio

I want to create, in a single command, a video from 3 sources:
a silent background video;
a smaller video to be overlayed (same length of 1), KEEPING its AUDIO;
a PNG logo to be overlayed
I can create the video but cannot get the audio track. I don't understand if -vf is supposed to work in this case. This is what I've tried to do :
ffmpeg.exe -y -i MASTER_SILENT_VIDEO.mp4 -vf "movie=SMALLER_VIDEO_WITH_AUDIO.flv, scale=320:-1[inner];movie=MY_LOGO.png[inner2]; [in][inner] overlay=800:480,amerge [step1]; [step1][inner2] overlay=30:30 [out]" completed.mp4
The "amerge" filter should do the audio merging job, but of course it doesn't work. I've found similar questions involving -map or filtergraph but they refer to mixing a video source and an audio source; I tried several filtergraph examples without success. Any idea?
overlay one video over other using audio from one input
Use -filter_complex, eliminate the movie source filters, and explicitly define output streams with -map:
ffmpeg -y -i main.mp4 -i overlay_with_audio.flv -i logo.png -filter_complex
"[1:v]scale=320:-1[scaled];
[0:v][scaled]overlay=800:480[bg];
[bg][2:v]overlay=30:30,format=yuv420p[video]"
-map "[video]" -map 1:a -movflags +faststart
output.mp4
You may have to provide additional options to the overlay filters depending on the length of the inputs and how you want overlay to react, but because you did not provide the complete console output from your command I had to make a generic, less efficient, and possibly incorrect example.
overlay one video over other merging audio from both inputs
ffmpeg -y -i main.mp4 -i overlay_with_audio.flv -i logo.png -filter_complex
"[1:v]scale=320:-1[scaled];
[0:v][scaled]overlay=800:480[bg];
[bg][2:v]overlay=30:30,format=yuv420p[video];
[0:a][1:a]amerge=inputs=2[audio]"
-map "[video]" -map "[audio]" -ac 2 -movflags +faststart
output.mp4
I'm assuming both inputs are stereo and that you want a stereo output. Also see FFmpeg Wiki: Audio channel Manipulation - 2 × stereo → stereo.

Resources