~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/quicktime/apple/qtkit_export.m

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: qtkit_export.m 28242 2010-04-17 08:33:42Z damien78 $
3
 
 *
4
 
 * qtkit_export.m
5
 
 *
 
1
/*
6
2
 * Code to create QuickTime Movies with Blender
7
3
 *
8
4
 * ***** BEGIN GPL LICENSE BLOCK *****
38
34
#include "DNA_scene_types.h"
39
35
#include "DNA_userdef_types.h"
40
36
 
41
 
#include "AUD_C-API.h"
 
37
#ifdef WITH_AUDASPACE
 
38
#  include "AUD_C-API.h"
 
39
#endif
42
40
 
43
41
#include "BKE_global.h"
 
42
#include "BKE_main.h"
44
43
#include "BKE_scene.h"
45
44
#include "BKE_report.h"
46
45
 
107
106
/* Video codec */
108
107
static QuicktimeCodecTypeDesc qtVideoCodecList[] = {
109
108
        {kRawCodecType, 1, "Uncompressed"},
110
 
        {kJPEGCodecType, 2, "JPEG"},
111
 
        {kMotionJPEGACodecType, 3, "M-JPEG A"},
112
 
        {kMotionJPEGBCodecType, 4, "M-JPEG B"},
113
 
        {kDVCPALCodecType, 5, "DV PAL"},
114
 
        {kDVCNTSCCodecType, 6, "DV/DVCPRO NTSC"},
115
 
        {kDVCPROHD720pCodecType, 7, "DVCPRO HD 720p"},
116
 
        {kDVCPROHD1080i50CodecType, 8, "DVCPRO HD 1080i50"},
117
 
        {kDVCPROHD1080i60CodecType, 9, "DVCPRO HD 1080i60"},
118
 
        {kMPEG4VisualCodecType, 10, "MPEG4"},
119
 
        {kH263CodecType, 11, "H.263"},
120
 
        {kH264CodecType, 12, "H.264"},
 
109
        {k422YpCbCr8CodecType, 2, "Uncompressed 8-bit 4:2:2"},
 
110
        {k422YpCbCr10CodecType, 3, "Uncompressed 10-bit 4:2:2"},
 
111
        {kComponentVideoCodecType, 4, "Component Video"},
 
112
        {kPixletCodecType, 5, "Pixlet"},
 
113
        {kPNGCodecType, 6, "PNG"},
 
114
        {kJPEGCodecType, 7, "JPEG"},
 
115
        {kMotionJPEGACodecType, 8, "M-JPEG A"},
 
116
        {kMotionJPEGBCodecType, 9, "M-JPEG B"},
 
117
        {kDVCPALCodecType, 10, "DV PAL"},
 
118
        {kDVCNTSCCodecType, 11, "DV/DVCPRO NTSC"},
 
119
        {kDVCPROHD720pCodecType, 12, "DVCPRO HD 720p"},
 
120
        {kDVCPROHD1080i50CodecType, 13, "DVCPRO HD 1080i50"},
 
121
        {kDVCPROHD1080i60CodecType, 14, "DVCPRO HD 1080i60"},
 
122
        {kMPEG4VisualCodecType, 15, "MPEG4"},
 
123
        {kH263CodecType, 16, "H.263"},
 
124
        {kH264CodecType, 17, "H.264"},
 
125
        {kAnimationCodecType, 18, "Animation"},
121
126
        {0,0,NULL}};
122
127
 
123
 
static int qtVideoCodecCount = 12;
 
128
static int qtVideoCodecCount = 18;
124
129
 
125
 
