203
static int isavi (const char *name)
212
static int isavi(const char *name)
205
return AVI_is_avi (name);
215
return AVI_is_avi(name);
208
222
#ifdef WITH_QUICKTIME
209
static int isqtime (const char *name)
223
static int isqtime(const char *name)
211
return anim_is_quicktime (name);
225
return anim_is_quicktime(name);
215
229
#ifdef WITH_FFMPEG
217
void silence_log_ffmpeg(int quiet)
220
av_log_set_level(AV_LOG_QUIET);
223
av_log_set_level(AV_LOG_DEBUG);
227
extern void do_init_ffmpeg(void);
228
void do_init_ffmpeg(void)
230
static int ffmpeg_init = 0;
234
avdevice_register_all();
235
if ((G.debug & G_DEBUG_FFMPEG) == 0) {
236
silence_log_ffmpeg(1);
239
silence_log_ffmpeg(0);
244
static int isffmpeg (const char *filename)
246
AVFormatContext *pFormatCtx;
232
#define va_copy(dst, src) ((dst) = (src))
235
/* BLI_vsnprintf in ffmpeg_log_callback() causes invalid warning */
237
# pragma GCC diagnostic push
238
# pragma GCC diagnostic ignored "-Wmissing-format-attribute"
241
static char ffmpeg_last_error[1024];
243
static void ffmpeg_log_callback(void *ptr, int level, const char *format, va_list arg)
245
if (ELEM(level, AV_LOG_FATAL, AV_LOG_ERROR)) {
251
n = BLI_vsnprintf(ffmpeg_last_error, sizeof(ffmpeg_last_error), format, arg2);
253
/* strip trailing \n */
254
ffmpeg_last_error[n - 1] = '\0';
257
if (G.debug & G_DEBUG_FFMPEG) {
258
/* call default logger to print all message to console */
259
av_log_default_callback(ptr, level, format, arg);
264
# pragma GCC diagnostic pop
267
void IMB_ffmpeg_init(void)
270
avdevice_register_all();
272
ffmpeg_last_error[0] = '\0';
274
/* set own callback which could store last error to report to UI */
275
av_log_set_callback(ffmpeg_log_callback);
278
const char *IMB_ffmpeg_last_error(void)
280
return ffmpeg_last_error;
283
static int isffmpeg(const char *filename)
285
AVFormatContext *pFormatCtx = NULL;
250
289
AVCodecContext *pCodecCtx;
254
if ( BLI_testextensie(filename, ".swf") ||
255
BLI_testextensie(filename, ".jpg") ||
256
BLI_testextensie(filename, ".png") ||
257
BLI_testextensie(filename, ".dds") ||
258
BLI_testextensie(filename, ".tga") ||
259
BLI_testextensie(filename, ".bmp") ||
260
BLI_testextensie(filename, ".exr") ||
261
BLI_testextensie(filename, ".cin") ||
262
BLI_testextensie(filename, ".wav")) return 0;
264
if (av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL)!=0) {
291
if (BLI_testextensie(filename, ".swf") ||
292
BLI_testextensie(filename, ".jpg") ||
293
BLI_testextensie(filename, ".png") ||
294
BLI_testextensie(filename, ".dds") ||
295
BLI_testextensie(filename, ".tga") ||
296
BLI_testextensie(filename, ".bmp") ||
297
BLI_testextensie(filename, ".exr") ||
298
BLI_testextensie(filename, ".cin") ||
299
BLI_testextensie(filename, ".wav"))
304
if (avformat_open_input(&pFormatCtx, filename, NULL, NULL) != 0) {
265
305
if (UTIL_DEBUG) fprintf(stderr, "isffmpeg: av_open_input_file failed\n");
269
if (av_find_stream_info(pFormatCtx)<0) {
270
if (UTIL_DEBUG) fprintf(stderr, "isffmpeg: av_find_stream_info failed\n");
309
if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {
310
if (UTIL_DEBUG) fprintf(stderr, "isffmpeg: avformat_find_stream_info failed\n");
271
311
av_close_input_file(pFormatCtx);
275
315
if (UTIL_DEBUG) av_dump_format(pFormatCtx, 0, filename, 0);
278
/* Find the first video stream */
280
for (i=0; i<pFormatCtx->nb_streams; i++)
318
/* Find the first video stream */
320
for (i = 0; i < pFormatCtx->nb_streams; i++)
281
321
if (pFormatCtx->streams[i] &&
282
pFormatCtx->streams[i]->codec &&
283
(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO))
322
pFormatCtx->streams[i]->codec &&
323
(pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO))
289
if (videoStream==-1) {
329
if (videoStream == -1) {
290
330
av_close_input_file(pFormatCtx);
294
334
pCodecCtx = pFormatCtx->streams[videoStream]->codec;
296
/* Find the decoder for the video stream */
297
pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
336
/* Find the decoder for the video stream */
337
pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
338
if (pCodec == NULL) {
299
339
av_close_input_file(pFormatCtx);
303
if (avcodec_open(pCodecCtx, pCodec)<0) {
343
if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) {
304
344
av_close_input_file(pFormatCtx);