FFMPEG converting media type aswell as relocating MOOV atom
I have found this line online
ffmpeg -i input.mp4 -c:a copy -c:v copy -movflags faststart output.mp4
Which takes an input, and copies the audio, video and sets the MOOV atom to the beginning in an element called output.mp4. Basically creating the same video with the MOOV atoms in a new place.
I need to convert the type of this media though - so I have the line
ffmpeg -i input.wmv -vcodec h264 -f mp4 output.mp4
My problem is, is this possible in one line? I know I can run one after another but that creates a couple of videos when I only need the resulting video, which could result in a lot of memory wasted.
I am sure the line
ffmpeg -i input.wmv -movflags faststart -vcodec h264 -f mp4 output.mp4
Is legitimate, but without the straight copies, this takes a long long time to compute.
Any input on MOOV atoms and ffmpeg computation is welcome.
Solution 1:
Copying streams is faster
Your first example is simply copying the streams and then relocating the moov atom. This relocation allows a video to begin playback before it is completely downloaded such as a viewer watching your video via browser.
ffmpeg -i input.mp4 -codec copy -map 0 -movflags +faststart output.mp4
Encoding is slower
Encoding, as in your second example, can take a long time depending on several factors including: the complexity and duration of your input, how your ffmpeg and x264 builds were compiled, the age of your builds (potential lack of features, improvements, and bug fixes), your CPU, the encoder used, and your encoding settings. Not all of these can be controlled, but you can make sure you're using a recent build and you can change your encoding settings to better fit your needs.
Getting FFmpeg
Static builds are easy to use: just download, extract, and run. See the FFmpeg Download page for options for Linux, Windows, and OS X users. You can also compile and several step-by-step FFmpeg compile guides are available.
Using a preset
You can use a faster encoding preset when encoding with x264:
ffmpeg -i in.wmv -codec:v libx264 -preset fast -movflags +faststart out.mp4
A preset is a collection of options that determine the encoding efficiency and therefore will also affect the speed. Current presets are: ultrafast
, superfast
, veryfast
, faster
, fast
, medium
, slow
, slower
, veryslow
, placebo
. The default is medium
, and placebo
is a waste of time. General recommendation is to simply use the slowest preset that you have patience for. See the FFmpeg and x264 Encoding Guide for more information.
The -f mp4
is unnecessary and depending on your ffmpeg version h264
can work as an encoder name it is convention to use libx264
.