简体   繁体   English

用ffmpeg找出文件是视频还是图像

[英]find out if file is a video or an image with ffmpeg

is there any direct way of finding out whether file is an image or video while using ffmpeg library? 使用ffmpeg库时,有什么直接的方法可以找出文件是图像还是视频?

i know i can get codec_id from AVCodecContext ( https://www.ffmpeg.org/doxygen/trunk/structAVCodecContext.html ), but enumeration at https://www.ffmpeg.org/doxygen/trunk/group__lavc__core.html#gaadca229ad2c20e060a14fec08a5cc7ce 我知道我可以从AVCodecContext( https://www.ffmpeg.org/doxygen/trunk/structAVCodecContext.html )获取codec_id,但在https://www.ffmpeg.org/doxygen/trunk/group__lavc__core.html#gaadca229ad2c20e060a14fec08a5cc7ce

is really huge and doesnt seem to be categorized.. 真的很大,似乎没有分类。

ok after investigating ffprobe sources seems that i found something which helps (not sure if it's 100% reliable) 确定调查ffprobe来源后,似乎我发现了一些有帮助的东西(不确定它是否100%可靠)

AVFormatContext->iformat->name

but similar problem there .. lot of uncategorized possibilities. 但是那里有类似的问题..很多未分类的可能性。 except that it returns "image2"/"gif"/"ico" in case of an image. 除了在出现图像的情况下返回“ image2” /“ gif” /“ ico”之外。 more image formats can appear, all supported are listed at http://www.ffmpeg.org/general.html#Image-Formats 可能会出现更多图像格式,所有受支持的图像都列在http://www.ffmpeg.org/general.html#Image-Formats

if it's not an image, it is necessarry to analyze all streams and detect video stream within them (to know it's a video not an audio or subtitles file). 如果不是图像,则必须分析所有流并检测其中的视频流(要知道这是视频而不是音频或字幕文件)。 basically check for: 基本上检查:

AVFormatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO

it is still necesarry to check iformat->name first, because streams check returns AVMEDIA_TYPE_VIDEO both for images and videos. 仍然需要首先检查iformat-> name,因为流检查会同时返回图像和视频的AVMEDIA_TYPE_VIDEO。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM