Esempio n. 1
0
static OSStatus finish_video(void)
{
    video_ready = 0;
    
    // ----- PixelBuffer -----
    CVPixelBufferRelease(pixelBuffer);

    // ----- Codec -----
    
    OSErr theError = ICMCompressionSessionCompleteFrames(videoCompressionSession, true, 0, 0);
    if (theError)
        log_debug("quicktime_video: error completing frames!");
        
    ICMCompressionSessionRelease(videoCompressionSession);
	
    // ----- Movie -----

    //End media editing
    theError = EndMediaEdits(videoMedia);
    if (theError)
        log_debug("quicktime_video: error ending media edits");

    theError = ExtendMediaDecodeDurationToDisplayEndTime(videoMedia, NULL);
    if (theError)
        log_debug("quicktime_video: error setting decode duration!");

    //Add media to track
    theError = InsertMediaIntoTrack(videoTrack, 0, 0, GetMediaDisplayDuration(videoMedia), fixed1);
    if (theError)
        log_debug("quicktime_video: error inserting media into track!");

    videoTrack=NULL;
    videoMedia=NULL;
    return theError;
}
Esempio n. 2
0
void qDestroyEncoderAPI(QEncoder* encoder)
{
    // push out any remaining frames before releasing the compression session.
    ICMCompressionSessionCompleteFrames(encoder->session, 1, 0, 0);

    ICMCompressionSessionRelease(encoder->session);
    CloseComponent(encoder->compressor);
    free(encoder);
}
Esempio n. 3
0
static ComponentResult _setup_cs(StreamInfoPtr si)
{
    ComponentResult err = noErr;
    ICMEncodedFrameOutputRecord efor;
    SInt32 tmpval = 0;

    dbg_printf("[ vOE]  >> [%08lx] :: _setup_cs()\n", (UInt32) -1);

    if (si->si_v.cs) {
        ICMCompressionSessionCompleteFrames(si->si_v.cs, true, 0, 0);
        ICMCompressionSessionRelease(si->si_v.cs);
        si->si_v.cs = NULL;
    }

    err = ICMCompressionSessionOptionsCreate(NULL, &si->si_v.cs_opts);
    if (err)
        goto bail;


    // We must set this flag to enable P or B frames.
    err = ICMCompressionSessionOptionsSetAllowTemporalCompression(si->si_v.cs_opts,
                                                                  true);
    dbg_printf("[ vOE]  ?1 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
    if (err)
        goto bail;

    // We must set this flag to enable B frames.
    err = ICMCompressionSessionOptionsSetAllowFrameReordering(si->si_v.cs_opts,
                                                              true);
    dbg_printf("[ vOE]  ?2 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
    if (err)
        goto bail;

    // Set the maximum key frame rate.
    err = ICMCompressionSessionOptionsSetMaxKeyFrameInterval(si->si_v.cs_opts,
                                                             si->si_v.keyrate);
    dbg_printf("[ vOE]  ?3 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
    if (err)
        goto bail;

    // This allows the compressor more flexibility
    //  (ie, dropping and coalescing frames).
    err = ICMCompressionSessionOptionsSetAllowFrameTimeChanges(si->si_v.cs_opts,
                                                               true);
    dbg_printf("[ vOE]  ?4 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
    if (err)
        goto bail;

    // We need durations when we store frames.
    err = ICMCompressionSessionOptionsSetDurationsNeeded(si->si_v.cs_opts, true);
    dbg_printf("[ vOE]  ?5 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
    if (err)
        goto bail;

    tmpval = si->si_v.quality;
    err = ICMCompressionSessionOptionsSetProperty(si->si_v.cs_opts,
                                                  kQTPropertyClass_ICMCompressionSessionOptions,
                                                  kICMCompressionSessionOptionsPropertyID_Quality,
                                                  sizeof(tmpval),
                                                  &tmpval);
    dbg_printf("[ vOE]  ?6 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
    if (err)
        goto bail;

    err = ICMCompressionSessionOptionsSetProperty(si->si_v.cs_opts,
                                                  kQTPropertyClass_ICMCompressionSessionOptions,
                                                  kICMCompressionSessionOptionsPropertyID_ExpectedFrameRate,
                                                  sizeof(si->si_v.fps),
                                                  &si->si_v.fps);
    dbg_printf("[ vOE]  ?7 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
    if (err)
        goto bail;

    tmpval = si->si_v.bitrate;
    err = ICMCompressionSessionOptionsSetProperty(si->si_v.cs_opts,
                                                  kQTPropertyClass_ICMCompressionSessionOptions,
                                                  kICMCompressionSessionOptionsPropertyID_AverageDataRate,
                                                  sizeof(tmpval),
                                                  &tmpval);
    dbg_printf("[ vOE]  ?8 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
    if (err)
        goto bail;

    if (si->si_v.custom != NULL) {
        err = ICMCompressionSessionOptionsSetProperty(si->si_v.cs_opts,
                                                      kQTPropertyClass_ICMCompressionSessionOptions,
                                                      kICMCompressionSessionOptionsPropertyID_CompressorSettings,
                                                      sizeof(si->si_v.custom),
                                                      &si->si_v.custom);
        dbg_printf("[ vOE]  ?9 [%08lx] :: _setup_cs() = %ld\n", (UInt32) -1, err);
        if (err)
            goto bail;
    }

    if (!err) {
        efor.encodedFrameOutputCallback = _frame_compressed;
        efor.encodedFrameOutputRefCon = (void *) si;
        efor.frameDataAllocator = NULL;

        err = ICMCompressionSessionCreate(NULL, si->si_v.width >> 16,
                                          si->si_v.height >> 16,
                                          kVideoFormatXiphTheora, /* fixed for now... */
                                          si->sourceTimeScale, si->si_v.cs_opts,
                                          NULL, &efor, &si->si_v.cs);
        dbg_printf("[ vOE]  ?A [%08lx] :: _setup_cs() = %ld [%lx x %lx]\n",
                   (UInt32) -1, err, si->si_v.width, si->si_v.height);
    }