Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg: set the language of an audio stream

I have 3 files: video.mp4, audionl.mp4 & audioeng.mp4. I tried adding them all together in 1 output.mp4 file like this:

ffmpeg -y -i video.mp4 -i audionl.mp4 -i audioeng.mp4  -map 0:v -map 1:a -map 2:a -metadata:s:a:0 language=nl -metadata:s:a:0 title="NL" -metadata:s:a:1 language=eng  -metadata:s:a:1 title="ENG" -acodec copy -bsf:a aac_adtstoasc -vcodec copy  -movflags faststart output.mp4 2>&1

This is the output I see from ffmpeg:

ffmpeg version 2.6.9 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.9.2 (Debian 4.9.2-10)
  configuration: --prefix=/usr --extra-cflags='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security ' --extra-ldflags='-Wl,-z,relro' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl --enable-nonfree --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-x11grab --enable-libgsm --enable-libtheora --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libspeex --enable-nonfree --disable-stripping --enable-libvpx --enable-libschroedinger --disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg --enable-librtmp --enable-avfilter --enable-libfreetype --enable-libvo-aacenc --disable-decoder=amrnb --enable-libvo-amrwbenc --enable-libaacplus --libdir=/usr/lib/x86_64-linux-gnu --disable-vda --enable-libbluray --enable-libcdio --enable-gnutls --enable-frei0r --enable-openssl --enable-libass --enable-libopus --enable-fontconfig --enable-libpulse --disable-mips32r2 --disable-mipsdspr1 --disable-mipsdspr2 --enable-libvidstab --enable-libzvbi --enable-avresample --disable-htmlpages --disable-podpages --enable-libutvideo --enable-libfdk-aac --enable-libx265 --enable-libiec61883 --enable-vaapi --enable-libdc1394 --disable-altivec --shlibdir=/usr/lib/x86_64-linux-gnu
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: isomavc1mp42dash
    creation_time   : 2017-06-04 06:35:06
  Duration: 00:20:52.80, start: 0.000000, bitrate: 1172 kb/s
    Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 1168 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2017-06-04 06:35:06
      handler_name    : VideoHandler
      encoder         : VideoHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'audionl.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: isomM4A mp42dash
    creation_time   : 2017-06-04 06:35:06
  Duration: 00:20:52.80, start: 0.000000, bitrate: 96 kb/s
    Stream #1:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2017-06-04 06:35:06
      handler_name    : SoundHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'audioeng.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: isomM4A mp42dash
    creation_time   : 2017-06-04 06:35:06
  Duration: 00:20:52.78, start: 0.000000, bitrate: 64 kb/s
    Stream #2:0(eng): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 62 kb/s (default)
    Metadata:
      creation_time   : 2017-06-04 06:35:06
      handler_name    : SoundHandler
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: isomavc1mp42dash
    encoder         : Lavf56.25.101
    Stream #0:0(eng): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=2-31, 1168 kb/s, 25 fps, 25 tbr, 90k tbn, 90k tbc (default)
    Metadata:
      creation_time   : 2017-06-04 06:35:06
      handler_name    : VideoHandler
      encoder         : VideoHandler
    Stream #0:1(nl): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 93 kb/s (default)
    Metadata:
      creation_time   : 2017-06-04 06:35:06
      handler_name    : SoundHandler
      title           : NL
    Stream #0:2(eng): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 62 kb/s (default)
    Metadata:
      creation_time   : 2017-06-04 06:35:06
      handler_name    : SoundHandler
      title           : ENG
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
  Stream #2:0 -> #0:2 (copy)
Press [q] to stop, [?] for help
[mp4 @ 0xbb1320] Starting second pass: moving the moov atom to the beginning of the file
frame=31320 fps=20993 q=-1.0 Lsize=  204217kB time=00:20:52.79 bitrate=1335.4kbits/s
video:178734kB audio:23867kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.797284%

As you can see in there: "Stream #0:0(eng)", "Stream #0:1(nl)" & "Stream #0:2(eng)". So that looks fine.

But when I open it in VLC, I see under Audio tracks: NL - [English] ENG - [English]

So I went back to check on ffmpeg with "ffmpeg -i output.mp4":

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.25.101
  Duration: 00:20:52.80, start: 0.000000, bitrate: 1335 kb/s
    Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 1168 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
    Stream #0:2(eng): Audio: aac (HE-AAC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 62 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

And here they are English again...

Afterwards I tried this:

ffmpeg -y -i audionl.mp4 -c:a copy -metadata:s:a:0 language=nl output.mp4

But also that failed to set the correct language on the output file... I'm at a loss here and hope someone can help me set these languages correctly.

Thanks a lot!

like image 500
Steven Van Ingelgem Avatar asked Jun 04 '17 07:06

Steven Van Ingelgem


People also ask

What output files does FFmpeg support?

There are three output files specified, and for the first two, no -map options are set, so ffmpeg will select streams for these two files automatically. out1.mkv is a Matroska container file and accepts video, audio and subtitle streams, so ffmpeg will try to select one of each type.

Why doesn't FFmpeg support subtitles?

Since you've not specified an encoder for subtitles, ffmpeg is trying to pick one and fails since it doesn't have an image-based subtitle encoder. You can copy or drop the stream. Of course, your primary aim is to map only the audio stream by language.

How do I map a multichannel audio stream in FFmpeg?

All codec AVOptions are per-stream, and thus a stream specifier should be attached to them: ffmpeg -i multichannel.mxf -map 0:v:0 -map 0:a:0 -map 0:a:0 -c:a:0 ac3 -b:a:0 640k -ac:a:1 2 -c:a:1 aac -b:2 128k out.mp4 In the above example, a multichannel audio stream is mapped twice for output.

How do I enable lame support in FFmpeg?

Furthermore, the audio stream is MP3-encoded so you need to enable LAME support by passing --enable-libmp3lame to configure. The mapping is particularly useful for DVD transcoding to get the desired audio language. NOTE: To see the supported input formats, use ffmpeg -demuxers .


1 Answers

FFmpeg expects ISO 639-2 codes for languages, so for Dutch, it's either

-metadata:s:a:0 language=dut

or

-metadata:s:a:0 language=nld
like image 118
Gyan Avatar answered Sep 21 '22 14:09

Gyan