FFMPEG merge audio and video to multiple outputs formats

Hi everybody,

I was wondering this day, how to combine audio and video file to multiple outputs formats using FFMPEG.
I’ve searched a long on Google with no results, so I thought by myself and have found the solution, it’s very simple to use.
All you have to do is add outputs to your convert command, and it’s done.

By example, let’s try to convert wav and webm input into mp4, we’ll proceed as this:

ffmpeg -i input.webm -i input.wav -map 0:0 -map 1:0 output.mp4

Good, now when it comes to add multiple outputs, it is not more difficult, we only have to add new outputs at the suit.
By example, let’s try to add “avi and ogg” formats.
This is the result

ffmpeg -i input.webm -i input.wav -map 0:0 -map 1:0 output.mp4 output.ogg output.avi

Perfect !
But some formats will need specific codecs in order to work, like “FLV”.
To make it work you only have to specify the corresponding codecs before the output, like this.

ffmpeg -i input.webm -i input.wav -map 0:0 -map 1:0 output.mp4 output.ogg output.avi -c:a libmp3lame -ar 44100 -c:v libx264 output.flv

And for linux users

ffmpeg -i input.webm -i input.wav -map 0:0 -map 1:0 -strict experimental output.ogg -strict experimental output.mp4 -c:a libmp3lame -ar 44100 -c:v libx264 -strict experimental output.flv

Congratulations, the job is done, you’re a hero.
Hope it will help you.

FFMPEG merge audio and video to multiple outputs formats

Stream live mp4 video with ffmpeg while encoding

Hello everybody,

It’s been awhile I’ve posted an article on this blog, and, it’s with a great pleasure I share with you what I’ve just learnt… How to stream an mp4 video while encoding it, directly with ffmpeg just like Youtube or Vimeo?

First, we’ll have to understand why an mp4 video has to be completely loaded by the browser in order to play it.

1. MOOV ATOM, What’s that?
MOOV ATOM, is literaly an autonomous unit of metadata related to the video file, that contains informations about:
– The video duration
– The video display characteristics
– Some additional video track informations

With mp4 files, the MOOV ATOM is placed by default at the end of the file, so, until your video is completely loaded, it is impossible to know its duration and some other essential informations, this is why mp4 videos are not natively streamable on the fly while encoding.

But, this is not the case for “flv, ogg, webm, mpeg-ts” video files, that are called SOTF (Stream-Oriented Transport Format).

2. How to encode mp4 and move MOOV ATOM details to the beginning?
This is done in just one command with the “-movflags faststart” attributes, juste like this.

ffmpeg -i input.avi -c:v libx264 -crf 22 -c:a libfaac -movflags faststart output.mp4

3. Now, how to stream our video while encoding?
Ok, now we have a streamable mp4 file, what we need is to live streaming it while encoding.
You have many ways to solve this, like using JWPlayer and FFMPEG.

I will not explain again what has been perfectly explained on another website, so I recommand you to see this great tutorial about video live streaming with FFServer and FFmpeg.

Or this great tutorial too.

Hope it helped you.

Stream live mp4 video with ffmpeg while encoding

FFMPEG – Codec type mismatch for mapping #0.0 -> #0.0

Maybe you have already faced this error while trying to mix an audio with a video file, and it is very frustrating, mainly if you have a very pressed customer. In my case, this was my command line:

ffmpeg -i 1.wav -i 1.webm -map 0:0 -map 1:0 1.mp4

And the corresponding error:

Codec type mismatch for mapping #0.0 -> #0.0

This occured because:

  • Firstly, i was mixing the audio file before the video file, while ffmpeg only expects streams in the following order “video, audio”, maybe because of videos random bitrates, don’t ask me why, if you have an idea to share, you’re welcome.
  • Secondly, my ffmpeg version on my Linux server was experimental about AAC formats, because ffmpeg converts my .wav to .aac, so the tip was to specify that are in experimental mode. This is the working command:

ffmpeg -i 1.webm -i 1.wav -stric experimental -map 0:0 -map 1:0 1.mp4

That’s all, hope this could be helpful for you in the future.

FFMPEG – Codec type mismatch for mapping #0.0 -> #0.0