1

So i have been through lots of tests and i still cannot seem to get audio to mux over video using ffmpeg and cannot figure where i am going wrong so would really appreciate some help.

I have this video. Video Download

And if i run ffmpeg -i it gives me this.

 Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709), 366x662 [SAR 1:1 DAR 183:331], 755 kb/s, 24 fps, 24 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 105 kb/s (default)

So stream 0:0

And i have this piece of audio. Audio download

and when i run ffmpeg i get this.

Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 277 kb/s
Stream #0:1: Video: png, rgb24, 400x400, 90k tbr, 90k tbn, 90k tbc

so what i am look to do is copy my audio 0:0 over to replace the video audio 0:1 without re encoding the whole file.

ffmpeg -i testing.mp4 -i rkelly.mp3 -c copy -map 0:1 -map 0:0 -shortest out3.mp4 
1
  • Please always include the full, uncut command line output from ffmpeg.
    – slhck
    May 23, 2015 at 13:00

1 Answer 1

4

The first number in the -map option is the input file index. So if you're using 0 twice, you're only using testing.mp4.

Try this instead:

ffmpeg -i testing.mp4 -i rkelly.mp3 -c copy -map 0:v:0 -map 1:a:0 -shortest out3.mp4 

Here, 0:v:0 selects the first video stream of the first input file, and 1:a:0 selects the first audio stream of the second input file. In principle the :0 is not necessary for your files but it doesn't hurt to have it there in case of multiple video/audio tracks.

See the FFmpeg wiki entry on the -map option for more.

2
  • Also to note for anyone else muxing a mp3 with a mp4 wont play in quicktime but will play in vlc player if you mux a m4a with a mp4 it will play correctly in both players May 24, 2015 at 0:33
  • The mistake you're making is not investigating the input files with MediaInfo. An m4a file might not contain the audio stream you assume it does. I suppose you think it'll contain aac, but in my experience it just might contain - for example - an mp3 stream. It may well be you're actually asking ffmpeg to put avc video and mp3 audio in your output mp4 container, even though you think you're creating a file containing aac audio. Then some players will play the mp4 and others won't. If you don't know what streams you're putting into the mp4, you can't know which players will play it.
    – Ed999
    May 3, 2021 at 14:58

You must log in to answer this question.

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