I have a directory with many files of different types and want to find out the codec of each video file. This works well with this command:

$ ffprobe -v error -select_streams v -show_entries stream=codec_name,codec_type -of default=noprint_wrappers=1 video-file

But unfortunately I also get a result for JPG and text files:

$ ffprobe -v error -select_streams v -show_entries stream=codec_name,codec_type -of default=noprint_wrappers=1 file.jpg 
$ ffprobe -v error -select_streams v -show_entries stream=codec_name,codec_type -of default=noprint_wrappers=1 file.txt

Both files are clearly not video files. Well, I could filter out the file extensions or blacklist these codec names. But isn't there a proper way with ffprobe?


FFmpeg is primarily a processor of timed media samples. An image is a video stream consisting of one frame. Checking for pipe in format=format_name entry is your best bet for detecting images.

As far as text files go, ffmpeg converts the .txt contents to a video image, and the codec_type indicates the decoded stream type. You can check format_name again for tty.

  • Thanks, that helped me a lot to understand the problem. Do you know other non-video formats where ffmpeg recognizes a video stream? – Alexander Bösecke Jul 2 '18 at 16:37

With the help of Gyan's comment I created this little function for the fish shell.

function gvc --description 'Get the video codec of a file if the file is a video' --argument file
    if test -f "$file"
        set format (ffprobe -v panic -select_streams v -show_entries format=format_name -of default=nokey=1:noprint_wrappers=1 $file)
        if test -n "$format" -a "$format" != "image2" -a "$format" != "tty"
            echo (ffprobe -v error -select_streams v -show_entries stream=codec_name -of default=nokey=1:noprint_wrappers=1 $file)
    return $status

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.