Tous les produits
Search
Centre de documentation

Object Storage Service:Ingestion de flux RTMP

Dernière mise à jour :Aug 18, 2026

Object Storage Service (OSS) permet d'ingérer des flux vidéo encodés en H.264 et des flux audio encodés en AAC via le protocole Real-Time Messaging Protocol (RTMP). Vous pouvez utiliser les données audio et vidéo ingérées pour la vidéo à la demande ou la diffusion en direct. Cette rubrique explique comment ingérer des flux audio et vidéo dans OSS et comment lire les données ingérées.

Limites

  • Seule l'ingestion de flux RTMP est prise en charge. La récupération de flux n'est pas disponible.

  • Les données ingérées doivent contenir un flux vidéo au format H.264.

  • Un flux audio est facultatif. S'il est présent, il doit être au format AAC ; les autres formats sont ignorés.

  • Le vidage ne prend en charge que le protocole HTTP Live Streaming (HLS).

  • Un seul client peut ingérer un flux dans un LiveChannel à la fois.

Ingérer des données audio et vidéo dans OSS

  1. Obtenez une URL d'ingestion.

    Appelez l'opération API PutLiveChannel via un SDK pour créer un LiveChannel et obtenir son URL d'ingestion.

    • Si la liste de contrôle d'accès (ACL) du bucket est définie sur public-read-write, utilisez directement l'URL d'ingestion obtenue.

    • Si l'ACL du bucket est définie sur public-read ou private, vous devez signer l'URL. Pour plus d'informations, consultez Signature V1.

    Seuls les SDK Java et Python permettent d'obtenir des URL d'ingestion.

    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();
                }
            }
        }
    }

    Les URL d'ingestion renvoyées sont les suivantes :

    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)

    Les URL d'ingestion renvoyées sont les suivantes :

    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. Utilisez l'URL d'ingestion pour ingérer des données audio et vidéo dans OSS.

    La convention de nommage des fichiers générés par l'ingestion de flux est <channel-name><timestamp>.ts, où <channel-name> correspond au nom du canal et <timestamp> représente l'horodatage en millisecondes lors de la génération de la tranche de fichier.

    FFmpeg

    Utilisez FFmpeg pour ingérer un fichier vidéo local dans OSS. Par exemple :

    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. Installez OBS Studio.

    2. Dans la barre de navigation supérieure, choisissez .

    3. Dans le volet de navigation de gauche, cliquez sur Stream.

    4. Configurez les paramètres suivants dans la boîte de dialogue :

      Parameter

      Description

      Service

      Dans la liste déroulante, sélectionnez Custom.

      Server

      Saisissez l'URL de l'étape 1 sans les informations de signature d'ingestion de flux : rtmp://examplebucket.oss-cn-hangzhou.aliyuncs.com/live.

      Stream Key

      Saisissez les informations signées d'ingestion de flux obtenues à l'étape 1 : test-channel?playlistName=playlist.m3u8&OSSAccessKeyId=LTAI**************&Expires=1688543369&Signature=eqK8z0ZTSwznP7fkELy0ck********.

    5. Cliquez sur OK.

Lire les contenus audio et vidéo ingérés

Diffusion en direct

Pendant l'ingestion de flux, lisez le contenu via le protocole HLS. La méthode de lecture varie selon la plateforme :

  • Sur les plateformes mobiles telles qu'Android et iOS, ouvrez l'URL de lecture du LiveChannel dans un navigateur web.

  • Sur macOS, utilisez le navigateur Safari pour la lecture.

  • Sur PC, installez le lecteur multimédia VLC. Après l'installation, ouvrez VLC, choisissez , puis saisissez l'URL de lecture obtenue dans la zone de texte Please Enter A Network URL.

Pour assurer une diffusion en direct fluide, définissez une durée de fragment courte (par exemple, 2 secondes) et une taille de groupe d'images (GOP) correspondante. Dans OBS, ce paramètre s'appelle Keyframe Interval.

Dans OBS, accédez à Settings > Output. Définissez Output Mode sur Advanced. Dans l'onglet Streaming, définissez Keyframe Interval (seconds, 0=auto) sur 2.

Vidéo à la demande

Pendant l'ingestion de flux, OSS pousse ou met continuellement à jour le fichier M3U8 en tant que flux en direct. Une fois l'ingestion terminée, appelez l'opération API PostVodPlaylist pour créer une liste de lecture VOD. Utilisez l'URL de cette liste de lecture pour la lecture.

Pour les scénarios de vidéo à la demande, définissez une taille GOP plus grande afin de réduire le nombre de fichiers .ts, ce qui permet de diminuer le débit binaire.

Documents connexes