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

前提是你 提交于 2019-11-27 20:09:17

If you pass an input file to ffmpeg, without other parameters, it will give you information about the video source:

ffmpeg -i myfile.avi

Another way would be the -identify option of mplayer, which might be slightly easier to parse. There is a wrapper script midentify which gives you even better output. See this example.

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

An alternative is to use ffprobe which is included with ffmpeg. The following will give the most terse output I can find from the ffmpeg tools:

ffprobe -hide_banner -stats -i myfile.avi
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!