Giter Club home page Giter Club logo

Comments (16)

GiacomoLeopizzi avatar GiacomoLeopizzi commented on June 10, 2024 3

Hi! I had the same issue and I think I have a solution to propose.

I added a new ARFrameMode

@objc public enum ARFrameMode: Int {
    case auto    
    case aspectFit
    /// Recommended for iPhone X
    case aspectFill
    
    case viewAspectRatio
} 

And added this code to the bufferSize var in RenderArR.swift (line 40)

case .viewAspectRatio where view is UIView:
                let bufferWidth = CVPixelBufferGetWidth(raw)
                let bufferHeight = CVPixelBufferGetHeight(raw)
                let viewSize = (view as! UIView).bounds.size
                let targetSize = AVMakeRect(aspectRatio: viewSize, insideRect: CGRect(x: 0, y: 0, width: bufferWidth, height: bufferHeight)).size
                width = Int(targetSize.width)
                height = Int(targetSize.height)

In order to use AVMakeRect I imported AVFoundation in the same file.

@AFathi please let me know what you think about my solution. I think that in this way it's easy to support custom sizes of the recording cause the size is calculated based on the aspect ratio of the view.

Regards,
Giacomo Leopizzi

from arvideokit.

AFathi avatar AFathi commented on June 10, 2024

@GiacomoLeopizzi, great approach! Can you create a pull request with these changes?

Also the only thing I'd change is this the force wrapping part.
from this:

                let viewSize = (view as! UIView).bounds.size

to this:

                let viewSize = (view as? UIView)?.bounds.size ?? .zero

or have some kind of a guard statement.

from arvideokit.

GiacomoLeopizzi avatar GiacomoLeopizzi commented on June 10, 2024

@AFathi sure! I’ll do it today.
About the guard, I forced the cast cause I put a where in the case switch. If you think it’s not fine, I can add a guard of course!

from arvideokit.

GiacomoLeopizzi avatar GiacomoLeopizzi commented on June 10, 2024

@kellum42 the issue is solved in current version of the library.
Use:

recorder.contentMode = .viewAspectRatio

To record with same aspect ratio of the view you used to create the RecordAR instance.

Regards,
Giacomo

from arvideokit.

J-Arji avatar J-Arji commented on June 10, 2024

hey, I can't found "viewAspectRatio" in contentMode .
can you help me?
how can able to make the video a square ?
thanks

from arvideokit.

GiacomoLeopizzi avatar GiacomoLeopizzi commented on June 10, 2024

Sure @J-Arji
You should have something like

let view = ARSCNView()
// Add subview, setup constraints, etc
guard let recorder = RecordAR(ARSceneKit: view) else {         
    // do something...
}
recorder.contentMode = .viewAspectRatio

If you cannot find it please check you have the latest version of the library

from arvideokit.

GiacomoLeopizzi avatar GiacomoLeopizzi commented on June 10, 2024

In contentMode .viewAspectRatio the output video has the same aspect ratio of the view, so just make sure the view has 1:1 aspect ration and the output will have square frames.

from arvideokit.

J-Arji avatar J-Arji commented on June 10, 2024

i add this line

guard let recorder = RecordAR(ARSceneKit: sceneView) else {
            print("can not add recorder ")
            return
        }
        if ratioMode == .normal {
            recorder.contentMode = . viewAspectRatio
        } else if ratioMode == .story {
            recorder.contentMode = .aspectFill
            
        } else {
            recorder.contentMode = .auto
            
        }

but when I play record video it's fill

from arvideokit.

GiacomoLeopizzi avatar GiacomoLeopizzi commented on June 10, 2024

You should set the recorder.contentMode to .viewAspectRatio in order to get the output you want.

from arvideokit.

GiacomoLeopizzi avatar GiacomoLeopizzi commented on June 10, 2024

Of course the view itself has also to be 1:1

from arvideokit.

GiacomoLeopizzi avatar GiacomoLeopizzi commented on June 10, 2024

This should happen cause contentMode is not to .viewAspectRatio

from arvideokit.

J-Arji avatar J-Arji commented on June 10, 2024

but content mode is to .viewAspectRatio

I change it

from arvideokit.

GiacomoLeopizzi avatar GiacomoLeopizzi commented on June 10, 2024

Are you sure it's called? Cause I noticed you have an if block, maybe ratioMode is not .normal

from arvideokit.

J-Arji avatar J-Arji commented on June 10, 2024

when I breakpoint buffer size in write return
PHOTO-2020-04-24-13-34-58

but in RanderAr buffersize is 1080,1080

when I call again width and height it's ok
why ??

from arvideokit.

GiacomoLeopizzi avatar GiacomoLeopizzi commented on June 10, 2024

When you call again you mean on next frame or next recording (I mean you stop recording and start it again)?

from arvideokit.

J-Arji avatar J-Arji commented on June 10, 2024

yeah,
I understand why I have a problem.
I set recorder?.onlyRenderWhileRecording = false
when I start and stop is ok
I change onlyRenderWhileRecording to true and it's ok

but I think this part has a problem.

from arvideokit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.