Avplayer export session video size issue

Hi,

This issue I regarding AVPlayerItem rendering in mobile screens.

we have a scenario where we need to record a video with camera and send it to server and after successful upload we should be Able see the video in app with good quality.

while sending video to server we are exporting it to highest quality and also while sending video we are sending video's natural size in such a way that it looks good in mobile screens.

Ex : if we are sending video in 720*1080 , natural size is set as 360*640 so that it looks good in mobile screens

Issues
  1. when we are trying to render video from url with out scaling natural size we are not able to fit video in the complete screen.Video is stuck at one corner of the screen.

  2. When we are trying to fill video in the screen (scaling natural size ) we are not able to get good clarity video.

  3. This issue is not happening when we are uploading from library

Blockers
  1. how do I calculate the natural size of the video while assigning it to "renderSize" of "AVMutableVideoComposition"

  2. While calculating this scale ratio I should not loose clarity of the video and I should be able to receive as original one

Please let me know for the solutions

Thanks in advance
You can use the url of the video asset to make a AVURLAsset like this:

Code Block
let videoAsset = AVURLAsset(url : sourceURL)


Then you need to get the video track of your video (AVAssetTrack) like this:

Code Block
let videoAssetTrack = videoAsset.tracks(withMediaType: .video).first


then you can find its natural size :

Code Block
let naturalSize = videoAssetTrack.naturalSize


Hope it solves the problem of getting the natural size of the video.
Avplayer export session video size issue
 
 
Q