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.

Advertisements
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.
https://www.virag.si/2012/11/streaming-live-webm-video-with-ffmpeg/

Or this great tutorial too.
http://www.bogotobogo.com/VideoStreaming/ffmpeg_http_live_streaming_hls.php

Hope it helped you.

Stream live mp4 video with ffmpeg while encoding

jsHtml5AVRecorder – Record html5 audio and video simultaneously and convert them to mp4

A few days ago, I’ve published two javascripts plugins, jsHtml5AudioRecorder and jsHtml5VideoRecorder.

Each of them allows you to record respectively, audio and video from html5 live stream.

jsHtml5AVRecorder is a wrapper of these two plugins.
It allows you to record simultaneously audio and video from live stream, and convert them to mp4 using FFMPEG.

It is really simple to understand, this is how to use it:

var jsAVRecorder = new jsHtml5AVRecorder();
jsAVRecorder.audioWrapper                    = jsAudioRecorder;      //jsHtml5AudioRecorder object with parameters - here https://github.com/edouardkombo/jsHtml5AudioRecorder
jsAVRecorder.videoWrapper                    = jsVideoRecorder;      //jsHtml5VideoRecorder object with parameters - here https://github.com/edouardkombo/jsHtml5VideoRecorder
jsAVRecorder.convertFilesTo                  = 'mp4';                //MP4 is the extension in which convert the medias
jsAVRecorder.doConversion                    = false;                 //Apply conversion
jsAVRecorder.streamConvertedResult           = false;                 //Show the result of the conversion
jsAVRecorder.deleteSeparatedFiles            = false;                 //Delete audio and video files, to only keep the single file
jsAVRecorder.mediaPath                       = '/medias/Temp/';
jsAVRecorder.phpFile                         = '/form/convertProcess.php'; //File is included inside the repository


jsAVRecorder.init();

function startRecording() {
    jsAVRecorder.startRecording();
}

/**
 * You can use "save", "saveAndDownload" or "saveAndStream", "downloadAndStream" parameters
 */
function stopRecording() {
    //For demo
    jsAVRecorder.stopRecording('stream');
    
    //In production
    //jsAVRecorder.stopRecording('saveAndStream');
}

Feel free to help improve this code and leads it at another level.

The complete code is hosted on Github: https://github.com/edouardkombo/jsHtml5AVRecorder
 
Demo is available here: https://edouardkombo.github.io/jsHtml5AVRecorder/demo
 
To download from Bower:

bower install js-html5-av-recorder
jsHtml5AVRecorder – Record html5 audio and video simultaneously and convert them to mp4

FFMPEG (windows) – unknown encoder libfaac // encode avi to mp4 without libfaac

When it comes to encode some videos with ffmpeg, some libraries are needed, but not all provided inside the ffmpeg package.

To encode avi videos to mp4 with ffmpeg, you will need libfaac, and this library is hard to run.
FAAC is an MPEG-4 and MPEG-2 AAC encoder (http://www.audiocoding.com/faac.html).

So, if you have libfaac, this instruction will help you:

ffmpeg -i input.avi -c:v libx264 -crf 19 -preset slow -c:a libfaac -b:a 192k -ac 2 out.mp4

But, if you don’t have libfaac, this instruction will save you time:

ffmpeg -i input.avi -c:v libx264 -crf 19 -preset slow -c:a aac -strict experimental -b:a 192k -ac 2 out.mp4

More details here: http://superuser.com/questions/525249/convert-avi-to-mp4-keeping-the-same-quality

Have a great day.

FFMPEG (windows) – unknown encoder libfaac // encode avi to mp4 without libfaac

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