Comprehensive video handling with social.plus SDK including upload, transcoding, streaming, and multi-resolution support
social.plus provides advanced video handling capabilities with automatic transcoding, multi-resolution support, and streaming optimization. This guide covers everything from basic uploads to advanced video processing workflows.
Video Limits: Maximum file size is 2GB per video. Supported formats: MP4, MOV, and AVI with automatic transcoding to optimized MP4 versions.
Upload videos with automatic transcoding, progress tracking, and format optimization. The SDK handles video compression and generates multiple resolutions for adaptive streaming.
Videos are automatically transcoded to multiple resolutions in the background. Use the status property to track transcoding progress.
Copy
Ask AI
// Note: videoUrl must be a local file url.func uploadVideoExample(videoUrl: URL) async { do { let video = try await fileRepository.uploadVideo(with: videoUrl, progress: { progress in print("uploading progress: \(progress)") }) print("uploading finish successfully: fileId \(String(describing: video.fileId))") } catch { // Handle error here }}
let fileRepository = AmityFileRepository(client: client)do { // Get AmityRawFile let rawFile = try await fileRepository.getFile(fileId: "<video-file-id>") // Transform AmityRawFile to specific AmityVideoData. // If AmityRawFile is not the type `video`, it will return nil. if rawFile.type == .video { guard let videoData = rawFile.mapToVideoData() else { return } let resolutions: [AmityVideoResolution] = Array(videoData.videoUrls.keys).sorted() for resolution in resolutions { if let fileUrl = videoData.getVideo(resolution: resolution) { // url of each video // Download the video by using fileDownload api or // You can use any network client to download the video. let path = try await fileRepository.downloadFile(fromURL: fileUrl) print("Video file downloaded to local path: \(path)") } } }} catch { // Handle error here}
social.plus automatically generates video thumbnails for preview purposes. Thumbnails are created during the transcoding process and provide visual previews for video content.
Thumbnails are generated asynchronously during transcoding. Check the transcoding status before accessing thumbnail URLs.
Copy
Ask AI
let fileRepository = AmityFileRepository(client: client) ... func downloadVideoThumbnailAsData(from message: AmityMessage) { guard let thumbnailFileId = message.data?["thumbnailFileId"] as? String, !thumbnailFileId.isEmpty, let imageInfo = message.getVideoThumbnailImageInfo() else { return } // Download from url and return saved image url. fileRepository.downloadImage(fromURL: imageInfo.fileURL, size: .small) { imageUrl, error in // Handle image url and error. } } func downloadVideoThumbnailAsUIImage(from message: AmityMessage) { guard let thumbnailFileId = message.data?["thumbnailFileId"] as? String, !thumbnailFileId.isEmpty, let imageInfo = message.getVideoThumbnailImageInfo() else { return } // Download from url and return image. fileRepository.downloadImageAsData(fromURL: imageInfo.fileURL, size: .small) { image, size, error in // Handle image and error. } }