Is there a way to use ffmpeg to determine the encoding of a file before transcoding?

Bill Noble picture Bill Noble · Apr 11, 2011 · Viewed 34.9k times · Source

I am planning to use ffmpeg to ensure all video files uploaded to my website are encoded as mp4 h264.

Rather than automatically processing every file I would like to minimise the processing overhead by only processing those files that are not already mp4 h264. Is there an easy way to do this either with ffmpeg or with another command line utility?

Answer

llogan picture llogan · Feb 8, 2016

Use ffprobe.

Example command

$ ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=nokey=1:noprint_wrappers=1 input.mp4

Result

h264

Option descriptions

  • -v error Omit extra information except for fatal errors.

  • -select_streams v:0 Select only the first video stream. Otherwise the codec_name for all other streams in the file, such as audio, will be shown as well.

  • -show_entries stream=codec_name Only output the codec_name instead of all stream info.

  • -of default=nokey=1:noprint_wrappers=1 Select the default output format style and omit the key and wrapper info. Otherwise, without these options, it will output:

    [STREAM]
    codec_name=h264
    [/STREAM]
    

Also see