Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

ffmpeg - Using ffprobe to check if file is audio or video only

Is there an ffprobe command I can run to see if an mov file that I have is audio-only or contains video as well? I have various mov files, some of which are audio dubs and some of which are full videos.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To output the codec_type

ffprobe -loglevel error -show_entries stream=codec_type -of default=nw=1 input.foo

Example result:

codec_type=video
codec_type=audio

If you have multiple audio or video streams the output will show multiple video or audio entries.


Same as above but output just the values

ffprobe -loglevel error -show_entries stream=codec_type -of default=nw=1=nk=1 input.foo

or:

ffprobe -loglevel error -show_entries stream=codec_type -of csv=p=0 input.foo

Example result:

video
audio

To include the stream index

ffprobe -loglevel error -show_entries stream=index,codec_type -of csv=p=0 input.foo

Example result:

0,video
1,audio

In this example the video is the first stream and the audio is the second stream which is the norm but not always the case.


Output nothing if there is no audio

ffprobe -loglevel error -select_streams a -show_entries stream=codec_type -of csv=p=0 input.foo

Example result for input with audio:

audio

If the input does not have audio then there will be no output (null output) which could be useful for scripted usage.


JSON output example

ffprobe -loglevel error -show_entries stream=codec_type -of json input.mkv 

Example result:

{
    "programs": [

    ],
    "streams": [
        {
            "codec_type": "video"
        },
        {
            "codec_type": "audio"
        }
    ]
}

Other output formats

If you want different output formatting (ini, flat, compact, csv, xml) see FFprobe Documentation: Writers.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...