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

Low Quality Video Capture #83

Closed
otymartin opened this issue Jun 17, 2017 · 13 comments
Closed

Low Quality Video Capture #83

otymartin opened this issue Jun 17, 2017 · 13 comments
Labels

Comments

@otymartin
Copy link

otymartin commented Jun 17, 2017

@piemonte
Hey the previous issue #34 was closed so I thought it necessary to bring this up again since i failed to fix it.

For whatever reason despite setting videoConfigured to high quality, I still get lowQuality output video when I play back using your other library Player.

I have these settings in my viewDidLoad so would appreciate further hints as to what could possible cause the bad video. Im using the latest version of this library.

self.nextLevel.delegate = self
        self.nextLevel.videoDelegate = self
        self.nextLevel.photoDelegate = self
        self.nextLevel.deviceDelegate = self
        self.nextLevel.captureMode = .video
        self.nextLevel.focusMode = .autoFocus
        self.nextLevel.devicePosition = .front
        self.nextLevel.deviceOrientation = .portrait
        self.nextLevel.videoStabilizationMode = .auto
        self.nextLevel.videoConfiguration.bitRate = 2000000
        self.nextLevel.videoConfiguration.preset = AVCaptureSessionPresetHigh
        self.nextLevel.videoConfiguration.transform = CGAffineTransform(scaleX: -1, y: 1)```
@piemonte piemonte added the bug label Aug 28, 2017
@piemonte
Copy link
Contributor

hey @otymartin thanks, will check this out when i get a chance

@yazeedabalkhail
Copy link

Hello there!

Was wondering if any update has happened on this, or if you found a workaround? Experiencing the same issue.

@otymartin @piemonte

@yazeedabalkhail
Copy link

yazeedabalkhail commented Dec 20, 2017

If it is any help with helping debugging the problem, here are a couple of tests i did on different presets:

1- When using presets low or medium --> You get the same results as expected (no pixelation)
2- When using presets high or hd etc --> You get pixelated, however the first second of displaying the video will not be pixelated
3- When using preset hd4K3840x2160 --> You get pixelated, however it is the lesser of all high preset options such as hd720, etc. Although still noticable
4- When using preset iFrame960x540 --> You get a video better then medium quality, without the pixelation happening

Hope this can help, thank you.

@otymartin
Copy link
Author

@yazeedabalkhail no had to use another lib. Would love to use this lib though so will come back to it and take on this issue again and see if i can figure it out.

@BrikerMan
Copy link
Contributor

I have the similar issue, is there any ways to improve video quality.

@klpl
Copy link

klpl commented Dec 24, 2017

I had the same issue. I resolved it by increasing the bitRate.

@otymartin
Copy link
Author

@klpl what did you increase it to?

@klpl
Copy link

klpl commented Dec 24, 2017

@otymartin
Copy link
Author

@klpl cool man, will try it out and see if this finally solves it.

@tungfam
Copy link

tungfam commented Feb 5, 2018

@klpl hi, could you please kindly share the code how you calculate bitsPerSecond?
from apple's docs it seems we need this:
CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions( videoFormatDescription )
in order to calculate it. But where can we get it from ? 😅

Will appreciate any help!

@klpl
Copy link

klpl commented Feb 5, 2018

@tungfam
In NextLevelConfiguration.swift > avcaptureSettingsDictionary method:
let numPixels = (config[AVVideoWidthKey] as! Int) * (config[AVVideoHeightKey] as! Int)
let bitsPerPixel = 10.1
let bitsPerSecond = Int(Double(numPixels) * bitsPerPixel)
[...]
compressionDict[AVVideoAverageBitRateKey] = NSNumber(integerLiteral: bitsPerSecond)

tungfam added a commit to tungfam/NextLevel that referenced this issue Feb 6, 2018
This change will fix the issue with bad video quality regardless of `videoConfiguration.preset` or `videoConfiguration.bitRate` being set.

A lot more details in this issue: NextLevel#83
@tungfam
Copy link

tungfam commented Feb 6, 2018

many thanks to @klpl I found out what fixes the issue and created a PR.

More details:

after few hours of testing and going around the code, I found out that no matter what value you set to NextLevel.shared.videoConfiguration.bitRate either 1 or 999999999 it will not affect the video quality.

then I applied the code that @klpl suggested. And checked again that changing NextLevel.shared.videoConfiguration.bitRate doesn't affect anything. But the video quality did become better.

Then I changed videoConfiguration.preset to .high or to .hd4K3840x2160 and the quality was just amazing 👌 .

@yazeedabalkhail thank you too!:) I was trying to use iFrame960x540 which was actually good (before I applied changes from PR). But then after fixing the issue the .high was better than iFrame960x540.

@piemonte first of all thanks a lot for a such cool lib!
please take a chance to review the PR.
Try testing it and you will see how better the video quality became. Please let me know if you have questions.

@piemonte
Copy link
Contributor

i added a better configuration to the sample project, hope that helps everyone.

050ba1b

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

No branches or pull requests

6 participants