ios-gpuimage-plus icon indicating copy to clipboard operation
ios-gpuimage-plus copied to clipboard

when saving mov file the result is laggy

Open hassan0424 opened this issue 2 years ago • 2 comments

when saving mov(recorded by iphone, sample mov file downloaded from internet works fine) file the result is laggy. frame shows for 2sec pause for 0.1 sec again frame show for 2 sec repeat until end

i saw the code inside cge.framework. maybe modifying below codes can help to solve my issue, but dont know exactly what and how to modify it

- (BOOL)readNextVideoFrameFromOutput
{
    if(_readerVideoTrackOutput)
    {
        if(_videoAssetReader.status == AVAssetReaderStatusReading)
        {
            CMSampleBufferRef sampleBufferRef = [_readerVideoTrackOutput copyNextSampleBuffer];

            if(sampleBufferRef)
            {
                CMTime currentSampleTime = CMSampleBufferGetOutputPresentationTimeStamp(sampleBufferRef);

                if (_playAtActualSpeed)
                {
                    CMTime differenceFromLastFrame = CMTimeSubtract(currentSampleTime, _prevFrameTime);
                    CFAbsoluteTime currentActualTime = CFAbsoluteTimeGetCurrent();

                    CGFloat frameTimeDifference = CMTimeGetSeconds(differenceFromLastFrame);
                    CGFloat actualTimeDifference = currentActualTime - _prevActualFrameTime;

                    if (frameTimeDifference > actualTimeDifference)
                    {
                        usleep(1000000.0 * (frameTimeDifference - actualTimeDifference));
                    }

                    _prevFrameTime = currentSampleTime;
                    _prevActualFrameTime = CFAbsoluteTimeGetCurrent();
                }

                if(s_fpsLimit > 0)
                {
                    double currTime = CMTimeGetSeconds(currentSampleTime);
                    int maxFrameForNow = currTime * s_fpsLimit + 5;
                    if(s_fpsCount > maxFrameForNow)
                    {
                        ShopliveFilterSDK_NSLog(@"Too many frames, skip...");
                        CFRelease(sampleBufferRef);
                        return YES;
                    }
                    else
                    {
                        ++s_fpsCount;
                    }
                }
                
                CVImageBufferRef movieFrame = CMSampleBufferGetImageBuffer(sampleBufferRef);
                [self processVideoFrame:movieFrame sampleTime:currentSampleTime lastTime:_procFrameTime];
                _procFrameTime = currentSampleTime;

                CFRelease(sampleBufferRef);
                return YES;
            }
            else
            {
                _readerVideoTrackOutput = nil;
            }
        }
    }

    return NO;
}

hassan0424 avatar Dec 18 '23 09:12 hassan0424

How to see your problem? I tried on my device, not showing your problem. Please provide more info.

wysaid avatar Jan 05 '24 06:01 wysaid

How to see your problem? I tried on my device, not showing your problem. Please provide more info.

sorry it was my error, the result is fine, thks for the reply

hassan0424 avatar Jan 05 '24 07:01 hassan0424