All Products
Search
Document Center

Object Storage Service:RTMP stream ingest

Last Updated:Sep 17, 2025

OSS supports pushing H.264-encoded video streams and AAC-encoded audio streams using the Real-Time Messaging Protocol (RTMP). The ingested data can be used for video-on-demand or live streaming scenarios. This topic describes how to push audio and video streams to OSS and play the ingested data.

Limits

  • Only RTMP stream ingest is supported. Stream pulling is not supported.

  • The uploaded data must contain a video stream in H.264 format.

  • An audio stream is optional. If you include an audio stream, it must be in the AAC format. Audio streams in other formats are discarded.

  • Only the HTTP Live Streaming (HLS) protocol is supported for dumping.

  • Only one client can push a stream to a LiveChannel at a time.

Push audio and video data to OSS

  1. Obtain an ingest URL.

    Use an SDK to call the PutLiveChannel operation to create a LiveChannel and obtain its ingest URL.

    • If the access control list (ACL) of the bucket is set to public-read-write, you can use the obtained ingest URL directly for stream ingest.

    • If the bucket ACL is set to public-read or private, you must sign the URL. For more information about how to sign a URL, see Signature V1.

    Only the Java SDK and Python SDK support obtaining ingest URLs.

    Java

    import com.aliyun.oss.ClientException; import com.aliyun.oss.OSS; import com.aliyun.oss.OSSClientBuilder; import com.aliyun.oss.OSSException; import com.aliyun.oss.model.*; import java.util.List; import com.aliyun.oss.common.auth.*; import com.aliyun.oss.ClientBuilderConfiguration; import com.aliyun.oss.common.comm.SignVersion; public class Demo { public static void main(String[] args) throws Exception { String endpoint = "https://oss-cn-hangzhou.aliyuncs.com"; // Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set. EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider(); // Specify the bucket name. Example: examplebucket. String bucketName = "examplebucket"; // Specify the LiveChannel name. String liveChannelName = "yourLiveChannelName"; // Specify the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set Region to cn-hangzhou. String region = "cn-hangzhou"; // Create an OSSClient instance. // When the OSSClient instance is no longer used, call the shutdown method to release resources. ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration(); clientBuilderConfiguration.setSignatureVersion(SignVersion.V4); OSS ossClient = OSSClientBuilder.create() .endpoint(endpoint) .credentialsProvider(credentialsProvider) .clientConfiguration(clientBuilderConfiguration) .region(region) .build(); try { CreateLiveChannelRequest request = new CreateLiveChannelRequest(bucketName, liveChannelName, "desc", LiveChannelStatus.Enabled, new LiveChannelTarget()); CreateLiveChannelResult result = ossClient.createLiveChannel(request); // Obtain the ingest URLs. List<String> publishUrls = result.getPublishUrls(); for (String item : publishUrls) { // Obtain the ingest URL that does not contain signature information. System.out.println(item); // Obtain the ingest URL that contains signature information. LiveChannelInfo liveChannelInfo = ossClient.getLiveChannelInfo(bucketName, liveChannelName); // The expires parameter specifies the expiration time. The value is a UNIX timestamp. This example sets the expiration time to one hour from now. long expires = System.currentTimeMillis() / 1000 + 3600; // The playlistName parameter specifies the name passed in the CreateLiveChannel operation. If this parameter is not specified, the default value playlist.m3u8 is used. You can also call the GetLiveChannelInfo operation to obtain this name. String signRtmpUrl = ossClient.generateRtmpUri(bucketName, liveChannelName, liveChannelInfo.getTarget().getPlaylistName(), expires); System.out.println(signRtmpUrl); } // Obtain the playback URLs. List<String> playUrls = result.getPlayUrls(); for (String item : playUrls) { System.out.println(item); } } catch (OSSException oe) { oe.printStackTrace(); System.out.println("Caught an OSSException, which means your request made it to OSS, " + "but was rejected with an error response for some reason."); System.out.println("Error Message:" + oe.getErrorMessage()); System.out.println("Error Code:" + oe.getErrorCode()); System.out.println("Request ID:" + oe.getRequestId()); System.out.println("Host ID:" + oe.getHostId()); } catch (ClientException ce) { System.out.println("Caught an ClientException, which means the client encountered " + "a serious internal problem while trying to communicate with OSS, " + "such as not being able to access the network."); System.out.println("Error Message:" + ce.getMessage()); } finally { if (ossClient != null) { ossClient.shutdown(); } } } }

    The following ingest URLs are returned:

    rtmp://examplebucket.oss-cn-hangzhou.aliyuncs.com/live/test-channel rtmp://examplebucket.oss-cn-hangzhou.aliyuncs.com/live/test-channel?Expires=1688542428&OSSAccessKeyId=LTAI********&Signature=VfUgZt5N%2B6Uk4C9QH%2BzrRBTO2I****&playlistName=playlist.m3u8 http://examplebucket.oss-cn-hangzhou.aliyuncs.com/test-channel/playlist.m3u8

    Python

    # -*- coding: utf-8 -*- import oss2 from oss2.credentials import EnvironmentVariableCredentialsProvider # Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set. auth = oss2.ProviderAuth(EnvironmentVariableCredentialsProvider()) # Specify the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. # Specify the bucket name. Example: examplebucket. bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket') # Specify the LiveChannel name. Example: test-channel. channel_name = "test-channel" channel_cfg = oss2.models.LiveChannelInfo(target = oss2.models.LiveChannelInfoTarget()) channel = bucket.create_live_channel(channel_name, channel_cfg) publish_url = channel.publish_url # Generate a signed URL for RTMP stream ingest and set the expiration time to 3,600 seconds. signed_publish_url = bucket.sign_rtmp_url(channel_name, "playlist.m3u8", 3600) # Print the unsigned ingest URL. print('publish_url='+publish_url) # Print the signed ingest URL. print('signed_publish_url='+signed_publish_url)

    The following ingest URLs are returned:

    publish_url=rtmp://examplebucket.oss-cn-hangzhou.aliyuncs.com/live/test-channel signed_publish_url=rtmp://examplebucket.oss-cn-hangzhou.aliyuncs.com/live/test-channel?playlistName=playlist.m3u8&OSSAccessKeyId=LTAI********&Expires=1688543369&Signature=eqK8z0ZTSwznP7fkELy0ckt0Iv****
  2. Use the ingest URL to push audio and video data to OSS.

    Use FFmpeg for stream ingest

    You can use FFmpeg to push a local video file to OSS. For example:

    ffmpeg -i 1.flv -c copy -f flv "rtmp://examplebucket.oss-cn-hangzhou.aliyuncs.com/live/test-channel?playlistName=playlist.m3u8&OSSAccessKeyId=LTAI********&Expires=1688543369&Signature=eqK8z0ZTSwznP7fkELy0ckt0Iv***"

    Use OBS for stream ingest

    1. Install OBS Studio.

    2. In the top navigation bar, choose File > Settings.

    3. In the navigation pane on the left, click Stream.

    4. In the dialog box that appears, configure the parameters as described in the following table.

      Parameter

      Description

      Service

      From the drop-down list, select Custom.

      Server

      Enter the ingest URL obtained in Step 1 that does not contain signature information: rtmp://examplebucket.oss-cn-hangzhou.aliyuncs.com/live.

      Stream Key

      Enter the signed ingest information obtained in Step 1: test-channel?playlistName=playlist.m3u8&OSSAccessKeyId=LTAI**************&Expires=1688543369&Signature=eqK8z0ZTSwznP7fkELy0ck********.

    5. Click OK.

Play audio and video data pushed to OSS

Live streaming scenario

During stream ingest, you can use the HLS protocol to play the ingested content. The playback methods vary based on the platform:

  • On mobile platforms such as Android and iOS, enter the playback URL of the LiveChannel in a browser.

  • On macOS, use the Safari browser for playback.

  • On a PC, install VLC media player for playback. After the installation is complete, open VLC media player, choose Media > Open Network Stream..., and then enter the playback URL `play_url` in the Please Enter A Network URL text box.

For smooth live streaming, set a small `FragDuration`, such as 2 s. In addition, set the size of the group of pictures (GOP) to be the same as the `FragDuration` of the LiveChannel. To set the GOP (or keyframe Interval) in OBS, follow these steps:

Video-on-demand scenario

During stream ingest, OSS continuously pushes and updates the M3U8 file as a live stream. After the stream ingest is complete, you must call the PostVodPlaylist operation to assemble an M3U8 file for video-on-demand playback. You can then use the URL of this file for playback.

For video-on-demand scenarios, you can set a larger GOP to reduce the number of TS files and decrease the bitrate.

References