I wished to be able do this multiple times now so I ask.
If I have an existing video or audio file, ffmpeg
, mplayer
and other media players can detect at least some of it's "propreties" like container, codec and bitrate used, probably various quality and encoding specific settings, etc.
How can I extract these settings from an existing file in order to use them (directly) for encoding with ffmpeg?
For example, I got an mkv
video encoded with x264
with some settings, and another uncompressed avi
file. I would like to "copy" the encoding settings used in for x264 mkv file to transcode the avi with the same settings.
Note: I'm looking for a way that should include no human work with "translating" the settings from a decoder to the encoder. It is okay if I need to extract the settings first and save it somewhere but I would like to be able to simply feed the read options to a command line or preset|configuration file for ffmpeg.
Best Answer
There is no automatic way to do that. You have to look at the parameters of the original file and apply them to the output file.
In most cases, these will be the following:
-filter:v scale
or-s:v
-filter:v fps
-r
-pix_fmt
(e.g.,-pix_fmt yuv420p
should give you the best compatibility)-g
But even if you get that all right, some devices may require specific, proprietary information embedded in the bitstream.
As for the specific task of using
x264
, this is not going to be trivial. I'm not aware of a single script that'd take care of these tasks, which are usually done manually. For the most info about the encoding settings, on Unix/Linux or OS X, you can usemediainfo
with some Bash tricks.For example, for an x264-encoded video in an MP4 file:
This will output a list of x264 options:
You could then manually pass these options to the x264 binary.
If you go through FFmpeg, that's a little more complicated though, as not all of x264's options can or should be mapped like this. Note that often a simple preset, tune and profile specification will do as well (as seen in
x264 --fullhelp
and the x264 encoding guide), and specifying the CRF level is enough.And this is not even considering audio, where luckily, there aren't that many options.