我怎么知道某个文件是视频文件? [英] How can I know a certain file is a video file?

查看:150
本文介绍了我怎么知道某个文件是视频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定某个用户上传的文件是否是视频文件.

I am trying to figure out if a certain user-uploaded file is a video file.

我首先尝试了ffprobe,

I first tried ffprobe,

# a png file

Input #0, png_pipe, from '<file>':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: png, rgba(pc), 920x2094 [SAR 4724:4724 DAR 460:1047], 25 tbr, 25 tbn, 25 tbc

# a text file

Input #0, tty, from '<file>':
  Duration: 00:00:00.24, bitrate: 40 kb/s
    Stream #0:0: Video: ansi, pal8, 640x400, 25 fps, 25 tbr, 25 tbn, 25 tbc

# a video file

Input #0, matroska,webm, from '<file>':
  Metadata:
    encoder         : libebml v1.3.5 + libmatroska v1.4.8
    creation_time   : 2017-12-12T20:18:42.000000Z
  <redacted>

但是要弄清楚到底是什么太难了.甚至图像文件和文本文件也算作视频.

but it's too hard to figure out what's what. Even image files and text files count as a video.

我应该将输出 matroska,webm 与ffmpeg支持的每个编解码器进行比较,还是有更好的方法呢?

Should I compare the output matroska,webm, with every codec ffmpeg supports or is there a better way to do this?

推荐答案

使用 ffprobe :

ffprobe -v error -select_streams v:0 -show_entries stream=codec_type -of csv=p=0 input.mkv

输出视频或完全不输出.

问题是 ffprobe 将图像视为视频,因此您可以另外/替代地使用 codec_name 来帮助确定类型:

The problem is that ffprobe considers images to be video, so you can additionally/alternatively use codec_name to help determine the type:

ffprobe -v error -select_streams v:0 -show_entries stream=codec_name,codec_type -of default=nw=1 input.png

输出:

codec_name=png
codec_type=video

这篇关于我怎么知道某个文件是视频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