Save Video
By default, VideoEditor SDK exports edited videos in the same resolution, as they were originally loaded into the editor, as long as no cropping operation was carried out. The base resolution of the input and thus output video can be modified with the initializer of the Video
object that is used to create a VideoEditViewController
.
You can immediately display the exported video. The final video is not stored in the camera roll. It is written to a temporary file by default but the export file URL can be changed which requires writing permissions to the specified destination. After a successful export, the delegate method gets called with the resulting video file URL and any further processing has to be handled there.
Configuration#
VideoEditor SDK offers the configuration of exported video codecs, bit rate, and file containers. It can be set on VideoEditViewControllerOptions
while setting up VideoEditViewController
. Export resolution and frame rate are determined when you provide the initial video to the VideoEditViewController
. On iOS, you have two options for video compression, which are H.264 or HEVC (H.265). You can also choose the VideoContainerFormat
. There are two supported formats, which are MP4 and MOV. The only difference between these formats is that MOV is a proprietary format by Apple, so to ensure maximum cross-platform compatibility, we recommend using MP4, which is set by default.
let configuration = Configuration { builder inbuilder.configureVideoEditViewController { options in// Setting the video container formatoptions.videoContainerFormat = .mp4// Setting the video codec to H.264 with bit rate of 3840 bits per secondoptions.videoCodec = .h264(withBitRate: 3840)}}
H.264#
When using H.264 you have multiple options to configure the video codec.
- Specify bit rate only:
options.videoCodec = .h264(withBitRate: 3840)
- Specify bit rate, profile, and level:
options.videoCodec = .h264(withBitRate: 3840, profile: .HighAutoLevel)
Bit rate#
Beware that the requested bit rate is the average bit rate and not the constant one. It depends on the video frame rate, resolution, and other factors, so it's not always possible to exactly match the bit rate we want. In the end, it will be close to the requested bit rate but not the same.
Profiles and levels#
H.264 implements different compression profiles, which can also be configured via profile parameters when setting up the codec. When a profile is set, there is a set of levels which define a set of performance constraints that the decoder must conform to be able to decode the video. A decoder that conforms to a given level must be able to decode all bitstreams encoded for that level and all lower levels. VideoEditor SDK supports the three most used profiles. To read each of these use-cases refer to the link here.
Profile | Level | Enum |
---|---|---|
Profile Baseline | Level Auto | Enum .BaselineAutoLevel |
Profile | Level 3.0 | Enum .BaselineLevel30 |
Profile | Level 3.1 | Enum .BaselineLevel31 |
Profile | Level 4.1 | Enum .BaselineLevel41 |
Profile Main | Level Auto | Enum .MainAutoLevel |
Profile | Level 3.0 | Enum .MainLevel30 |
Profile | Level 3.1 | Enum .MainLevel31 |
Profile | Level 3.2 | Enum .MainLevel32 |
Profile | Level 4.1 | Enum .MainLevel41 |
Profile High | Level Auto | Enum .HighAutoLevel |
Profile | Level 4.0 | Enum .HighLevel40 |
Profile | Level 4.1 | Enum .HighLevel41 |
HEVC (H.265)#
As said earlier HEVC (known also as H.265) is only supported on iOS 11 or later. Unfortunately, it doesn't support as much flexibility as H.264, but there is a parameter that you can configure to achieve different file size/quality that is suited to your needs.
To use HEVC as your video codec, you need to set options.videoCodec = .hevc(withQuality: 1.0)
, which means HEVC codec with quality value of 1 (lossless).
Quality value#
The quality value ranges from 0.0 to 1.0 and it tells the encoder what compression level is desired. Quality level value means low = 0.25, normal = 0.50, high = 0.75, and 1.0 implies lossless compression for the encoder. In HEVC, lossless encoding means that DCT transforms and quantization are bypassed but normal predictions are still used.