How to modify the SDK's default image and video compression settings?

Description

When sending images and short videos using the Android/iOS IMLib/IMKit SDK, the SDK has these default behaviors:

  • Image thumbnails: The SDK creates a large image at 30% quality from the original, meeting standard size requirements before upload. The longest side after compression won’t exceed 240 px. Thumbnails are used in the chat UI.
  • Images: If the original image isn’t selected for sending, the SDK creates a large image at 85% quality from the original, meeting standard size requirements before upload. The longest side after compression won’t exceed 1080 px.
  • Short video thumbnails: A thumbnail is generated from the first frame of the short video, using the same method as image thumbnails.
  • Short videos: The short video file is compressed to a resolution of 544 * 960.

Your app might need to adjust the SDK’s default compression settings.

Analysis

Modifying the SDK’s default settings isn’t recommended. Potential issues include:

  • Increasing thumbnail quality may enlarge the message content. If it exceeds the 128 KB limit, sending may fail.
  • Increasing the compression ratio for original images or short videos may result in larger files, increasing upload time and causing slow sending.

Solution

If changes are necessary, test them thoroughly in your development environment.

Android side

  1. Create a configuration file in your app directory: /src/main/res/values/rc_configuration.xml.

  2. Copy the following content into the new rc_configuration.xml file.

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
        <!--Image compression ratio-->
        <integer name="rc_image_quality">85</integer>
        <!--Image compression width and height-->
        <integer name="rc_image_size">1080</integer>
    
        <!--Send the original image if it’s under 200k-->
        <integer name="rc_max_original_image_size">200</integer>
    
        <!--Thumbnail compression ratio for images and short videos-->
        <integer name="rc_thumb_quality">30</integer>
        <!--Thumbnail compression width and height-->
        <integer name="rc_thumb_compress_size">240</integer>
        <!--Minimum thumbnail compression width and height-->
        <integer name="rc_thumb_compress_min_size">100</integer>
    
        <!--Short video compression width, use multiples of 16-->
        <integer name="rc_sight_compress_width">544</integer>
        <!--Short video compression height, use multiples of 16-->
        <integer name="rc_sight_compress_height">960</integer>
    
    </resources>
    

iOS side

Modify the SDK’s configuration file: /imlibcore/RongIMLibCore/RCConfig.plist. Note: This configuration will be overwritten after an SDK upgrade.

  • Modify image settings under the Image key.
  • Modify short video settings under the Sight key.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Location</key>
	<dict>
		<key>LocationImageQuality</key>
		<real>0.7</real>
		<key>LocationImageWidth</key>
		<string>480</string>
		<key>LocationImageHeight</key>
		<string>240</string>
	</dict>
	<key>File</key>
	<dict>
		<key>RelativePath</key>
		<string>Documents/MyFile</string>
		<key>MaxRangeUnit</key>
		<real>1048576</real>
	</dict>
	<key>Voice</key>
	<dict>
		<key>AudioEncodingBitRate</key>
		<real>7950</real>
	</dict>
	<key>Image</key>
	<dict>
		<key>ThumbnailQuality</key>
		<string>0.3</string>
		<key>ThumbnailMaxSize</key>
		<string>240</string>
		<key>ThumbnailMinSize</key>
		<string>100</string>
		<key>ImageQuality</key>
		<real>0.85</real>
		<key>ImageWidth</key>
		<integer>1080</integer>
		<key>ImageHeight</key>
		<integer>1080</integer>
	</dict>
	<key>CustomerService</key>
	<dict>
		<key>SuspendWhenLeave</key>
		<true/>
	</dict>
	<key>Download</key>
	<dict>
		<key>DownloadSliceSize</key>
		<real>20971520</real>
	</dict>
	<key>Sight</key>
	<dict>
		<key>SightCompressWidth</key>
		<integer>540</integer>
		<key>SightCompressHeight</key>
		<integer>960</integer>
	</dict>
</dict>
</plist>

More support

If you have questions, feel free to submit a ticket.