diff options
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/IMB_imbuf.h | 4 | ||||
-rw-r--r-- | source/blender/imbuf/intern/anim_movie.c | 4 | ||||
-rw-r--r-- | source/blender/imbuf/intern/util.c | 51 |
3 files changed, 40 insertions, 19 deletions
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index 738e61dbe6e..a04affd4891 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -506,5 +506,9 @@ void IMB_processor_apply_threaded(int buffer_lines, int handle_size, void *init_ void *customdata), void *(do_thread) (void *)); +/* ffmpeg */ +void IMB_ffmpeg_init(void); +const char *IMB_ffmpeg_last_error(void); + #endif diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c index f07a18cb89c..9092d59c351 100644 --- a/source/blender/imbuf/intern/anim_movie.c +++ b/source/blender/imbuf/intern/anim_movie.c @@ -439,8 +439,6 @@ static ImBuf *avi_fetchibuf(struct anim *anim, int position) #ifdef WITH_FFMPEG -extern void do_init_ffmpeg(void); - static int startffmpeg(struct anim *anim) { int i, videoStream; @@ -463,8 +461,6 @@ static int startffmpeg(struct anim *anim) streamcount = anim->streamindex; - do_init_ffmpeg(); - if (avformat_open_input(&pFormatCtx, anim->name, NULL, NULL) != 0) { return -1; } diff --git a/source/blender/imbuf/intern/util.c b/source/blender/imbuf/intern/util.c index 2b0597d64a5..9ec22f0798e 100644 --- a/source/blender/imbuf/intern/util.c +++ b/source/blender/imbuf/intern/util.c @@ -43,6 +43,8 @@ #include "BLI_path_util.h" #include "BLI_fileops.h" +#include "BLI_utildefines.h" +#include "BLI_string.h" #include "DNA_userdef_types.h" #include "BKE_global.h" @@ -220,6 +222,8 @@ static int isqtime(const char *name) #ifdef WITH_FFMPEG +static char ffmpeg_last_error[1024]; + void silence_log_ffmpeg(int quiet) { if (quiet) { @@ -230,21 +234,40 @@ void silence_log_ffmpeg(int quiet) } } -extern void do_init_ffmpeg(void); -void do_init_ffmpeg(void) +void ffmpeg_log_callback(void *ptr, int level, const char *format, va_list arg) { - static int ffmpeg_init = 0; - if (!ffmpeg_init) { - ffmpeg_init = 1; - av_register_all(); - avdevice_register_all(); - if ((G.debug & G_DEBUG_FFMPEG) == 0) { - silence_log_ffmpeg(1); - } - else { - silence_log_ffmpeg(0); - } + if (ELEM(level, AV_LOG_FATAL, AV_LOG_ERROR)) { + size_t n = BLI_vsnprintf(ffmpeg_last_error, sizeof(ffmpeg_last_error), format, arg); + + /* strip trailing \n */ + ffmpeg_last_error[n - 1] = '\0'; } + + /* call default logger to print all message to console */ + av_log_default_callback(ptr, level, format, arg); +} + +void IMB_ffmpeg_init(void) +{ + av_register_all(); + avdevice_register_all(); + + if ((G.debug & G_DEBUG_FFMPEG) == 0) { + silence_log_ffmpeg(1); + } + else { + silence_log_ffmpeg(0); + } + + ffmpeg_last_error[0] = '\0'; + + /* set own callback which could store last error to report to UI */ + av_log_set_callback(ffmpeg_log_callback); +} + +const char *IMB_ffmpeg_last_error(void) +{ + return ffmpeg_last_error; } static int isffmpeg(const char *filename) @@ -255,8 +278,6 @@ static int isffmpeg(const char *filename) AVCodec *pCodec; AVCodecContext *pCodecCtx; - do_init_ffmpeg(); - if (BLI_testextensie(filename, ".swf") || BLI_testextensie(filename, ".jpg") || BLI_testextensie(filename, ".png") || |