1

I want to add a second audio stream to an mp4 video file already containing sound.

The second audio stream is a little longer than the video, but I want the final product to be the same length.

I tried using the -shortest feature but the second audio stream I wanted to add want not audible at all.

I think -shortest only allows for one stream, so what can I do to keep the video the same length and keep both audio streams?

Here is the full command I used before asking this question:

ffmpeg -i input.mp4 -i input.m4a -map 0:v -map 0:a -shortest output.mp4

Output of 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         : Lavf58.45.100
  Duration: 00:00:32.08, start: 0.000000, bitrate: 1248 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x600 [SAR 1:1 DAR 4:5], 1113 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
scob_
  • 277
  • 1
  • 11

1 Answers1

1

You have to map the audio from the 2nd input as well.

ffmpeg -i input.mp4 -i input.m4a -map 0:v -map 0:a -map 1:a -shortest -fflags +shortest -max_interleave_delta 100M output.mp4

See https://stackoverflow.com/a/55804507/ for explanation of how to make shortest effective.

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • Thanks for your help. The second audio stream is now showing, but it's still inaudible. Any ideas? https://pastebin.com/iNgQXvbj – scob_ Nov 20 '20 at 10:08
  • Which player did you test in? And did you switch the audio selection? – Gyan Nov 20 '20 at 12:39
  • I tested in VLC. Sorry, my question was a bit unclear - with the end result, I wanted both streams to play at the same time. I just merged audio streams to make this happen. Thanks for your help! – scob_ Nov 20 '20 at 20:31