twilio / video-quickstart-ios

Twilio Video Quickstart for iOS
https://www.twilio.com/docs/api/video
MIT License
460 stars 178 forks source link

Changing dimension size of local frames #516

Closed ksuhr1 closed 3 years ago

ksuhr1 commented 4 years ago

Description

Hello! I am trying to change the capture format dimensions of the local frame to width: 360 and height:480. I used the croppingRequest found on https://www.twilio.com/docs/video/video-source-apis, however it didn't crop or change the dimension size. I'm not sure if cropping is the best option because I don't really want to lose any information. I saw that there is a format provided 480 x 360, but thats the opposite of what I want. Any help would be great! Thank you!

Steps to Reproduce

Code

Screen Shot 2020-07-02 at 3 08 10 PM
piyushtank commented 4 years ago

@ksuhr1 - Most camera supports 480x360 format in built on iOS devices however you can check it by calling supportedFormatsForDevice on CameraSource. Also since the 640x480 and 480x360 has the same aspect ratio, I believe cropping will not be required.

Can you try modifying your code to following and let us know?

let frontDevice = TVICameraSource.captureDevice(for: .front)!
let formats = TVICameraSource.supportedFormats(for: frontDevice)

// We match 640x480 directly, since it is known to be supported by all devices.
var preferredFormat: TVIVideoFormat?
for format in formats {
    let theFormat = format as! TVIVideoFormat
    if theFormat.dimensions.width == 640,
        theFormat.dimensions.height == 480 {
        preferredFormat = theFormat
    }
}

guard let captureFormat = preferredFormat else {
    // The preferred format could not be found.
    return
}

// Request 480x360 as the output format
let outputFormat = TVIVideoFormat()
let dimension = captureFormat.dimensions.height
outputFormat.dimensions = CMVideoDimensions(width: 480, height: 360)

self.camera?.requestOutputFormat(outputFormat)
self.camera?.startCapture(with: frontDevice, 
                          format: captureFormat, 
                          completion: nil)
piyushtank commented 3 years ago

Closing the ticket assuming the problem due to no activity on the ticket. Feel free to reopen or open an another ticket if you have questions.