I have an mp4 video file with multiple audio tracks. I would like to strip away the rest of the tracks and keep just one. How do I do this?
-
related: https://stackoverflow.com/questions/38161697/how-to-remove-one-track-from-video-file-using-ffmpeg/38162168#38162168 – Ciro Santilli OurBigBook.com Sep 08 '19 at 04:18
-
Here's a Gist of what I did and works perfectly for me -> https://gist.github.com/carlosveucv/aab4f695373965deed4334f6b40e50b1 – carlosveucv Apr 01 '21 at 11:27
10 Answers
First run ffmpeg -i file.mp4
to see which streams exists in your file. You should see something like this:
Stream #0.0: Video: mpeg4, yuv420p, 720x304 [PAR 1:1 DAR 45:19], 23.98 tbr, 23.98 tbn, 23.98 tbc
Stream #0.1: Audio: ac3, 48000 Hz, 5.1, s16, 384 kb/s
Stream #0.2: Audio: ac3, 48000 Hz, 5.1, s16, 384 kb/s
Then run ffmpeg -i file.mp4 -map 0:0 -map 0:2 -acodec copy -vcodec copy new_file.mp4
to copy video stream and 2nd audio stream to new_file.mp4
.

- 6,737
-
4On Windows this command gave the error
Option map (set input stream mapping) cannot be applied to input file file.mp4 new_file.mp4 -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to.
: to fix it simply change the order of the arguments thusly:ffmpeg -i file.mp4 -map 0:0 -map 0:2 -acodec copy -vcodec copy new_file.mp4
– MrLore Sep 29 '13 at 11:47 -
-
1
-
1
-
3You can use the more generic option
-c copy
to have identical streams for audio, video but also subtitles:ffmpeg -i input.mp4 -map 0:0 -map 0:2 -c copy output.mp4
. – Futal Sep 09 '17 at 08:01 -
ffmpeg
complains about not having an output file when used only with the input option.ffprobe
is made for getting info about files. – phip Jul 26 '20 at 21:35
Related issue—removing all audio tracks from an mp4 file can be done thus:
ffmpeg -i input_file.mp4 -vcodec copy -an output_file.mp4

- 1,811
-
1This gives me the error
The encoder 'aac' is experimental but experimental codecs are not enabled, add '-strict -2' if you want to use it.
But I added those flags and it's still the same...? – poshaughnessy Apr 24 '17 at 10:34 -
See also: https://superuser.com/questions/268985/remove-audio-from-video-file-with-ffmpeg – Ciro Santilli OurBigBook.com Sep 08 '19 at 04:16
-
Re poshaughnessy's comment: there seems to be some information here: https://stackoverflow.com/questions/32931685/the-encoder-aac-is-experimental-but-experimental-codecs-are-not-enabled The discussion suggests recent versions of ffmpeg do not experience the "aac experimental" problem. As a general rule, it helps to diagnose your problem if you state the version of the software you're using and the exact syntax of the command (after you added the flags) that gave the error (cf. freeseek's answer loc. cit.). In this specific case, video information from the input file may also be helpful. – Greg Marks Sep 10 '19 at 15:50
Identify stream numbers:
$ ffmpeg -i in.mp4
...
Stream #0:0: Video: ...
Stream #0:1: Audio: ...
Stream #0:2: Audio: ...
Use -map _file_:_stream_
to select which streams to process and output
$ ffmpeg -i in.mp4 -map 0:0 -map 0:2 -vcodec copy -acodec copy out.mp4
I used Avidemux (GUI) several times, and ffmpeg (console).
In Avidemux, you choose "Audio" -> "Select tracks" in the main menu; then save you video as a new file.
Interestingly enough, in some cases Avidemux produced "better" output than ffmpeg.
just in case, Avidemux and ffmpeg are in the standard Fedora Linux repository. (I'm sure they are standard in other Linux flavors, too.)

- 281
You could try avidemux
which handles only one audio file internally (and therefore forces you to select one specific track). I've never tried it with .mp4 but it works with other formats.

- 35,944
- 12
- 67
- 51
-
Doesn't work so well. Maybe it's a bug, but the audio comes back mangled, though it does do the job (remove the rest of the audio tracks). – tshepang Jan 25 '11 at 20:32
-vn
or -an
will remove all the video or audio tracks. Supplying -vn -acodec copy
will remove video; -an -vcodec copy
will remove all audio.
-vcodec copy
specifies that ffmpeg should do a straight copy the existing video track (and not do any processing/encoding of it). If you don't specify it, then it will still work but ffmpeg may re-encode the existing video track and the operation will use more CPU and may take considerably longer.

- 103

- 219
- 2
- 8
Using avidemux in command-line.
(In Avidemux GUI, as decribed in https://unix.stackexchange.com/a/85834/4319 above, you simply select/unselect the audio tracks, and save the file. (Everything is copied to the new AVI.))
I've looked at what kind of projects are saved as SpiderMonkey or TinyPy projetcs for my actions, and it turned out that the SpiderMonkey (JavaScript) project lacks the audio track selection actions which I needed, but the TinyPy (Python) project did have them.
I removed everything unrelated (a dozen of unneeded lines), and this is what I got in my some_series.py
:
#PY <- Needed to identify #
#--automatically built--
adm = Avidemux()
adm.audioClearTracks()
adm.audioAddTrack(1)
It leaves track 1, but drops track 0.
Then I ran a batch conversion of many files with a command like this one:
for f in *.avi; do avidemux3_cli --nogui --load "$f" --run ../some_series.py --save ../some_series/"${f%%.rus.eng.avi}".eng.avi --quit; done
It copies everything, but drops all but the needed audio track.
The way to run avidemux from command-line was learned by me from https://www.avidemux.org/admWiki/doku.php?id=tutorial:batch_processing, although they do not mention the Python scripts, only the JS ones (which didn't work for me).

- 15,462
If you don't mind the program being GUI, with Blender's video editor you can do that and much much more.

- 4,015
The ffmpeg
program has been replaced by avconv
. avconv
has very similar usage to ffmpeg
, thus all the commands in this post can be something like:
avconv <old ffpmeg command line options>
Follow this link to install avconv
if you're on Ubuntu.

- 171