35# include <libavcodec/avcodec.h>
36# include <libavdevice/avdevice.h>
37# include <libavformat/avformat.h>
38# include <libavutil/log.h>
48 ".png",
".tga",
".bmp",
".jpg",
".jpeg",
".sgi",
".rgb",
".rgba",
".tif",
".tiff",
".tx",
59 ".psd",
".pdd",
".psb",
67 ".avi",
".flc",
".mov",
".movie",
".mp4",
".m4v",
".m2v",
".m2t",
".m2ts",
".mts",
68 ".ts",
".mv",
".avs",
".wmv",
".ogv",
".ogg",
".r3d",
".dv",
".mpeg",
".mpg",
69 ".mpg2",
".vob",
".mkv",
".flv",
".divx",
".xvid",
".mxf",
".webm",
".gif",
nullptr,
94#define HEADER_SIZE 2048
104 printf(
"%s: loading %s\n", __func__, filepath);
107 if (
BLI_stat(filepath, &st) == -1) {
110 if (((st.st_mode) & S_IFMT) != S_IFREG) {
127 if (type->is_a !=
nullptr) {
128 if (type->is_a(buf, buf_size)) {
129 return type->filetype;
156 if (type !=
nullptr) {
160 if (type->is_a !=
nullptr) {
161 return type->is_a(buf,
size_t(buf_size));
178# pragma GCC diagnostic push
179# pragma GCC diagnostic ignored "-Wmissing-format-attribute"
182static char ffmpeg_last_error[1024];
184static void ffmpeg_log_callback(
void *
ptr,
int level,
const char *
format, va_list arg)
186 if (
ELEM(level, AV_LOG_FATAL, AV_LOG_ERROR)) {
190 va_copy(args_cpy, arg);
195 ffmpeg_last_error[n - 1] =
'\0';
200 av_log_default_callback(
ptr, level,
format, arg);
205# pragma GCC diagnostic pop
210 avdevice_register_all();
212 ffmpeg_last_error[0] =
'\0';
215 av_log_set_level(AV_LOG_DEBUG);
219 av_log_set_callback(ffmpeg_log_callback);
224 return ffmpeg_last_error;
227static int isffmpeg(
const char *filepath)
229 AVFormatContext *pFormatCtx =
nullptr;
232 const AVCodec *pCodec;
252 if (avformat_open_input(&pFormatCtx, filepath,
nullptr,
nullptr) != 0) {
254 fprintf(stderr,
"isffmpeg: av_open_input_file failed\n");
259 if (avformat_find_stream_info(pFormatCtx,
nullptr) < 0) {
261 fprintf(stderr,
"isffmpeg: avformat_find_stream_info failed\n");
263 avformat_close_input(&pFormatCtx);
268 av_dump_format(pFormatCtx, 0, filepath, 0);
273 for (i = 0; i < pFormatCtx->nb_streams; i++) {
274 if (pFormatCtx->streams[i] && pFormatCtx->streams[i]->codecpar &&
275 (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO))
282 if (videoStream == -1) {
283 avformat_close_input(&pFormatCtx);
287 AVCodecParameters *codec_par = pFormatCtx->streams[videoStream]->codecpar;
290 pCodec = avcodec_find_decoder(codec_par->codec_id);
291 if (pCodec ==
nullptr) {
292 avformat_close_input(&pFormatCtx);
296 avformat_close_input(&pFormatCtx);
307 printf(
"%s: %s\n", __func__, filepath);
311 if (isffmpeg(filepath)) {
File and directory operations.
int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_open(const char *filepath, int oflag, int pmode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int64_t BLI_read(int fd, void *buf, size_t nbytes)
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool BLI_path_extension_check_n(const char *path,...) ATTR_NONNULL(1) ATTR_SENTINEL(0)
#define VSNPRINTF(dst, format, args)
Compatibility-like things for windows.
const char * IMB_ffmpeg_last_error()
Contains defines and structs used throughout the imbuf module.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
const ImFileType * IMB_file_type_from_ftype(int ftype)
const ImFileType IMB_FILE_TYPES[]
const ImFileType * IMB_FILE_TYPES_LAST
int IMB_ispic_type_from_memory(const uchar *buf, const size_t buf_size)
const char * imb_ext_movie[]
int IMB_ispic_type(const char *filepath)
const char * imb_ext_audio[]
bool IMB_isanim(const char *filepath)
static int64_t imb_ispic_read_header_from_filepath(const char *filepath, uchar buf[HEADER_SIZE])
bool IMB_ispic_type_matches(const char *filepath, int filetype)
bool IMB_ispic(const char *filepath)
const char * imb_ext_image[]