2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2002-10-12 11:37:38 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
* util.c
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup imbuf
|
2011-02-27 20:23:21 +00:00
|
|
|
*/
|
|
|
|
|
|
2008-11-04 23:46:01 +00:00
|
|
|
#ifdef _WIN32
|
2012-08-12 23:28:33 +00:00
|
|
|
# include <io.h>
|
2008-11-04 23:46:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
2012-08-12 23:28:33 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2013-03-04 18:36:37 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2012-08-12 23:28:33 +00:00
|
|
|
#include "BLI_path_util.h"
|
2012-05-01 21:46:55 +00:00
|
|
|
#include "BLI_fileops.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
#include "imbuf.h"
|
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
#include "IMB_imbuf.h"
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
#include "IMB_filetype.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-28 02:15:46 +00:00
|
|
|
#include "IMB_anim.h"
|
|
|
|
|
|
2006-02-05 19:23:34 +00:00
|
|
|
#ifdef WITH_FFMPEG
|
2019-04-17 06:17:24 +02:00
|
|
|
# include "BLI_string.h" /* BLI_vsnprintf */
|
2011-05-27 07:47:42 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
# include "BKE_global.h" /* G.debug */
|
2011-05-27 07:47:42 +00:00
|
|
|
|
2019-01-26 20:41:52 +11:00
|
|
|
# include <libavcodec/avcodec.h>
|
|
|
|
|
# include <libavformat/avformat.h>
|
|
|
|
|
# include <libavdevice/avdevice.h>
|
|
|
|
|
# include <libavutil/log.h>
|
|
|
|
|
|
|
|
|
|
# include "ffmpeg_compat.h"
|
2006-02-05 19:23:34 +00:00
|
|
|
#endif
|
|
|
|
|
|
2003-04-28 02:15:46 +00:00
|
|
|
#define UTIL_DEBUG 0
|
|
|
|
|
|
2010-08-03 12:34:42 +00:00
|
|
|
const char *imb_ext_image[] = {
|
2019-04-17 06:17:24 +02:00
|
|
|
".png", ".tga", ".bmp", ".jpg", ".jpeg", ".sgi", ".rgb", ".rgba",
|
2010-08-03 12:34:42 +00:00
|
|
|
#ifdef WITH_TIFF
|
2019-04-17 06:17:24 +02:00
|
|
|
".tif", ".tiff", ".tx",
|
2010-08-03 12:34:42 +00:00
|
|
|
#endif
|
2010-08-21 08:22:47 +00:00
|
|
|
#ifdef WITH_OPENJPEG
|
2019-04-17 06:17:24 +02:00
|
|
|
".jp2", ".j2c",
|
2010-08-03 12:34:42 +00:00
|
|
|
#endif
|
|
|
|
|
#ifdef WITH_HDR
|
2019-04-17 06:17:24 +02:00
|
|
|
".hdr",
|
2010-08-03 12:34:42 +00:00
|
|
|
#endif
|
|
|
|
|
#ifdef WITH_DDS
|
2019-04-17 06:17:24 +02:00
|
|
|
".dds",
|
2010-08-03 12:34:42 +00:00
|
|
|
#endif
|
|
|
|
|
#ifdef WITH_CINEON
|
2019-04-17 06:17:24 +02:00
|
|
|
".dpx", ".cin",
|
2010-08-03 12:34:42 +00:00
|
|
|
#endif
|
2010-08-21 08:22:47 +00:00
|
|
|
#ifdef WITH_OPENEXR
|
2019-04-17 06:17:24 +02:00
|
|
|
".exr",
|
2013-10-08 21:17:24 +00:00
|
|
|
#endif
|
2013-10-11 16:38:04 +00:00
|
|
|
#ifdef WITH_OPENIMAGEIO
|
2019-04-17 06:17:24 +02:00
|
|
|
".psd", ".pdd", ".psb",
|
2013-10-08 21:17:24 +00:00
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
NULL,
|
2013-10-08 21:17:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const char *imb_ext_image_filepath_only[] = {
|
2013-10-11 16:38:04 +00:00
|
|
|
#ifdef WITH_OPENIMAGEIO
|
2019-04-17 06:17:24 +02:00
|
|
|
".psd",
|
|
|
|
|
".pdd",
|
|
|
|
|
".psb",
|
2010-08-03 12:34:42 +00:00
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
NULL,
|
2012-05-16 07:38:23 +00:00
|
|
|
};
|
2010-08-03 12:34:42 +00:00
|
|
|
|
|
|
|
|
const char *imb_ext_movie[] = {
|
2019-04-17 06:17:24 +02:00
|
|
|
".avi", ".flc", ".mov", ".movie", ".mp4", ".m4v", ".m2v", ".m2t", ".m2ts", ".mts",
|
|
|
|
|
".ts", ".mv", ".avs", ".wmv", ".ogv", ".ogg", ".r3d", ".dv", ".mpeg", ".mpg",
|
|
|
|
|
".mpg2", ".vob", ".mkv", ".flv", ".divx", ".xvid", ".mxf", ".webm", NULL,
|
2012-05-16 07:38:23 +00:00
|
|
|
};
|
2010-08-03 12:34:42 +00:00
|
|
|
|
|
|
|
|
/* sort of wrong being here... */
|
|
|
|
|
const char *imb_ext_audio[] = {
|
2019-04-17 06:17:24 +02:00
|
|
|
".wav",
|
|
|
|
|
".ogg",
|
|
|
|
|
".oga",
|
|
|
|
|
".mp3",
|
|
|
|
|
".mp2",
|
|
|
|
|
".ac3",
|
|
|
|
|
".aac",
|
|
|
|
|
".flac",
|
|
|
|
|
".wma",
|
|
|
|
|
".eac3",
|
|
|
|
|
".aif",
|
|
|
|
|
".aiff",
|
|
|
|
|
".m4a",
|
|
|
|
|
".mka",
|
|
|
|
|
NULL,
|
2012-05-16 07:38:23 +00:00
|
|
|
};
|
2010-08-03 12:34:42 +00:00
|
|
|
|
2014-04-30 10:43:46 +10:00
|
|
|
int IMB_ispic_type(const char *name)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* increased from 32 to 64 because of the bitmaps header size */
|
2013-07-13 12:58:00 +00:00
|
|
|
#define HEADER_SIZE 64
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
unsigned char buf[HEADER_SIZE];
|
|
|
|
|
const ImFileType *type;
|
|
|
|
|
BLI_stat_t st;
|
|
|
|
|
int fp;
|
2003-04-28 02:15:46 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(!BLI_path_is_rel(name));
|
2015-06-17 15:53:35 +10:00
|
|
|
|
2019-04-23 11:01:30 +10:00
|
|
|
if (UTIL_DEBUG) {
|
2019-04-17 06:17:24 +02:00
|
|
|
printf("%s: loading %s\n", __func__, name);
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2019-04-23 11:01:30 +10:00
|
|
|
if (BLI_stat(name, &st) == -1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
|
|
|
|
if (((st.st_mode) & S_IFMT) != S_IFREG) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2003-04-28 02:15:46 +00:00
|
|
|
|
2019-04-23 11:01:30 +10:00
|
|
|
if ((fp = BLI_open(name, O_BINARY | O_RDONLY, 0)) == -1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
|
if (read(fp, buf, HEADER_SIZE) <= 0) {
|
|
|
|
|
close(fp);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2003-04-28 02:15:46 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
close(fp);
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* XXX move this exception */
|
2019-04-23 11:01:30 +10:00
|
|
|
if ((BIG_LONG(((int *)buf)[0]) & 0xfffffff0) == 0xffd8ffe0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return IMB_FTYPE_JPG;
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2003-04-28 02:15:46 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
|
|
|
|
|
if (type->is_a) {
|
|
|
|
|
if (type->is_a(buf)) {
|
|
|
|
|
return type->filetype;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (type->is_a_filepath) {
|
|
|
|
|
if (type->is_a_filepath(name)) {
|
|
|
|
|
return type->filetype;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
2013-07-13 12:58:00 +00:00
|
|
|
|
|
|
|
|
#undef HEADER_SIZE
|
Merge image related changes from the render branch. This includes the image
tile cache code in imbuf, but it is not hooked up to the render engine.
Imbuf module: some small refactoring and removing a lot of unused or old code
(about 6.5k lines).
* Added a ImFileType struct with callbacks to make adding an file format type,
or making changes to the API easier.
* Move imbuf init/exit code into IMB_init()/IMB_exit() functions.
* Increased mipmap levels from 10 to 20, you run into this limit already with
a 2k image.
* Removed hamx, amiga, anim5 format support.
* Removed colormap saving, only simple colormap code now for reading tga.
* Removed gen_dynlibtiff.py, editing this is almost as much work as just
editing the code directly.
* Functions removed that were only used for sequencer plugin API:
IMB_anim_nextpic, IMB_clever_double, IMB_antialias, IMB_gamwarp,
IMB_scalefieldImBuf, IMB_scalefastfieldImBuf, IMB_onethird, IMB_halflace,
IMB_dit0, IMB_dit2, IMB_cspace
* Write metadata info into OpenEXR images. Can be viewed with the command
line utility 'exrheader'
For the image tile cache code, see this page:
http://wiki.blender.org/index.php/Dev:2.5/Source/Imaging/ImageTileCache
2010-05-07 15:18:04 +00:00
|
|
|
}
|
2003-04-28 02:15:46 +00:00
|
|
|
|
2014-04-30 10:43:46 +10:00
|
|
|
bool IMB_ispic(const char *name)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return (IMB_ispic_type(name) != 0);
|
2014-04-30 10:43:46 +10:00
|
|
|
}
|
2003-04-28 02:15:46 +00:00
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
static int isavi(const char *name)
|
2011-12-17 00:52:36 +00:00
|
|
|
{
|
2012-10-08 02:51:42 +00:00
|
|
|
#ifdef WITH_AVI
|
2019-04-17 06:17:24 +02:00
|
|
|
return AVI_is_avi(name);
|
2012-10-08 02:51:42 +00:00
|
|
|
#else
|
2019-04-17 06:17:24 +02:00
|
|
|
(void)name;
|
|
|
|
|
return false;
|
2012-10-08 02:51:42 +00:00
|
|
|
#endif
|
2003-04-28 02:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
2006-02-05 19:23:34 +00:00
|
|
|
#ifdef WITH_FFMPEG
|
2008-11-03 13:33:11 +00:00
|
|
|
|
2012-10-08 01:05:37 +00:00
|
|
|
/* BLI_vsnprintf in ffmpeg_log_callback() causes invalid warning */
|
2019-04-17 06:17:24 +02:00
|
|
|
# ifdef __GNUC__
|
|
|
|
|
# pragma GCC diagnostic push
|
|
|
|
|
# pragma GCC diagnostic ignored "-Wmissing-format-attribute"
|
|
|
|
|
# endif
|
2012-10-08 01:05:37 +00:00
|
|
|
|
2012-08-26 11:01:14 +00:00
|
|
|
static char ffmpeg_last_error[1024];
|
|
|
|
|
|
2012-09-15 01:52:28 +00:00
|
|
|
static void ffmpeg_log_callback(void *ptr, int level, const char *format, va_list arg)
|
2006-02-05 19:23:34 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ELEM(level, AV_LOG_FATAL, AV_LOG_ERROR)) {
|
|
|
|
|
size_t n;
|
|
|
|
|
va_list args_cpy;
|
|
|
|
|
|
|
|
|
|
va_copy(args_cpy, arg);
|
|
|
|
|
n = BLI_vsnprintf(ffmpeg_last_error, sizeof(ffmpeg_last_error), format, args_cpy);
|
|
|
|
|
va_end(args_cpy);
|
|
|
|
|
|
|
|
|
|
/* strip trailing \n */
|
|
|
|
|
ffmpeg_last_error[n - 1] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (G.debug & G_DEBUG_FFMPEG) {
|
|
|
|
|
/* call default logger to print all message to console */
|
|
|
|
|
av_log_default_callback(ptr, level, format, arg);
|
|
|
|
|
}
|
2012-08-26 11:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
# ifdef __GNUC__
|
|
|
|
|
# pragma GCC diagnostic pop
|
|
|
|
|
# endif
|
2012-10-08 01:05:37 +00:00
|
|
|
|
2012-08-26 11:01:14 +00:00
|
|
|
void IMB_ffmpeg_init(void)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
av_register_all();
|
|
|
|
|
avdevice_register_all();
|
2012-08-26 11:01:14 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ffmpeg_last_error[0] = '\0';
|
2012-08-26 11:01:14 +00:00
|
|
|
|
2019-04-23 11:01:30 +10:00
|
|
|
if (G.debug & G_DEBUG_FFMPEG) {
|
2019-04-17 06:17:24 +02:00
|
|
|
av_log_set_level(AV_LOG_DEBUG);
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2013-04-29 16:03:21 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* set own callback which could store last error to report to UI */
|
|
|
|
|
av_log_set_callback(ffmpeg_log_callback);
|
2012-08-26 11:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *IMB_ffmpeg_last_error(void)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return ffmpeg_last_error;
|
2006-02-05 19:23:34 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
static int isffmpeg(const char *filename)
|
2011-12-17 00:52:36 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
AVFormatContext *pFormatCtx = NULL;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
int videoStream;
|
|
|
|
|
AVCodec *pCodec;
|
|
|
|
|
AVCodecContext *pCodecCtx;
|
|
|
|
|
|
|
|
|
|
if (BLI_path_extension_check_n(filename,
|
|
|
|
|
".swf",
|
|
|
|
|
".jpg",
|
|
|
|
|
".png",
|
|
|
|
|
".dds",
|
|
|
|
|
".tga",
|
|
|
|
|
".bmp",
|
|
|
|
|
".tif",
|
|
|
|
|
".exr",
|
|
|
|
|
".cin",
|
|
|
|
|
".wav",
|
|
|
|
|
NULL)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (avformat_open_input(&pFormatCtx, filename, NULL, NULL) != 0) {
|
2019-04-23 11:01:30 +10:00
|
|
|
if (UTIL_DEBUG) {
|
2019-04-17 06:17:24 +02:00
|
|
|
fprintf(stderr, "isffmpeg: av_open_input_file failed\n");
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {
|
2019-04-23 11:01:30 +10:00
|
|
|
if (UTIL_DEBUG) {
|
2019-04-17 06:17:24 +02:00
|
|
|
fprintf(stderr, "isffmpeg: avformat_find_stream_info failed\n");
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
avformat_close_input(&pFormatCtx);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-23 11:01:30 +10:00
|
|
|
if (UTIL_DEBUG) {
|
2019-04-17 06:17:24 +02:00
|
|
|
av_dump_format(pFormatCtx, 0, filename, 0);
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
/* Find the first video stream */
|
|
|
|
|
videoStream = -1;
|
2019-05-31 22:51:19 +10:00
|
|
|
for (i = 0; i < pFormatCtx->nb_streams; i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
if (pFormatCtx->streams[i] && pFormatCtx->streams[i]->codec &&
|
|
|
|
|
(pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)) {
|
|
|
|
|
videoStream = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
if (videoStream == -1) {
|
|
|
|
|
avformat_close_input(&pFormatCtx);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pCodecCtx = pFormatCtx->streams[videoStream]->codec;
|
|
|
|
|
|
|
|
|
|
/* Find the decoder for the video stream */
|
|
|
|
|
pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
|
|
|
|
|
if (pCodec == NULL) {
|
|
|
|
|
avformat_close_input(&pFormatCtx);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) {
|
|
|
|
|
avformat_close_input(&pFormatCtx);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
avcodec_close(pCodecCtx);
|
|
|
|
|
avformat_close_input(&pFormatCtx);
|
|
|
|
|
|
|
|
|
|
return 1;
|
2006-02-05 19:23:34 +00:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-05-16 07:38:23 +00:00
|
|
|
int imb_get_anim_type(const char *name)
|
2011-12-17 00:52:36 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int type;
|
|
|
|
|
BLI_stat_t st;
|
2003-04-28 02:15:46 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(!BLI_path_is_rel(name));
|
2015-06-17 15:53:35 +10:00
|
|
|
|
2019-04-23 11:01:30 +10:00
|
|
|
if (UTIL_DEBUG) {
|
2019-04-17 06:17:24 +02:00
|
|
|
printf("%s: %s\n", __func__, name);
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2003-04-28 02:15:46 +00:00
|
|
|
|
2007-05-30 06:11:25 +00:00
|
|
|
#ifndef _WIN32
|
2019-04-17 06:17:24 +02:00
|
|
|
# ifdef WITH_FFMPEG
|
|
|
|
|
/* stat test below fails on large files > 4GB */
|
2019-04-23 11:01:30 +10:00
|
|
|
if (isffmpeg(name)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return (ANIM_FFMPEG);
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
# endif
|
2019-04-23 11:01:30 +10:00
|
|
|
if (BLI_stat(name, &st) == -1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return (0);
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
|
|
|
|
if (((st.st_mode) & S_IFMT) != S_IFREG) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return (0);
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-23 11:01:30 +10:00
|
|
|
if (isavi(name)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return (ANIM_AVI);
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-23 11:01:30 +10:00
|
|
|
if (ismovie(name)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return (ANIM_MOVIE);
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2007-05-30 06:11:25 +00:00
|
|
|
#else
|
2019-04-23 11:01:30 +10:00
|
|
|
if (BLI_stat(name, &st) == -1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return (0);
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
|
|
|
|
if (((st.st_mode) & S_IFMT) != S_IFREG) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return (0);
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-23 11:01:30 +10:00
|
|
|
if (ismovie(name)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return (ANIM_MOVIE);
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
# ifdef WITH_FFMPEG
|
2019-04-23 11:01:30 +10:00
|
|
|
if (isffmpeg(name)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return (ANIM_FFMPEG);
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
# endif
|
|
|
|
|
|
2019-04-23 11:01:30 +10:00
|
|
|
if (isavi(name)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return (ANIM_AVI);
|
2019-04-23 11:01:30 +10:00
|
|
|
}
|
2003-04-28 02:15:46 +00:00
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
type = IMB_ispic(name);
|
|
|
|
|
if (type) {
|
|
|
|
|
return ANIM_SEQUENCE;
|
|
|
|
|
}
|
2012-04-23 08:05:02 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ANIM_NONE;
|
2003-04-28 02:15:46 +00:00
|
|
|
}
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2014-02-03 18:55:59 +11:00
|
|
|
bool IMB_isanim(const char *filename)
|
2011-12-17 00:52:36 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int type;
|
2015-06-17 15:53:35 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
type = imb_get_anim_type(filename);
|
2018-06-17 17:04:54 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return (type && type != ANIM_SEQUENCE);
|
2003-04-28 02:15:46 +00:00
|
|
|
}
|
2015-04-06 10:40:12 -03:00
|
|
|
|
|
|
|
|
bool IMB_isfloat(ImBuf *ibuf)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const ImFileType *type;
|
|
|
|
|
|
|
|
|
|
for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
|
|
|
|
|
if (type->ftype(type, ibuf)) {
|
|
|
|
|
return (type->flag & IM_FTYPE_FLOAT) != 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2015-04-06 10:40:12 -03:00
|
|
|
}
|