Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when saving mov file the result is laggy #52

Open
hassan0424 opened this issue Dec 18, 2023 · 2 comments
Open

when saving mov file the result is laggy #52

hassan0424 opened this issue Dec 18, 2023 · 2 comments

Comments

@hassan0424
Copy link

hassan0424 commented Dec 18, 2023

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;
}
@wysaid
Copy link
Owner

wysaid commented Jan 5, 2024

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

@hassan0424
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants