6 * ***** BEGIN GPL LICENSE BLOCK *****
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23 * All rights reserved.
25 * The Original Code is: all of this file.
27 * Contributor(s): none yet.
29 * ***** END GPL LICENSE BLOCK *****
32 /** \file blender/imbuf/intern/anim_movie.c
49 #undef AVIIF_KEYFRAME // redefined in AVI_avi.h
50 #undef AVIIF_LIST // redefined in AVI_avi.h
52 #define FIXCC(fcc) if (fcc == 0) fcc = mmioFOURCC('N', 'o', 'n', 'e'); \
53 if (fcc == BI_RLE8) fcc = mmioFOURCC('R', 'l', 'e', '8');
56 #include <sys/types.h>
66 #include "BLI_blenlib.h" /* BLI_remlink BLI_filesize BLI_addtail
67 BLI_countlist BLI_stringdec */
68 #include "BLI_utildefines.h"
70 #include "MEM_guardedalloc.h"
72 #include "DNA_userdef_types.h"
75 #include "BKE_global.h"
76 #include "BKE_depsgraph.h"
83 #if defined(_WIN32) || defined(__APPLE__)
84 #include "quicktime_import.h"
85 #endif /* _WIN32 || __APPLE__ */
86 #endif /* WITH_QUICKTIME */
88 #include "IMB_imbuf_types.h"
89 #include "IMB_imbuf.h"
91 #include "IMB_allocimbuf.h"
95 #include <libavformat/avformat.h>
96 #include <libavcodec/avcodec.h>
97 #include <libavutil/rational.h>
98 #include <libswscale/swscale.h>
100 #include "ffmpeg_compat.h"
105 #ifdef _WIN32 /* on windows we use the ones in extern instead */
106 #include "libredcode/format.h"
107 #include "libredcode/codec.h"
109 #include "libredcode/format.h"
110 #include "libredcode/codec.h"
118 #include <dmedia/moviefile.h>
120 static void movie_printerror(char * str) {
121 const char * errstr = mvGetErrorStr(mvGetErrno());
124 if (errstr) printf("%s: %s\n", str, errstr);
125 else printf("%s: returned error\n", str);
126 } else printf("%s\n", errstr);
129 static int startmovie(struct anim * anim) {
130 if (anim == 0) return(-1);
132 if ( mvOpenFile (anim->name, O_BINARY|O_RDONLY, &anim->movie ) != DM_SUCCESS ) {
133 printf("Can't open movie: %s\n", anim->name);
136 if ( mvFindTrackByMedium (anim->movie, DM_IMAGE, &anim->track) != DM_SUCCESS ) {
137 printf("No image track in movie: %s\n", anim->name);
138 mvClose(anim->movie);
142 anim->duration = mvGetTrackLength (anim->track);
143 anim->params = mvGetParams( anim->track );
145 anim->x = dmParamsGetInt( anim->params, DM_IMAGE_WIDTH);
146 anim->y = dmParamsGetInt( anim->params, DM_IMAGE_HEIGHT);
147 anim->interlacing = dmParamsGetEnum (anim->params, DM_IMAGE_INTERLACING);
148 anim->orientation = dmParamsGetEnum (anim->params, DM_IMAGE_ORIENTATION);
149 anim->framesize = dmImageFrameSize(anim->params);
151 anim->curposition = 0;
154 /*printf("x:%d y:%d size:%d interl:%d dur:%d\n", anim->x, anim->y, anim->framesize, anim->interlacing, anim->duration);*/
158 static ImBuf * movie_fetchibuf(struct anim * anim, int position) {
160 /* extern rectcpy(); */
162 unsigned int *rect1, *rect2;
164 if (anim == 0) return (0);
166 ibuf = IMB_allocImBuf(anim->x, anim->y, 24, IB_rect);
168 if ( mvReadFrames(anim->track, position, 1, ibuf->x * ibuf->y *
169 sizeof(int), ibuf->rect ) != DM_SUCCESS ) {
170 movie_printerror("mvReadFrames");
176 if (anim->interlacing == DM_IMAGE_INTERLACED_EVEN) {
177 rect1 = ibuf->rect + (ibuf->x * ibuf->y) - 1;
178 rect2 = rect1 - ibuf->x;
180 for (size = ibuf->x * (ibuf->y - 1); size > 0; size--){
186 if (anim->interlacing == DM_IMAGE_INTERLACED_EVEN)
189 rect2 = rect1 + ibuf->x;
191 for (size = ibuf->x * (ibuf->y - 1); size > 0; size--){
195 /*if (anim->orientation == DM_TOP_TO_BOTTOM) IMB_flipy(ibuf);*/
201 static void free_anim_movie(struct anim * anim) {
202 if (anim == NULL) return;
205 mvClose(anim->movie);
211 int ismovie(char *name) {
212 return (mvIsMovieFile(name) == DM_TRUE);
217 int ismovie(const char *UNUSED(name)) {
221 /* never called, just keep the linker happy */
222 static int startmovie(struct anim *UNUSED(anim)) { return 1; }
223 static ImBuf * movie_fetchibuf(struct anim *UNUSED(anim), int UNUSED(position)) { return NULL; }
224 static void free_anim_movie(struct anim *UNUSED(anim)) { ; }
229 # define PATHSEPERATOR '\\'
231 # define PATHSEPERATOR '/'
234 static int an_stringdec(const char *string, char* head, char *tail, unsigned short *numlen) {
235 unsigned short len,nume,nums=0;
241 for(i=len-1;i>=0;i--){
242 if (string[i]==PATHSEPERATOR) break;
243 if (isdigit(string[i])) {
256 strcpy(tail ,&string[nume+1]);
257 strcpy(head, string);
260 return ((int)atoi(&(string[nums])));
263 strcpy(head, string);
269 static void an_stringenc(char *string, const char *head, const char *tail, unsigned short numlen, int pic) {
270 BLI_stringenc(string, head, tail, numlen, pic);
273 static void free_anim_avi (struct anim *anim) {
274 #if defined(_WIN32) && !defined(FREE_WINDOWS)
278 if (anim == NULL) return;
279 if (anim->avi == NULL) return;
281 AVI_close (anim->avi);
282 MEM_freeN (anim->avi);
285 #if defined(_WIN32) && !defined(FREE_WINDOWS)
288 AVIStreamGetFrameClose(anim->pgf);
292 for (i = 0; i < anim->avistreams; i++){
293 AVIStreamRelease(anim->pavi[i]);
295 anim->avistreams = 0;
297 if (anim->pfileopen) {
298 AVIFileRelease(anim->pfile);
307 void IMB_free_anim_ibuf(struct anim * anim) {
308 if (anim == NULL) return;
310 if (anim->ibuf1) IMB_freeImBuf(anim->ibuf1);
311 if (anim->ibuf2) IMB_freeImBuf(anim->ibuf2);
313 anim->ibuf1 = anim->ibuf2 = NULL;
317 static void free_anim_ffmpeg(struct anim * anim);
320 static void free_anim_redcode(struct anim * anim);
323 void IMB_free_anim(struct anim * anim) {
325 printf("free anim, anim == NULL\n");
329 IMB_free_anim_ibuf(anim);
330 free_anim_movie(anim);
333 #ifdef WITH_QUICKTIME
334 free_anim_quicktime(anim);
337 free_anim_ffmpeg(anim);
340 free_anim_redcode(anim);
346 void IMB_close_anim(struct anim * anim) {
347 if (anim == NULL) return;
353 struct anim * IMB_open_anim( const char * name, int ib_flags) {
356 anim = (struct anim*)MEM_callocN(sizeof(struct anim), "anim struct");
358 strcpy(anim->name, name); /* fixme: possible buffer overflow here? */
359 anim->ib_flags = ib_flags;
365 static int startavi (struct anim *anim) {
368 #if defined(_WIN32) && !defined(FREE_WINDOWS)
370 int i, firstvideo = -1;
373 LPBITMAPINFOHEADER lpbi;
377 anim->avi = MEM_callocN (sizeof(AviMovie),"animavi");
379 if (anim->avi == NULL) {
380 printf("Can't open avi: %s\n", anim->name);
384 avierror = AVI_open_movie (anim->name, anim->avi);
386 #if defined(_WIN32) && !defined(FREE_WINDOWS)
387 if (avierror == AVI_ERROR_COMPRESSION) {
389 hr = AVIFileOpen(&anim->pfile, anim->name, OF_READ, 0L);
392 for (i = 0; i < MAXNUMSTREAMS; i++) {
393 if (AVIFileGetStream(anim->pfile, &anim->pavi[i], 0L, i) != AVIERR_OK) {
397 AVIStreamInfo(anim->pavi[i], &avis, sizeof(avis));
398 if ((avis.fccType == streamtypeVIDEO) && (firstvideo == -1)) {
399 anim->pgf = AVIStreamGetFrameOpen(anim->pavi[i], NULL);
404 anim->avi->header->TotalFrames = AVIStreamLength(anim->pavi[i]);
406 // get information about images inside the stream
407 l = sizeof(abFormat);
408 AVIStreamReadFormat(anim->pavi[i], 0, &abFormat, &l);
409 lpbi = (LPBITMAPINFOHEADER)abFormat;
410 anim->avi->header->Height = lpbi->biHeight;
411 anim->avi->header->Width = lpbi->biWidth;
413 FIXCC(avis.fccHandler);
415 printf("Can't find AVI decoder for type : %4.4hs/%4.4hs\n",
416 (LPSTR)&avis.fccType,
417 (LPSTR)&avis.fccHandler);
422 // register number of opened avistreams
423 anim->avistreams = i;
426 // Couldn't get any video streams out of this file
428 if ((anim->avistreams == 0) || (firstvideo == -1)) {
429 avierror = AVI_ERROR_FORMAT;
431 avierror = AVI_ERROR_NONE;
432 anim->firstvideo = firstvideo;
440 if (avierror != AVI_ERROR_NONE) {
441 AVI_print_error(avierror);
442 printf ("Error loading avi: %s\n", anim->name);
447 anim->duration = anim->avi->header->TotalFrames;
450 anim->x = anim->avi->header->Width;
451 anim->y = anim->avi->header->Height;
452 anim->interlacing = 0;
453 anim->orientation = 0;
454 anim->framesize = anim->x * anim->y * 4;
456 anim->curposition = 0;
459 /* printf("x:%d y:%d size:%d interl:%d dur:%d\n", anim->x, anim->y, anim->framesize, anim->interlacing, anim->duration);*/
464 static ImBuf * avi_fetchibuf (struct anim *anim, int position) {
469 if (anim == NULL) return (NULL);
471 #if defined(_WIN32) && !defined(FREE_WINDOWS)
472 if (anim->avistreams) {
473 LPBITMAPINFOHEADER lpbi;
476 lpbi = AVIStreamGetFrame(anim->pgf, position + AVIStreamStart(anim->pavi[anim->firstvideo]));
478 ibuf = IMB_ibImageFromMemory((unsigned char *) lpbi, 100, IB_rect);
486 ibuf = IMB_allocImBuf (anim->x, anim->y, 24, IB_rect);
488 tmp = AVI_read_frame (anim->avi, AVI_FORMAT_RGB32, position,
489 AVI_get_stream(anim->avi, AVIST_VIDEO, 0));
492 printf ("Error reading frame from AVI");
493 IMB_freeImBuf (ibuf);
497 for (y=0; y < anim->y; y++) {
498 memcpy (&(ibuf->rect)[((anim->y-y)-1)*anim->x], &tmp[y*anim->x],
505 ibuf->profile = IB_PROFILE_SRGB;
512 extern void do_init_ffmpeg(void);
514 static int startffmpeg(struct anim * anim) {
518 AVFormatContext *pFormatCtx;
519 AVCodecContext *pCodecCtx;
521 #ifdef FFMPEG_SWSCALE_COLOR_SPACE_SUPPORT
522 /* The following for color space determination */
523 int srcRange, dstRange, brightness, contrast, saturation;
525 const int *inv_table;
528 if (anim == 0) return(-1);
532 if(av_open_input_file(&pFormatCtx, anim->name, NULL, 0, NULL)!=0) {
536 if(av_find_stream_info(pFormatCtx)<0) {
537 av_close_input_file(pFormatCtx);
541 av_dump_format(pFormatCtx, 0, anim->name, 0);
544 /* Find the first video stream */
546 for(i=0; i<pFormatCtx->nb_streams; i++)
547 if(pFormatCtx->streams[i]->codec->codec_type
548 == AVMEDIA_TYPE_VIDEO) {
553 if(videoStream==-1) {
554 av_close_input_file(pFormatCtx);
558 pCodecCtx = pFormatCtx->streams[videoStream]->codec;
560 /* Find the decoder for the video stream */
561 pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
563 av_close_input_file(pFormatCtx);
567 pCodecCtx->workaround_bugs = 1;
569 if(avcodec_open(pCodecCtx, pCodec)<0) {
570 av_close_input_file(pFormatCtx);
574 anim->duration = ceil(pFormatCtx->duration
575 * av_q2d(pFormatCtx->streams[videoStream]->r_frame_rate)
580 anim->x = pCodecCtx->width;
581 anim->y = pCodecCtx->height;
582 anim->interlacing = 0;
583 anim->orientation = 0;
584 anim->framesize = anim->x * anim->y * 4;
586 anim->curposition = -1;
588 anim->pFormatCtx = pFormatCtx;
589 anim->pCodecCtx = pCodecCtx;
590 anim->pCodec = pCodec;
591 anim->videoStream = videoStream;
593 anim->pFrame = avcodec_alloc_frame();
594 anim->pFrameDeinterlaced = avcodec_alloc_frame();
595 anim->pFrameRGB = avcodec_alloc_frame();
597 if (avpicture_get_size(PIX_FMT_RGBA, anim->x, anim->y)
598 != anim->x * anim->y * 4) {
600 "ffmpeg has changed alloc scheme ... ARGHHH!\n");
601 avcodec_close(anim->pCodecCtx);
602 av_close_input_file(anim->pFormatCtx);
603 av_free(anim->pFrameRGB);
604 av_free(anim->pFrameDeinterlaced);
605 av_free(anim->pFrame);
606 anim->pCodecCtx = NULL;
610 if (anim->ib_flags & IB_animdeinterlace) {
611 avpicture_fill((AVPicture*) anim->pFrameDeinterlaced,
612 MEM_callocN(avpicture_get_size(
613 anim->pCodecCtx->pix_fmt,
615 "ffmpeg deinterlace"),
616 anim->pCodecCtx->pix_fmt, anim->x, anim->y);
619 if (pCodecCtx->has_b_frames) {
620 anim->preseek = 25; /* FIXME: detect gopsize ... */
625 anim->img_convert_ctx = sws_getContext(
626 anim->pCodecCtx->width,
627 anim->pCodecCtx->height,
628 anim->pCodecCtx->pix_fmt,
629 anim->pCodecCtx->width,
630 anim->pCodecCtx->height,
632 SWS_FAST_BILINEAR | SWS_PRINT_INFO,
635 if (!anim->img_convert_ctx) {
637 "Can't transform color space??? Bailing out...\n");
638 avcodec_close(anim->pCodecCtx);
639 av_close_input_file(anim->pFormatCtx);
640 av_free(anim->pFrameRGB);
641 av_free(anim->pFrameDeinterlaced);
642 av_free(anim->pFrame);
643 anim->pCodecCtx = NULL;
647 #ifdef FFMPEG_SWSCALE_COLOR_SPACE_SUPPORT
648 /* Try do detect if input has 0-255 YCbCR range (JFIF Jpeg MotionJpeg) */
649 if (!sws_getColorspaceDetails(anim->img_convert_ctx, (int**)&inv_table, &srcRange,
650 &table, &dstRange, &brightness, &contrast, &saturation)) {
652 srcRange = srcRange || anim->pCodecCtx->color_range == AVCOL_RANGE_JPEG;
653 inv_table = sws_getCoefficients(anim->pCodecCtx->colorspace);
655 if(sws_setColorspaceDetails(anim->img_convert_ctx, (int *)inv_table, srcRange,
656 table, dstRange, brightness, contrast, saturation)) {
658 printf("Warning: Could not set libswscale colorspace details.\n");
662 printf("Warning: Could not set libswscale colorspace details.\n");
669 static void ffmpeg_postprocess(struct anim * anim, ImBuf * ibuf,
672 AVFrame * input = anim->pFrame;
674 /* This means the data wasnt read properly,
675 this check stops crashing */
676 if (input->data[0]==0 && input->data[1]==0
677 && input->data[2]==0 && input->data[3]==0){
678 fprintf(stderr, "ffmpeg_fetchibuf: "
679 "data not read properly...\n");
683 if (anim->ib_flags & IB_animdeinterlace) {
684 if (avpicture_deinterlace(
686 anim->pFrameDeinterlaced,
689 anim->pCodecCtx->pix_fmt,
690 anim->pCodecCtx->width,
691 anim->pCodecCtx->height)
695 input = anim->pFrameDeinterlaced;
699 if (ENDIAN_ORDER == B_ENDIAN) {
700 int * dstStride = anim->pFrameRGB->linesize;
701 uint8_t** dst = anim->pFrameRGB->data;
702 int dstStride2[4] = { dstStride[0], 0, 0, 0 };
703 uint8_t* dst2[4] = { dst[0], 0, 0, 0 };
705 unsigned char* bottom;
708 sws_scale(anim->img_convert_ctx,
709 (const uint8_t * const *)input->data,
712 anim->pCodecCtx->height,
716 /* workaround: sws_scale bug
717 sets alpha = 0 and compensate
718 for altivec-bugs and flipy... */
720 bottom = (unsigned char*) ibuf->rect;
721 top = bottom + ibuf->x * (ibuf->y-1) * 4;
723 h = (ibuf->y + 1) / 2;
726 for (y = 0; y < h; y++) {
727 unsigned char tmp[4];
728 unsigned int * tmp_l =
732 for (x = 0; x < w; x++) {
742 *(unsigned int*) top = *tmp_l;
750 int * dstStride = anim->pFrameRGB->linesize;
751 uint8_t** dst = anim->pFrameRGB->data;
752 int dstStride2[4] = { -dstStride[0], 0, 0, 0 };
753 uint8_t* dst2[4] = { dst[0] + (anim->y - 1)*dstStride[0],
758 sws_scale(anim->img_convert_ctx,
759 (const uint8_t * const *)input->data,
762 anim->pCodecCtx->height,
766 r = (unsigned char*) ibuf->rect;
768 /* workaround sws_scale bug: older version of
769 sws_scale set alpha = 0... */
771 for (i = 0; i < ibuf->x * ibuf->y; i++) {
779 static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position) {
783 int64_t pts_to_search = 0;
786 int seek_by_bytes= 0;
787 int preseek_count = 0;
789 if (anim == 0) return (0);
791 ibuf = IMB_allocImBuf(anim->x, anim->y, 32, IB_rect);
793 avpicture_fill((AVPicture*) anim->pFrameRGB,
794 (unsigned char*) ibuf->rect,
795 PIX_FMT_RGBA, anim->x, anim->y);
797 if (position != anim->curposition + 1) {
798 if (position > anim->curposition + 1
800 && position - (anim->curposition + 1) < anim->preseek) {
801 while(av_read_frame(anim->pFormatCtx, &packet)>=0) {
802 if (packet.stream_index == anim->videoStream) {
803 avcodec_decode_video2(
805 anim->pFrame, &frameFinished,
812 av_free_packet(&packet);
813 if (position == anim->curposition+1) {
820 /* disable seek_by_bytes for now, since bitrates are guessed wrong!
821 also: MPEG2TS-seeking was fixed in later versions of ffmpeg, so problem
822 is somewhat fixed by now (until we add correct timecode management code...)
825 seek_by_bytes = !!(anim->pFormatCtx->iformat->flags & AVFMT_TS_DISCONT);
827 seek_by_bytes = FALSE;
830 if (position != anim->curposition + 1) {
832 av_q2d(anim->pFormatCtx->streams[anim->videoStream]
834 double pts_time_base = av_q2d(anim->pFormatCtx->streams[anim->videoStream]->time_base);
836 long long st_time = anim->pFormatCtx->start_time;
840 pos = position - anim->preseek;
844 preseek_count = position - pos;
846 pos *= anim->pFormatCtx->bit_rate / frame_rate;
849 pos = (long long) (position - anim->preseek)
850 * AV_TIME_BASE / frame_rate;
855 if (st_time != AV_NOPTS_VALUE) {
860 ret = av_seek_frame(anim->pFormatCtx, -1,
862 AVSEEK_FLAG_BACKWARD | (
865 | AVSEEK_FLAG_BYTE : 0));
867 fprintf(stderr, "error while seeking: %d\n", ret);
870 pts_to_search = (long long)
871 (((double) position) / pts_time_base / frame_rate);
872 if (st_time != AV_NOPTS_VALUE) {
873 pts_to_search += st_time / pts_time_base/ AV_TIME_BASE;
877 avcodec_flush_buffers(anim->pCodecCtx);
880 while(av_read_frame(anim->pFormatCtx, &packet)>=0) {
881 if(packet.stream_index == anim->videoStream) {
882 avcodec_decode_video2(anim->pCodecCtx,
883 anim->pFrame, &frameFinished,
886 if (seek_by_bytes && preseek_count > 0) {
890 if (frameFinished && !pos_found) {
892 if (!preseek_count) {
894 anim->curposition = position;
897 if (packet.dts >= pts_to_search) {
899 anim->curposition = position;
904 if(frameFinished && pos_found == 1) {
905 ffmpeg_postprocess(anim, ibuf, &filter_y);
906 av_free_packet(&packet);
911 av_free_packet(&packet);
914 if (filter_y && ibuf) {
918 ibuf->profile = IB_PROFILE_SRGB;
923 static void free_anim_ffmpeg(struct anim * anim) {
924 if (anim == NULL) return;
926 if (anim->pCodecCtx) {
927 avcodec_close(anim->pCodecCtx);
928 av_close_input_file(anim->pFormatCtx);
929 av_free(anim->pFrameRGB);
930 av_free(anim->pFrame);
932 if (anim->ib_flags & IB_animdeinterlace) {
933 MEM_freeN(anim->pFrameDeinterlaced->data[0]);
935 av_free(anim->pFrameDeinterlaced);
936 sws_freeContext(anim->img_convert_ctx);
945 static int startredcode(struct anim * anim) {
946 anim->redcodeCtx = redcode_open(anim->name);
947 if (!anim->redcodeCtx) {
950 anim->duration = redcode_get_length(anim->redcodeCtx);
955 static ImBuf * redcode_fetchibuf(struct anim * anim, int position) {
957 struct redcode_frame * frame;
958 struct redcode_frame_raw * raw_frame;
960 if (!anim->redcodeCtx) {
964 frame = redcode_read_video_frame(anim->redcodeCtx, position);
970 raw_frame = redcode_decode_video_raw(frame, 1);
972 redcode_free_frame(frame);
978 ibuf = IMB_allocImBuf(raw_frame->width * 2,
979 raw_frame->height * 2, 32, IB_rectfloat);
981 redcode_decode_video_float(raw_frame, ibuf->rect_float, 1);
986 static void free_anim_redcode(struct anim * anim) {
987 if (anim->redcodeCtx) {
988 redcode_close(anim->redcodeCtx);
989 anim->redcodeCtx = 0;
996 /* probeer volgende plaatje te lezen */
997 /* Geen plaatje, probeer dan volgende animatie te openen */
998 /* gelukt, haal dan eerste plaatje van animatie */
1000 static struct ImBuf * anim_getnew(struct anim * anim) {
1001 struct ImBuf *ibuf = NULL;
1003 if (anim == NULL) return(NULL);
1005 free_anim_movie(anim);
1006 free_anim_avi(anim);
1007 #ifdef WITH_QUICKTIME
1008 free_anim_quicktime(anim);
1011 free_anim_ffmpeg(anim);
1014 free_anim_redcode(anim);
1018 if (anim->curtype != 0) return (NULL);
1019 anim->curtype = imb_get_anim_type(anim->name);
1021 switch (anim->curtype) {
1023 ibuf = IMB_loadiffname(anim->name, anim->ib_flags);
1025 strcpy(anim->first, anim->name);
1030 if (startmovie(anim)) return (NULL);
1031 ibuf = IMB_allocImBuf (anim->x, anim->y, 24, 0); /* fake */
1034 if (startavi(anim)) {
1035 printf("couldnt start avi\n");
1038 ibuf = IMB_allocImBuf (anim->x, anim->y, 24, 0);
1040 #ifdef WITH_QUICKTIME
1042 if (startquicktime(anim)) return (0);
1043 ibuf = IMB_allocImBuf (anim->x, anim->y, 24, 0);
1048 if (startffmpeg(anim)) return (0);
1049 ibuf = IMB_allocImBuf (anim->x, anim->y, 24, 0);
1054 if (startredcode(anim)) return (0);
1055 ibuf = IMB_allocImBuf (8, 8, 32, 0);
1062 struct ImBuf * IMB_anim_previewframe(struct anim * anim) {
1063 struct ImBuf * ibuf = NULL;
1066 ibuf = IMB_anim_absolute(anim, 0);
1068 IMB_freeImBuf(ibuf);
1069 position = anim->duration / 2;
1070 ibuf = IMB_anim_absolute(anim, position);
1075 struct ImBuf * IMB_anim_absolute(struct anim * anim, int position) {
1076 struct ImBuf * ibuf = NULL;
1077 char head[256], tail[256];
1078 unsigned short digits;
1081 if (anim == NULL) return(NULL);
1083 filter_y = (anim->ib_flags & IB_animdeinterlace);
1085 if (anim->curtype == 0) {
1086 ibuf = anim_getnew(anim);
1091 IMB_freeImBuf(ibuf); /* ???? */
1095 if (position < 0) return(NULL);
1096 if (position >= anim->duration) return(NULL);
1098 switch(anim->curtype) {
1100 pic = an_stringdec(anim->first, head, tail, &digits);
1102 an_stringenc(anim->name, head, tail, digits, pic);
1103 ibuf = IMB_loadiffname(anim->name, IB_rect);
1105 anim->curposition = position;
1109 ibuf = movie_fetchibuf(anim, position);
1111 anim->curposition = position;
1112 IMB_convert_rgba_to_abgr(ibuf);
1113 ibuf->profile = IB_PROFILE_SRGB;
1117 ibuf = avi_fetchibuf(anim, position);
1119 anim->curposition = position;
1121 #ifdef WITH_QUICKTIME
1123 ibuf = qtime_fetchibuf(anim, position);
1125 anim->curposition = position;
1130 ibuf = ffmpeg_fetchibuf(anim, position);
1132 anim->curposition = position;
1133 filter_y = 0; /* done internally */
1138 ibuf = redcode_fetchibuf(anim, position);
1139 if (ibuf) anim->curposition = position;
1145 if (filter_y) IMB_filtery(ibuf);
1146 sprintf(ibuf->name, "%s.%04d", anim->name, anim->curposition + 1);
1154 int IMB_anim_get_duration(struct anim *anim) {
1155 return anim->duration;
1158 void IMB_anim_set_preseek(struct anim * anim, int preseek)
1160 anim->preseek = preseek;
1163 int IMB_anim_get_preseek(struct anim * anim)
1165 return anim->preseek;