int quicktime_get_num_videocodecs() {
 
130
int quicktime_get_num_videocodecs()
 
131
{
126
132
        return qtVideoCodecCount;
127
133
}
128
134
 
129
 
QuicktimeCodecTypeDesc* quicktime_get_videocodecType_desc(int indexValue) {
 
135
QuicktimeCodecTypeDesc* quicktime_get_videocodecType_desc(int indexValue)
 
136
{
130
137
        if ((indexValue>=0) && (indexValue < qtVideoCodecCount))
131
138
                return &qtVideoCodecList[indexValue];
132
139
        else
133
140
                return NULL;
134
141
}
135
142
 
136
 
int quicktime_rnatmpvalue_from_videocodectype(int codecType) {
 
143
int quicktime_rnatmpvalue_from_videocodectype(int codecType)
 
144
{
137
145
        int i;
138
146
        for (i=0;i<qtVideoCodecCount;i++) {
139
147
                if (qtVideoCodecList[i].codecType == codecType)
143
151
        return 0;
144
152
}
145
153
 
146
 
int quicktime_videocodecType_from_rnatmpvalue(int rnatmpvalue) {
 
154
int quicktime_videocodecType_from_rnatmpvalue(int rnatmpvalue)
 
155
{
147
156
        int i;
148
157
        for (i=0;i<qtVideoCodecCount;i++) {
149
158
                if (qtVideoCodecList[i].rnatmpvalue == rnatmpvalue)
163
172
 
164
173
static int qtAudioCodecCount = 4;
165
174
 
166
 
int quicktime_get_num_audiocodecs() {
 
175
int quicktime_get_num_audiocodecs()
 
176
{
167
177
        return qtAudioCodecCount;
168
178
}
169
179
 
170
 
QuicktimeCodecTypeDesc* quicktime_get_audiocodecType_desc(int indexValue) {
 
180
QuicktimeCodecTypeDesc* quicktime_get_audiocodecType_desc(int indexValue)
 
181
{
171
182
        if ((indexValue>=0) && (indexValue < qtAudioCodecCount))
172
183
                return &qtAudioCodecList[indexValue];
173
184
        else
174
185
                return NULL;
175
186
}
176
187
 
177
 
int quicktime_rnatmpvalue_from_audiocodectype(int codecType) {
 
188
int quicktime_rnatmpvalue_from_audiocodectype(int codecType)
 
189
{
178
190
        int i;
179
191
        for (i=0;i<qtAudioCodecCount;i++) {
180
192
                if (qtAudioCodecList[i].codecType == codecType)
184
196
        return 0;
185
197
}
186
198
 
187
 
int quicktime_audiocodecType_from_rnatmpvalue(int rnatmpvalue) {
 
199
int quicktime_audiocodecType_from_rnatmpvalue(int rnatmpvalue)
 
200
{
188
201
        int i;
189
202
        for (i=0;i<qtAudioCodecCount;i++) {
190
203
                if (qtAudioCodecList[i].rnatmpvalue == rnatmpvalue)
195
208
}
196
209
 
197
210
 
198
 
static NSString *stringWithCodecType(int codecType) {
 
211
static NSString *stringWithCodecType(int codecType)
 
212
{
199
213
        char str[5];
200
214
        
201
215
        *((int*)str) = EndianU32_NtoB(codecType);
204
218
        return [NSString stringWithCString:str encoding:NSASCIIStringEncoding];
205
219
}
206
220
 
207
 
void makeqtstring (RenderData *rd, char *string) {
 
221
void makeqtstring (RenderData *rd, char *string)
 
222
{
208
223
        char txt[64];
209
224
 
210
225
        strcpy(string, rd->pic);
211
 
        BLI_path_abs(string, G.sce);
 
226
        BLI_path_abs(string, G.main->name);
212
227
 
213
228
        BLI_make_existing_file(string);
214
229
 
215
230
        if (BLI_strcasecmp(string + strlen(string) - 4, ".mov")) {
216
 
                sprintf(txt, "%04d_%04d.mov", (rd->sfra) , (rd->efra) );
 
231
                sprintf(txt, "%04d-%04d.mov", (rd->sfra) , (rd->efra) );
217
232
                strcat(string, txt);
218
233
        }
219
234
}
220
235
 
221
 
void filepath_qt(char *string, RenderData *rd) {
 
236
void filepath_qt(char *string, RenderData *rd)
 
237
{
222
238
        if (string==NULL) return;
223
239
        
224
240
        strcpy(string, rd->pic);
225
 
        BLI_path_abs(string, G.sce);
 
241
        BLI_path_abs(string, G.main->name);
226
242
        
227
243
        BLI_make_existing_file(string);
228
244
        
229
245
        if (!BLI_testextensie(string, ".mov")) {
230
 
                /* if we dont have any #'s to insert numbers into, use 4 numbers by default */
 
246
                /* if we don't have any #'s to insert numbers into, use 4 numbers by default */
231
247
                if (strchr(string, '#')==NULL)
232
248
                        strcat(string, "####"); /* 4 numbers */
233
249
 
469
485
                                                qtexport->audioFile = NULL;
470
486
                                                [qtexport->audioFileName release];
471
487
                                                qtexport->audioFileName = nil;
472
 
                                        } else {
 
488
                                        }
 
489
                                        else {
473
490
                                                UInt32 prop,propSize;
474
491
                                                /* Set up codec properties */
475
492
                                                if (rd->qtcodecsettings.audiocodecType == kAudioFormatMPEG4AAC) { /*Lossy compressed format*/
519
536
                                        qtexport->movie = [[QTMovie alloc] initToWritableFile:qtexport->videoTempFileName error:&error];
520
537
 
521
538
                        }
522
 
                } else
 
539
                }
 
540
                else
523
541
                        qtexport->movie = [[QTMovie alloc] initToWritableFile:qtexport->filename error:&error];
524
542
                        
525
543
                if(qtexport->movie == nil) {
532
550
                        if (qtexport->videoTempFileName) [qtexport->videoTempFileName release];
533
551
                        qtexport->videoTempFileName = nil;
534
552
                        [QTMovie exitQTKitOnThread];
535
 
                } else {
 
553
                }
 
554
                else {
536
555
                        [qtexport->movie retain];
537
556
                        [qtexport->movie setAttribute:[NSNumber numberWithBool:YES] forKey:QTMovieEditableAttribute];
538
557
                        [qtexport->movie setAttribute:@"Made with Blender" forKey:QTMovieCopyrightAttribute];
581
600
        return success;
582
601
}
583
602
 
584
 
 
585
 
int append_qt(struct RenderData *rd, int frame, int *pixels, int rectx, int recty, ReportList *reports)
 
603
int append_qt(struct RenderData *rd, int start_frame, int frame, int *pixels, int rectx, int recty, ReportList *reports)
586
604
{
587
605
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
588
606
        NSBitmapImageRep *blBitmapFormatImage;
589
607
        NSImage *frameImage;
 
608
        OSStatus err = noErr;
590
609
        unsigned char *from_Ptr,*to_Ptr;
591
610
        int y,from_i,to_i;
592
611
        
593
 
        
594
612
        /* Create bitmap image rep in blender format (32bit RGBA) */
595
613
        blBitmapFormatImage = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
596
614
                                                                                                                                  pixelsWide:rectx 
628
646
        if (qtexport->audioFile) {
629
647
                UInt32 audioPacketsConverted;
630
648
                /* Append audio */
631
 
                while (((double)qtexport->audioTotalExportedFrames / (double) qtexport->audioInputFormat.mSampleRate)
632
 
                           < ((double)(frame - rd->sfra)) / (((double)rd->frs_sec) / rd->frs_sec_base)) {       
 
649
                while (qtexport->audioTotalExportedFrames < qtexport->audioLastFrame) { 
633
650
 
634
651
                        qtexport->audioBufferList.mNumberBuffers = 1;
635
652
                        qtexport->audioBufferList.mBuffers[0].mNumberChannels = qtexport->audioOutputFormat.mChannelsPerFrame;
637
654
                        qtexport->audioBufferList.mBuffers[0].mData = qtexport->audioOutputBuffer;
638
655
                        audioPacketsConverted = AUDIOOUTPUTBUFFERSIZE / qtexport->audioCodecMaxOutputPacketSize;
639
656
                        
640
 
                        AudioConverterFillComplexBuffer(qtexport->audioConverter, AudioConverterInputCallback,
 
657
                        err = AudioConverterFillComplexBuffer(qtexport->audioConverter, AudioConverterInputCallback,
641
658
                                                                                        NULL, &audioPacketsConverted, &qtexport->audioBufferList, qtexport->audioOutputPktDesc);
642
659
                        if (audioPacketsConverted) {
643
660
                                AudioFileWritePackets(qtexport->audioFile, false, qtexport->audioBufferList.mBuffers[0].mDataByteSize,
647
664
                                if (qtexport->audioOutputFormat.mFramesPerPacket) { 
648
665
                                        // this is the common case: format has constant frames per packet
649
666
                                        qtexport->audioTotalSavedFrames += (audioPacketsConverted * qtexport->audioOutputFormat.mFramesPerPacket);
650
 
                                } else {
 
667
                                }
 
668
                                else {
651
669
                                        unsigned int i;
652
670
                                        // if there are variable frames per packet, then we have to do this for each packeet
653
671
                                        for (i = 0; i < audioPacketsConverted; ++i)
656
674
                                
657
675
                                
658
676
                        }
 
677
                        else {
 
678
                                //Error getting audio packets
 
679
                                BKE_reportf(reports, RPT_ERROR, "Unable to get further audio packets from frame %i, error = 0x%x",(int)qtexport->audioTotalExportedFrames,err);
 
680
                                break;
 
681
                        }
 
682
 
659
683
                }
660
684
        }
661
685
        [pool drain];   
768
792
}
769
793
 
770
794
 
771
 
void free_qtcomponentdata(void) {
 
795
void free_qtcomponentdata(void)
 
796
{
772
797
}
773
798
 
774
 
void quicktime_verify_image_type(RenderData *rd)
 
799
void quicktime_verify_image_type(RenderData *rd, ImageFormatData *imf)
775
800
{
776
 
        if (rd->imtype == R_QUICKTIME) {
 
801
        if (imf->imtype == R_IMF_IMTYPE_QUICKTIME) {
777
802
                if ((rd->qtcodecsettings.codecType<= 0) ||
778
803
                        (rd->qtcodecsettings.codecSpatialQuality <0) ||
779
804
                        (rd->qtcodecsettings.codecSpatialQuality > 100)) {