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

FPS-reduction results in a cut off video #11

Open
trav-ma opened this issue Oct 28, 2023 · 1 comment
Open

FPS-reduction results in a cut off video #11

trav-ma opened this issue Oct 28, 2023 · 1 comment

Comments

@trav-ma
Copy link

trav-ma commented Oct 28, 2023

Seems like on any videos where framerate is reduced (for example, 30 to 24) the resulting video has like, 10% black frames at the end and the full video is cut off? I've had to comment this code out for now, sadly results in a bit larger video size. Hopefully can be fixed in the future.

Great package!

@trav-ma
Copy link
Author

trav-ma commented Oct 28, 2023

I tried to write frame dropping code that worked off a % difference between target and source:

        let dropFactor = Int(1.0 / 0.2) //example 20% frame rate drop
        
        videoInput.requestMediaDataWhenReady(on: videoCompressQueue) {
            while videoInput.isReadyForMoreMediaData {
                if let buffer = videoOutput.copyNextSampleBuffer() {
                    counter += 1
                    if counter % dropFactor == 0 {
                        // Drop this frame
                        CMSampleBufferInvalidate(buffer)
                        print("frame \(counter) dropped")
                    } else {
                        videoInput.append(buffer)
                        print("frame \(counter) added")
                    }
                } else {
                    videoInput.markAsFinished()
                    completion()
                    break
                }
            }
        }

This actually works pretty well as far as video quality is concerned, however, I'm not seeing a file size drop at all compared to not dropping frames at all (same example, 30 fps to 24 fps).

When I use your code that more or less just drops 20% of the frames off the end of the video, I actually see a pretty significant file size drop. I'm not sure why.

Adding the above % code to the audio frame dropping gets me a very minor file size reduction but I haven't tested what the quality of the audio is like after the frame dropping.

Not sure... for now, I'll bypass frame dropping completely but please let me know if you can get this working properly with meaningful file size reduction whenever you do a future update. Thanks!

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

1 participant