11

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

Here is the streaming o/p:

ffmpeg version 4.0 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7.3.0 (GCC)
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --e
nable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libblur
ay --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-
libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enab
le-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-li
bvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --en
able-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-
libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enabl
e-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enabl
e-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enab
le-dxva2 --enable-avisynth
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '36017P.mp4':
  Metadata:
    major_brand     : M4V
    minor_version   : 1
    compatible_brands: M4V mp42isom
    creation_time   : 2019-04-30T03:09:22.000000Z
  Duration: 00:29:29.94, start: 0.000000, bitrate: 2509 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv), 960x5
40 [SAR 1:1 DAR 16:9], 1998 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (defa
ult)
    Metadata:
      creation_time   : 2019-04-30T03:09:22.000000Z
      handler_name    : AliasHandler
      encoder         : H264
      timecode        : 22:30:00;02
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, flt
p, 125 kb/s (default)
    Metadata:
      creation_time   : 2019-04-30T03:09:22.000000Z
      handler_name    : AliasHandler
    Stream #0:2(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, flt
p, 125 kb/s (default)
    Metadata:
      creation_time   : 2019-04-30T03:09:22.000000Z
      handler_name    : AliasHandler
    Stream #0:3(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, flt
p, 125 kb/s (default)
    Metadata:
      creation_time   : 2019-04-30T03:09:22.000000Z
      handler_name    : AliasHandler
    Stream #0:4(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, flt
p, 125 kb/s (default)
    Metadata:
      creation_time   : 2019-04-30T03:09:22.000000Z
      handler_name    : AliasHandler
    Stream #0:5(eng): Data: none (tmcd / 0x64636D74) (default)
    Metadata:
      creation_time   : 2019-04-30T03:09:22.000000Z
      handler_name    : AliasHandler
      timecode        : 22:30:00;02
Stream mapping:
  Stream #0:2 -> #0:0 (aac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'new_english.mp3':
  Metadata:
    major_brand     : M4V
    minor_version   : 1
    compatible_brands: M4V mp42isom
    TSSE            : Lavf58.12.100
    Stream #0:0(eng): Audio: mp3 (libmp3lame), 48000 Hz, stereo, fltp (default)
    Metadata:
      creation_time   : 2019-04-30T03:09:22.000000Z
      handler_name    : AliasHandler
      encoder         : Lavc58.18.100 libmp3lame
size=   27656kB time=00:29:29.95 bitrate= 128.0kbits/s speed=19.7x
video:0kB audio:27656kB subtitle:0kB other streams:0kB global headers:0kB muxing
 overhead: 0.001179%
0

1 Answer 1

17

You can use the -map option to choose specific streams. To get a list of the available streams, run ffmpeg -i INPUT_FILE.EXT (Do not forget -i!), which gives e.g.:

…
Input #0, EXT, from 'INPUT_FILE.EXT':
  Metadata:
    encoder         : VirtualDubMod 1.5.10.2 (build 2542/release)
  Duration: 01:35:35.88, start: 0.000000, bitrate: 1029 kb/s
    Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 640x352 [SAR 1:1 DAR 20:11], 891 kb/s, 25 fps, 25 tbr, 25 tbn, 25 tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 128 kb/s
Metadata:
  title           : English AC3 2.0 (Stereo) @ 128 kbps
    Stream #0:2: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 192 kb/s
Metadata:
  title           : English AC3 2.0 (Stereo) @ 192 kbps
At least one output file must be specified

If you want to extract e.g. stream #0:2, use -map 0:2:

ffmpeg -i INPUT_FILE.EXT -map 0:2 OUTPUT_FILE.EXT

Further reading

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .