~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/quicktime/apple/quicktime_export.c

  • 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: quicktime_export.c 28112 2010-04-10 09:31:41Z damien78 $
 
1
/*
3
2
 *
4
3
 * quicktime_export.c
5
4
 *
28
27
 * ***** END GPL LICENSE BLOCK *****
29
28
 */
30
29
 
 
30
/** \file blender/quicktime/apple/quicktime_export.c
 
31
 *  \ingroup quicktime
 
32
 */
 
33
 
 
34
 
31
35
#ifdef WITH_QUICKTIME
32
36
#if defined(_WIN32) || defined(__APPLE__)
33
37
#ifndef USE_QTKIT
40
44
 
41
45
#include "BKE_context.h"
42
46
#include "BKE_global.h"
 
47
#include "BKE_main.h"
43
48
#include "BKE_report.h"
44
49
#include "BKE_scene.h"
45
50
 
60
65
#include <Movies.h>
61
66
#include <QuickTimeComponents.h>
62
67
#include <TextUtils.h> 
 
68
#include <string.h>
 
69
#include <memory.h>
 
70
 
63
71
#endif /* _WIN32 */
64
72
 
65
73
#ifdef __APPLE__
140
148
 
141
149
static int qtVideoCodecCount = 12;
142
150
 
143
 
int quicktime_get_num_videocodecs() {
 
151
int quicktime_get_num_videocodecs()
 
152
{
144
153
        return qtVideoCodecCount;
145
154
}
146
155
 
147
 
QuicktimeCodecTypeDesc* quicktime_get_videocodecType_desc(int indexValue) {
 
156
QuicktimeCodecTypeDesc* quicktime_get_videocodecType_desc(int indexValue)
 
157
{
148
158
        if ((indexValue>=0) && (indexValue < qtVideoCodecCount))
149
159
                return &qtVideoCodecList[indexValue];
150
160
        else
151
161
                return NULL;
152
162
}
153
163
 
154
 
int quicktime_rnatmpvalue_from_videocodectype(int codecType) {
 
164
int quicktime_rnatmpvalue_from_videocodectype(int codecType)
 
165
{
155
166
        int i;
156
167
        for (i=0;i<qtVideoCodecCount;i++) {
157
168
                if (qtVideoCodecList[i].codecType == codecType)
161
172
        return 0;
162
173
}
163
174
 
164
 
int quicktime_videocodecType_from_rnatmpvalue(int rnatmpvalue) {
 
175
int quicktime_videocodecType_from_rnatmpvalue(int rnatmpvalue)
 
176
{
165
177
        int i;
166
178
        for (i=0;i<qtVideoCodecCount;i++) {
167
179
                if (qtVideoCodecList[i].rnatmpvalue == rnatmpvalue)
175
187
 
176
188
static void CheckError(OSErr err, char *msg, ReportList *reports)
177
189
{
178
 
        if(err != noErr) {
 
190
        if (err != noErr) {
179
191
                BKE_reportf(reports, RPT_ERROR, "%s: %d", msg, err);
180
192
        }
181
193
}
195
207
        // check if current scene already has qtcodec settings, and clear them
196
208
        if (qcd) {
197
209
                free_qtcodecdata(qcd);
198
 
        } else {
 
210
        }
 
211
        else {
199
212
                qcd = rd->qtcodecdata = MEM_callocN(sizeof(QuicktimeCodecData), "QuicktimeCodecData");
200
213
        }
201
214
 
225
238
                qcd->cdSize = mySize;
226
239
 
227
240
                GetCodecInfo (&ci, qtdata->gSpatialSettings.codecType, 0);
228
 
        } else {
 
241
        }
 
242
        else {
229
243
                BKE_reportf(reports, RPT_ERROR, "Quicktime: QT_SaveCodecSettingsToScene failed\n"); 
230
244
        }
231
245
 
253
267
        }
254
268
                
255
269
        // restore codecsettings to the quicktime component
256
 
        if(qcd->cdParms && qcd->cdSize) {
 
270
        if (qcd->cdParms && qcd->cdSize) {
257
271
                myErr = SCSetSettingsFromAtomContainer((GraphicsExportComponent)qtdata->theComponent, (QTAtomContainer)myHandle);
258
272
                if (myErr != noErr) {
259
273
                        BKE_reportf(reports, RPT_ERROR, "Quicktime: SCSetSettingsFromAtomContainer failed\n"); 
281
295
                rd->qtcodecsettings.minTemporalQuality = (qtdata->aDataRateSetting.minTemporalQuality * 100) / codecLosslessQuality;
282
296
                //Frame duration is already known (qtdata->aDataRateSetting.frameDuration)
283
297
                
284
 
        } else {
 
298
        }
 
299
        else {
285
300
                BKE_reportf(reports, RPT_ERROR, "Quicktime: QT_GetCodecSettingsFromScene failed\n"); 
286
301
        }
287
302
bail:
379
394
        SCTemporalSettings gTemporalSettings;
380
395
        OSErr err = noErr;
381
396
 
382
 
        qtexport->ibuf = IMB_allocImBuf (rectx, recty, 32, IB_rect, 0);
383
 
        qtexport->ibuf2 = IMB_allocImBuf (rectx, recty, 32, IB_rect, 0);
 
397
        qtexport->ibuf = IMB_allocImBuf (rectx, recty, 32, IB_rect);
 
398
        qtexport->ibuf2 = IMB_allocImBuf (rectx, recty, 32, IB_rect);
384
399
 
385
400
        err = NewGWorldFromPtr( &qtexport->theGWorld,
386
401
                                                        k32ARGBPixelFormat,
399
414
        // the new callback based api for proper encoding, but that's not
400
415
        // really compatible with rendering out frames sequentially
401
416
        gTemporalSettings = qtdata->gTemporalSettings;
402
 
        if(qtdata->gSpatialSettings.codecType == kH264CodecType) {
403
 
                if(gTemporalSettings.temporalQuality != codecMinQuality) {
 
417
        if (qtdata->gSpatialSettings.codecType == kH264CodecType) {
 
418
                if (gTemporalSettings.temporalQuality != codecMinQuality) {
404
419
                        BKE_reportf(reports, RPT_WARNING, "Only minimum quality compression supported for QuickTime H.264.\n");
405
420
                        gTemporalSettings.temporalQuality = codecMinQuality;
406
421
                }
443
458
 
444
459
        //parse RGBA bitmap into Quicktime's ARGB GWorld
445
460
        boxsize = rectx * recty;
446
 
        for( index = 0; index < boxsize; index++) {
 
461
        for ( index = 0; index < boxsize; index++) {
447
462
                to[0] = from[3];
448
463
                to[1] = from[0];
449
464
                to[2] = from[1];
488
503
489
504
 
490
505
 
491
 
void filepath_qt(char *string, RenderData *rd) {
 
506
void filepath_qt(char *string, RenderData *rd)
 
507
{
492
508
        char txt[64];
493
509
 
494
510
        if (string==0) return;
495
511
 
496
512
        strcpy(string, rd->pic);
497
 
        BLI_path_abs(string, G.sce);
 
513
        BLI_path_abs(string, G.main->name);
498
514
 
499
515
        BLI_make_existing_file(string);
500
516
 
501
517
        if (BLI_strcasecmp(string + strlen(string) - 4, ".mov")) {
502
 
                sprintf(txt, "%04d_%04d.mov", (rd->sfra) , (rd->efra) );
 
518
                sprintf(txt, "%04d-%04d.mov", (rd->sfra) , (rd->efra) );
503
519
                strcat(string, txt);
504
520
        }
505
521
}
506
522
 
507
523
 
508
 
int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, ReportList *reports) {
 
524
int start_qt(struct Scene *scene, struct RenderData *rd, int rectx, int recty, ReportList *reports)
 
525
{
509
526
        OSErr err = noErr;
510
527
 
511
528
        char name[2048];
519
536
#endif
520
537
        int success= 1;
521
538
 
522
 
        if(qtexport == NULL) qtexport = MEM_callocN(sizeof(QuicktimeExport), "QuicktimeExport");
 
539
        if (qtexport == NULL) qtexport = MEM_callocN(sizeof(QuicktimeExport), "QuicktimeExport");
523
540
 
524
 
        if(qtdata) {
525
 
                if(qtdata->theComponent) CloseComponent(qtdata->theComponent);
 
541
        if (qtdata) {
 
542
                if (qtdata->theComponent) CloseComponent(qtdata->theComponent);
526
543
                free_qtcomponentdata();
527
544
        }
528
545
 
529
546
        qtdata = MEM_callocN(sizeof(QuicktimeComponentData), "QuicktimeCodecDataExt");
530
547
 
531
 
        if(rd->qtcodecdata == NULL || rd->qtcodecdata->cdParms == NULL) {
 
548
        if (rd->qtcodecdata == NULL || rd->qtcodecdata->cdParms == NULL) {
532
549
                get_qtcodec_settings(rd, reports);
533
 
        } else {
 
550
        }
 
551
        else {
534
552
                qtdata->theComponent = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType);
535
553
 
536
554
                QT_GetCodecSettingsFromScene(rd, reports);
575
593
                                                &qtexport->theMovie );
576
594
        CheckError(err, "CreateMovieFile error", reports);
577
595
 
578
 
        if(err != noErr) {
 
596
        if (err != noErr) {
579
597
                BKE_reportf(reports, RPT_ERROR, "Unable to create Quicktime movie: %s", name);
580
598
                success= 0;
581
599
#ifdef __APPLE__
582
600
                ExitMoviesOnThread();
583
601
#endif
584
 
        } else {
 
602
        }
 
603
        else {
585
604
                //printf("Created QuickTime movie: %s\n", name);
586
605
 
587
606
                QT_CreateMyVideoTrack(rectx, recty, reports);
591
610
}
592
611
 
593
612
 
594
 
int append_qt(struct RenderData *rd, int frame, int *pixels, int rectx, int recty, ReportList *reports) {
 
613
int append_qt(struct RenderData *rd, int start_frame, int frame, int *pixels, int rectx, int recty, ReportList *reports)
 
614
{
595
615
        QT_DoAddVideoSamplesToMedia(frame, pixels, rectx, recty, reports);
596
616
        return 1;
597
617
}
598
618
 
599
619
 
600
 
void end_qt(void) {
 
620
void end_qt(void)
 
621
{
601
622
        OSErr err = noErr;
602
623
        short resId = movieInDataForkResID;
603
624
 
604
 
        if(qtexport->theMovie) {
 
625
        if (qtexport->theMovie) {
605
626
                QT_EndCreateMyVideoTrack(NULL);
606
627
 
607
628
                err = AddMovieResource (qtexport->theMovie, qtexport->resRefNum, &resId, qtexport->qtfilename);
613
634
                err = UpdateMovieResource(qtexport->theMovie, qtexport->resRefNum, resId, qtexport->qtfilename);
614
635
                CheckError(err, "UpdateMovieResource error", NULL);
615
636
 
616
 
                if(qtexport->resRefNum) CloseMovieFile(qtexport->resRefNum);
 
637
                if (qtexport->resRefNum) CloseMovieFile(qtexport->resRefNum);
617
638
 
618
639
                DisposeMovie(qtexport->theMovie);
619
640
 
620
641
                //printf("Finished QuickTime movie.\n");
621
642
        }
622
643
 
623
 
        ExitMoviesOnThread();
 
644
#ifdef __APPLE__
 
645
                ExitMoviesOnThread();
 
646
#endif
624
647
        
625
 
        if(qtexport) {
 
648
        if (qtexport) {
626
649
                MEM_freeN(qtexport);
627
650
                qtexport = NULL;
628
651
        }
629
652
}
630
653
 
631
654
 
632
 
void free_qtcomponentdata(void) {
633
 
        if(qtdata) {
634
 
                if(qtdata->theComponent) CloseComponent(qtdata->theComponent);
 
655
void free_qtcomponentdata(void)
 
656
{
 
657
        if (qtdata) {
 
658
                if (qtdata->theComponent) CloseComponent(qtdata->theComponent);
635
659
                MEM_freeN(qtdata);
636
660
                qtdata = NULL;
637
661
        }
646
670
        err = SCGetInfo(qtdata->theComponent, scTemporalSettingsType,   &qtdata->gTemporalSettings);
647
671
        CheckError(err, "SCGetInfo fr error", reports);
648
672
 
649
 
        if( (rd->frs_sec == 24 || rd->frs_sec == 30 || rd->frs_sec == 60) &&
650
 
                (qtdata->gTemporalSettings.frameRate == 1571553 ||
651
 
                 qtdata->gTemporalSettings.frameRate == 1964113 ||
652
 
                 qtdata->gTemporalSettings.frameRate == 3928227)) {;} 
 
673
        if ( (rd->frs_sec == 24 || rd->frs_sec == 30 || rd->frs_sec == 60) &&
 
674
            (qtdata->gTemporalSettings.frameRate == 1571553 ||
 
675
             qtdata->gTemporalSettings.frameRate == 1964113 ||
 
676
             qtdata->gTemporalSettings.frameRate == 3928227))
 
677
        {
 
678
                /* do nothing */
 
679
        }
653
680
        else {
654
681
                if (rd->frs_sec_base > 0)
655
682
                        qtdata->gTemporalSettings.frameRate = 
656
 
                        ((float)(rd->frs_sec << 16) / rd->frs_sec_base) ;
 
683
                        ((float)(rd->frs_sec << 16) / rd->frs_sec_base);
657
684
        }
658
685
        
659
686
        err = SCSetInfo(qtdata->theComponent, scTemporalSettingsType,   &qtdata->gTemporalSettings);
660
687
        CheckError( err, "SCSetInfo error", reports );
661
688
 
662
 
        if(qtdata->gTemporalSettings.frameRate == 1571553) {                    // 23.98 fps
 
689
        if (qtdata->gTemporalSettings.frameRate == 1571553) {                   // 23.98 fps
663
690
                qtdata->kVideoTimeScale = 24000;
664
691
                qtdata->duration = 1001;
665
 
        } else if (qtdata->gTemporalSettings.frameRate == 1964113) {    // 29.97 fps
 
692
        }
 
693
        else if (qtdata->gTemporalSettings.frameRate == 1964113) {      // 29.97 fps
666
694
                qtdata->kVideoTimeScale = 30000;
667
695
                qtdata->duration = 1001;
668
 
        } else if (qtdata->gTemporalSettings.frameRate == 3928227) {    // 59.94 fps
 
696
        }
 
697
        else if (qtdata->gTemporalSettings.frameRate == 3928227) {      // 59.94 fps
669
698
                qtdata->kVideoTimeScale = 60000;
670
699
                qtdata->duration = 1001;
671
 
        } else {
 
700
        }
 
701
        else {
672
702
                qtdata->kVideoTimeScale = (qtdata->gTemporalSettings.frameRate >> 16) * 100;
673
703
                qtdata->duration = 100;
674
704
        }
675
705
}
676
706
 
677
 
void quicktime_verify_image_type(RenderData *rd)
 
707
void quicktime_verify_image_type(RenderData *rd, ImageFormatData *imf)
678
708
{
679
 
        if (rd->imtype == R_QUICKTIME) {
 
709
        if (imf->imtype == R_IMF_IMTYPE_QUICKTIME) {
680
710
                if ((rd->qtcodecsettings.codecType== 0) ||
681
711
                        (rd->qtcodecsettings.codecSpatialQuality <0) ||
682
712
                        (rd->qtcodecsettings.codecSpatialQuality > 100)) {
695
725
{
696
726
        OSErr err = noErr;
697
727
                // erase any existing codecsetting
698
 
        if(qtdata) {
699
 
                if(qtdata->theComponent) CloseComponent(qtdata->theComponent);
 
728
        if (qtdata) {
 
729
                if (qtdata->theComponent) CloseComponent(qtdata->theComponent);
700
730
                free_qtcomponentdata();
701
731
        }
702
732
 
705
735
        qtdata->theComponent = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType);
706
736
 
707
737
        // get previous selected codecsetting, from qtatom or detailed settings
708
 
        if(rd->qtcodecdata && rd->qtcodecdata->cdParms) {
 
738
        if (rd->qtcodecdata && rd->qtcodecdata->cdParms) {
709
739
                QT_GetCodecSettingsFromScene(rd, reports);
710
 
        } else {
 
740
        }
 
741
        else {
711
742
                SCGetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting);
712
743
                SCGetInfo(qtdata->theComponent, scSpatialSettingsType,  &qtdata->gSpatialSettings);
713
744
                SCGetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings);
746
777
        RenderData *rd = &scene->r;
747
778
 
748
779
        // erase any existing codecsetting
749
 
        if(qtdata) {
750
 
                if(qtdata->theComponent) CloseComponent(qtdata->theComponent);
 
780
        if (qtdata) {
 
781
                if (qtdata->theComponent) CloseComponent(qtdata->theComponent);
751
782
                free_qtcomponentdata();
752
783
        }
753
784
        
756
787
        qtdata->theComponent = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType);
757
788
        
758
789
        // get previous selected codecsetting, from qtatom or detailed settings
759
 
        if(rd->qtcodecdata && rd->qtcodecdata->cdParms) {
 
790
        if (rd->qtcodecdata && rd->qtcodecdata->cdParms) {
760
791
                QT_GetCodecSettingsFromScene(rd, op->reports);
761
 
        } else {
 
792
        }
 
793
        else {
762
794
                SCGetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting);
763
795
                SCGetInfo(qtdata->theComponent, scSpatialSettingsType,  &qtdata->gSpatialSettings);
764
796
                SCGetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings);
814
846
        QT_SaveCodecSettingsToScene(rd, op->reports);
815
847
 
816
848
        // framerate jugglin'
817
 
        if(qtdata->gTemporalSettings.frameRate == 1571553) {                    // 23.98 fps
 
849
        if (qtdata->gTemporalSettings.frameRate == 1571553) {                   // 23.98 fps
818
850
                qtdata->kVideoTimeScale = 24000;
819
851
                qtdata->duration = 1001;
820
852
 
821
853
                rd->frs_sec = 24;
822
854
                rd->frs_sec_base = 1.001;
823
 
        } else if (qtdata->gTemporalSettings.frameRate == 1964113) {    // 29.97 fps
 
855
        }
 
856
        else if (qtdata->gTemporalSettings.frameRate == 1964113) {      // 29.97 fps
824
857
                qtdata->kVideoTimeScale = 30000;
825
858
                qtdata->duration = 1001;
826
859
 
827
860
                rd->frs_sec = 30;
828
861
                rd->frs_sec_base = 1.001;
829
 
        } else if (qtdata->gTemporalSettings.frameRate == 3928227) {    // 59.94 fps
 
862
        }
 
863
        else if (qtdata->gTemporalSettings.frameRate == 3928227) {      // 59.94 fps
830
864
                qtdata->kVideoTimeScale = 60000;
831
865
                qtdata->duration = 1001;
832
866
 
833
867
                rd->frs_sec = 60;
834
868
                rd->frs_sec_base = 1.001;
835
 
        } else {
 
869
        }
 
870
        else {
836
871
                double fps = qtdata->gTemporalSettings.frameRate;
837
872
 
838
873
                qtdata->kVideoTimeScale = 60000;
841
876
                if ((qtdata->gTemporalSettings.frameRate & 0xffff) == 0) {
842
877
                        rd->frs_sec = fps / 65536;
843
878
                        rd->frs_sec_base = 1.0;
844
 
                } else {
 
879
                }
 
880
                else {
845
881
                        /* we do our very best... */
846
882
                        rd->frs_sec = fps  / 65536;
847
883
                        rd->frs_sec_base = 1.0;
871
907
void SCENE_OT_render_data_set_quicktime_codec(wmOperatorType *ot)
872
908
{
873
909
        /* identifiers */
874
 
        ot->name= "Change codec";
875
 
        ot->description= "Change Quicktime codec Settings";
876
 
        ot->idname= "SCENE_OT_render_data_set_quicktime_codec";
 
910
        ot->name = "Change codec";
 
911
        ot->description = "Change Quicktime codec Settings";
 
912
        ot->idname = "SCENE_OT_render_data_set_quicktime_codec";
877
913
        
878
914
        /* api callbacks */
879
915
#if defined(__APPLE__) && defined(GHOST_COCOA)
880
916
        ot->exec = cocoa_request_qtcodec_settings;
881
917
#else
882
 
        ot->exec= request_qtcodec_settings;
 
918
        ot->exec = request_qtcodec_settings;
883
919
#endif
884
 
        ot->poll= ED_operator_setqtcodec;
 
920
        ot->poll = ED_operator_setqtcodec;
885
921
        
886
922
        /* flags */
887
 
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 
923
        ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
888
924
}
889
925
 
890
926
#endif /* USE_QTKIT */