Tüm Ürünler
Search
Belge Merkezi

Object Storage Service:RTMP akış yayınlama

Son Güncelleme:Oct 01, 2026

Object Storage Service (OSS), Real-Time Messaging Protocol (RTMP) üzerinden H.264 kodlamalı video akışlarını ve AAC kodlamalı ses akışlarını almayı destekler. Alınan ses ve video verileri isteğe bağlı video veya canlı yayın için kullanılabilir. Bu konu, ses ve video akışlarının OSS'e nasıl alınacağını ve alınan verilerin nasıl oynatılacağını açıklar.

Sınırlamalar

  • Yalnızca RTMP akış yayınlama desteklenir. Akış çekme desteklenmez.

  • Alınan veriler H.264 formatında bir video akışı içermelidir.

  • Ses akışı isteğe bağlıdır. Ses akışı dahil edilirse AAC formatında olmalıdır; diğer formatlardaki akışlar atılır.

  • Döküm yalnızca HTTP Live Streaming (HLS) protokolünü destekler.

  • Bir anda yalnızca bir istemci bir LiveChannel'a akış gönderebilir.

Ses ve video verilerini OSS'e alma

  1. Bir yayınlama URL'si edinin.

    Bir LiveChannel oluşturmak ve yayınlama URL'sini almak için SDK kullanarak PutLiveChannel API işlemini çağırın.

    • Paketin erişim kontrol listesi (ACL) public-read-write ise, elde edilen yayınlama URL'sini doğrudan kullanabilirsiniz.

    • Paket ACL'si public-read veya private ise URL'yi imzalamanız gerekir. Daha fazla bilgi için bkz. Signature V1.

    Yalnızca Java ve Python SDK'ları yayınlama URL'leri almayı destekler.

    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 this 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. For 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 the 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 its 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 as a Unix timestamp. This example sets the expiration time to one hour from the current time.
                    long expires = System.currentTimeMillis() / 1000 + 3600;
                    // The playlistName parameter specifies the name that you passed when you called the createLiveChannel operation. If you do not specify this parameter, 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();
                }
            }
        }
    }

    Dönen yayınlama URL'leri aşağıdaki gibidir:

    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 this 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. For example, examplebucket.
    bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')
    # Specify the LiveChannel name. For 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)

    Dönen yayınlama URL'leri aşağıdaki gibidir:

    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. Ses ve video verilerini OSS'e almak için yayınlama URL'sini kullanın.

    Akış yayınlama ile oluşturulan dosyaların adlandırma kuralı <channel-name><timestamp>.ts şeklindedir; burada <channel-name> kanal adıdır ve <timestamp> dosya diliminin oluşturulduğu milisaniye cinsinden zaman damgasıdır.

    FFmpeg

    Yerel bir video dosyasını OSS'e almak için FFmpeg kullanabilirsiniz. Örneğin:

    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=eqK8z0ZTSwznP7fkELy0ck***"

    OBS

    1. OBS Studio yükleyin.

    2. Üst gezinme çubuğunda seçeneğini belirleyin.

    3. Sol gezinme bölmesinde Stream öğesine tıklayın.

    4. İletişim kutusunda aşağıdaki parametreleri yapılandırın:


      Parameter


      Description


      Service


      Açılan listeden Custom öğesini seçin.


      Server

      1. Adım adresindeki akış yayınlama imza bilgisi olmadan URL'yi girin: rtmp://examplebucket.oss-cn-hangzhou.aliyuncs.com/live.


      Stream Key

      1. Adım adresinde aldığınız imzalı akış yayınlama bilgilerini girin: test-channel?playlistName=playlist.m3u8&OSSAccessKeyId=LTAI**************&Expires=1688543369&Signature=eqK8z0ZTSwznP7fkELy0ck********.

    5. OK düğmesine tıklayın.

Alınan ses ve videoyu oynatma

Canlı yayın

Akış yayınlama sırasında içeriği HLS protokolünü kullanarak oynatabilirsiniz. Oynatma yöntemi platforma göre değişir:

  • Android ve iOS gibi mobil platformlarda LiveChannel oynatma URL'sini bir web tarayıcısında açın.

  • macOS'te oynatma için Safari tarayıcısını kullanabilirsiniz.

  • Bir bilgisayarda oynatma için VLC medya oynatıcıyı yükleyebilirsiniz. Yüklemeden sonra VLC medya oynatıcıyı açın, seçeneğini belirleyin ve ardından aldığınız oynatma URL'sini Please Enter A Network URL metin kutusuna girin.

Sorunsuz bir canlı yayın deneyimi için kısa bir FragDuration (örneğin 2 saniye) ve bununla eşleşen bir Grup Resim (GOP) boyutu ayarlayın. OBS'de bu ayar Keyframe Interval olarak adlandırılır.

OBS'de Settings > Output bölümüne gidin. Output Mode değerini Advanced olarak ayarlayın. Streaming sekmesinde Keyframe Interval (seconds, 0=auto) değerini 2 olarak ayarlayın.

İsteğe bağlı video

Akış yayınlama sırasında OSS, canlı bir akış olarak M3U8 dosyasını sürekli olarak iter veya günceller. Akış yayınlama işlemi sona erdiğinde, bir VOD oynatma listesi oluşturmak için PostVodPlaylist API işlemini çağırmanız gerekir. Oynatma için bu oynatma listesinin URL'sini kullanın.

İsteğe bağlı video senaryoları için, bit hızını düşürmeye yardımcı olan .ts dosyalarının sayısını azaltmak amacıyla daha büyük bir GOP ayarlayabilirsiniz.

İlgili belgeler