Video Handling

Video Data

The video data is the representation of the video that has been uploaded using the SDK. The uploaded video will be transcoded to other different resolutions depending on console settings. Below is a table of properties that it contains.

PropertyDescription

fileId

Identifier for the uploaded file

fileUrl

The HTTP web URL for the uploaded file. You can use this fileUrl for downloading the original video file. (The file format remains unchanged)

attributes

Contains a dictionary with values for name, extension, size and mimeType of uploaded video.

attributes.metadata

Contains a dictionary with values for video and audio of uploaded video.

attributes.metadata.video

Contains a dictionary with values for width, height, duration, bit_rate, avg_frame_rate and display_aspect_ratio

attributes.metadata.audio

Contains a dictionary with values for duration, bit_rate and sample_rate

videoUrl

After video uploaded and transcoded by the server. The video data will contain videoUrl that provides different video URLs for each resolution.

  1. original - the equivalent resolution to fileUrl

  2. 1080p - 1920×1080 in horizontal, and 1080x1920 in vertical

  3. 720p - 1280×720 horizontal, and 720x1280 in vertical

  4. 480p - 640x480 horizontal, and 480x640 in vertical

  5. 360p - 480x360 horizontal, and 360x480 in vertical

(All transcoded videos are in MP4 format)

status

An enum represents 4 video statues

  1. uploaded - the video is uploaded and users can watch the original raw file on fileUrl

  2. transcoding - the video is being transcoded to pre-defined resolutions

  3. transcoded - the video is transcoded and the resolutions are provided to videoUrl

  4. error - the video encounters an issue while transcoding

The fileUrl and videoUrl.original provides the URL of the same video resolution. The difference being, fileUrl returns the actual file format while videoUrl.original returns MP4 format.

Upload Videos

To upload a video to the system, you can use the Amity Video Upload API provided the SDK. The API allows you to upload a video to the Amity server. The SDK simplifies the process of uploading videos by providing pre-built components that you can easily integrate into your application.

Retrieve Videos

Get a Specific Video Resolution

Once you uploaded a video the videos undergo transcoding from their original resolution. You can quickly access the original size of the video right after you make the video message. However, it takes time for the transcoded resolutions to be ready. Here are the available transcoded resolutions.

  • 1080p

  • 720p

  • 480p

  • 360p

  • original

Get a Video Thumbnail Image

Additionally, you can display a video preview in the user interface by utilizing a video thumbnail image. This allows for a more visually appealing representation of the video and provides a quick preview for users before they choose to view the full video. The thumbnail may not immediately available after the video was uploaded. However, eventually, the thumbnail will be become available.

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.
        }
    }

Last updated