All Products
Search
Document Center

ApsaraVideo Live:Hasilkan URL ingest dan streaming

Last Updated:Apr 22, 2026

Untuk memulai streaming langsung, Anda memerlukan URL ingest untuk menyiarkan dan URL streaming untuk menonton. Topik ini menjelaskan cara menghasilkan URL ingest dan streaming yang ditandatangani dengan ApsaraVideo Live guna mengamankan distribusi aliran Anda.

Prasyarat

Sebelum menghasilkan URL ingest atau URL streaming, Anda harus menambahkan domain ingest dan domain streaming, lalu mengaitkan keduanya. Untuk informasi selengkapnya, lihat Tambahkan domain.

Catatan

Setiap domain mendukung beberapa URL ingest dan streaming untuk aliran bersamaan. Untuk domain ingest, batasnya adalah 300 aliran bersamaan di wilayah China (Beijing), China (Shanghai), dan China (Shenzhen), serta 50 di semua wilayah lainnya. Untuk informasi selengkapnya, lihat Batas.

Struktur URL

URL streaming terdiri dari protocol, domain ingest/streaming, AppName, StreamName, dan sebuah Token.

Tabel berikut menjelaskan komponen-komponen URL streaming langsung.

Parameter

Deskripsi

Contoh

Protocol

Protokol yang digunakan untuk streaming langsung.

rtmp

Ingest/Streaming domain

Domain yang telah Anda tambahkan. Gunakan domain ingest untuk menghasilkan URL ingest, dan domain streaming untuk menghasilkan URL streaming.

example.aliyundoc.com

AppName

Nama kustom untuk aplikasi streaming langsung Anda, digunakan untuk membedakan antar aplikasi atau skenario bisnis.

liveApp

StreamName

Pengenal unik kustom untuk aliran streaming langsung.

liveStream

access token

String terenkripsi yang dihasilkan menggunakan algoritma MD5 dan kunci otentikasi domain. Token ini mengamankan aliran streaming langsung. Untuk detail aturan pembuatannya, lihat URL signing.

1763451219-0-0-c9139**********08dcaf1dad8381

Hasilkan URL

Anda dapat menghasilkan URL ingest dan streaming menggunakan salah satu metode berikut:

  1. Hasilkan di Konsol: Direkomendasikan untuk uji coba awal dan pengujian. Konsol menghasilkan URL dengan Token terenkripsi hanya dengan satu klik.

  2. Hasilkan secara terprogram: Direkomendasikan untuk lingkungan produksi. Mengotomatiskan pembuatan URL di server Anda memungkinkan manajemen dan distribusi yang fleksibel.

Hasilkan di Konsol

  1. Buka halaman URL Generators.

  2. Lengkapi konfigurasi berikut dan klik Generate URLs untuk mendapatkan URL ingest dan streaming.

    image

    Catatan

    Pembuat URL tidak mendukung pembuatan URL streaming untuk live subtitles.

Hasilkan secara terprogram

Langkah 1: Susun URI

Susun URI dasar dalam format berikut: {protocol}://{domain}/{AppName}/{streamName}. Untuk contoh protokol berbeda, lihat Contoh URL ingest atau Contoh URL streaming.

// Pseudocode
protocol = "rtmp"
domain = "example.aliyundoc.com"
appName = "liveApp"
streamName = "liveStream"
uri = protocol + "://" + domain + "/" + appName + "/" + streamName
// Hasil: rtmp://example.aliyundoc.com/liveApp/liveStream

Langkah 2: Dapatkan kunci otentikasi

Kunci otentikasi digunakan untuk menghasilkan access token. Dapatkan kunci otentikasi dari halaman URL signing di Konsol atau dengan memanggil API DescribeLiveDomainConfigs.

Catatan

Gunakan kunci otentikasi domain ingest untuk URL ingest dan kunci domain streaming untuk URL streaming.

Langkah 3: Susun URL yang ditandatangani

Kode contoh berikut untuk protokol RTMP pertama-tama menghasilkan {Token}, lalu menyusun URL streaming langsung lengkap:

Java

import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AuthDemo {
    private static String md5Sum(String src) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        md5.update(StandardCharsets.UTF_8.encode(src));
        return String.format("%032x", new BigInteger(1, md5.digest()));
    }

private static String aAuth(String uri, String key, long exp) {
    String pattern = "^(rtmp://)?([^/?]+)(/[^?]*)?(\\\\?.*)?$";
    Pattern r = Pattern.compile(pattern);
    Matcher m = r.matcher(uri);
    String scheme = "", host = "", path = "", args = "";
    if (m.find()) {
        scheme = m.group(1) == null ? "rtmp://" : m.group(1);
        host = m.group(2) == null ? "" : m.group(2);
        path = m.group(3) == null ? "/" : m.group(3);
        args = m.group(4) == null ? "" : m.group(4);
    } else {
        System.out.println("NO MATCH");
    }

    String rand = "0";  // "0" by default, other value is ok
    String uid = "0";   // "0" by default, other value is ok
    String sString = String.format("%s-%s-%s-%s-%s", path, exp, rand, uid, key);
    String hashValue = md5Sum(sString);
    String authKey = String.format("%s-%s-%s-%s", exp, rand, uid, hashValue);
    if (args.isEmpty()) {
        return String.format("%s%s%s%s?auth_key=%s", scheme, host, path, args, authKey);
    } else {
        return String.format("%s%s%s%s&auth_key=%s", scheme, host, path, args, authKey);
    }
}

public static void main(String[] args) {
    // The ingest or streaming URL to be signed. example.aliyundoc.com is the ingest or streaming domain, liveApp is the AppName, and liveStream is the StreamName.
    // The same signing method is used for both ingest and streaming URLs.
    // The AppName and StreamName can be up to 256 characters long and can contain digits, uppercase and lowercase letters, hyphens (-), underscores (_), and equal signs (=).
    String uri = "rtmp://example.aliyundoc.com/liveApp/liveStream";  
    // The authentication key. Use the key of the ingest domain for ingest URLs and the key of the streaming domain for streaming URLs.
    String key = "<input private key>";                       
    // The URL's final expiration time is the `exp` timestamp plus the validity period configured for the domain's URL signing. For example, if `exp` is `now + 3600`, the URL expires at `now + 3600 + validity_period`.
    long exp = System.currentTimeMillis() / 1000 + 1 * 3600;  
    String authUri = aAuth(uri, key, exp);                    
    System.out.printf("URL : %s\nAuth: %s", uri, authUri);
}
}

Python

import re
import time
import hashlib
import datetime
def md5sum(src):
    m = hashlib.md5()
    if isinstance(src, str):
        src = src.encode('utf-8')
    m.update(src)
    return m.hexdigest()
    
def a_auth(uri, key, exp):
    p = re.compile("^(rtmp://)?([^/?]+)(/[^?]*)?(\\?.*)?$")
    if not p:
        return None
    m = p.match(uri)
    scheme, host, path, args = m.groups()
    if not scheme: scheme = "rtmp://"
    if not path: path = "/"
    if not args: args = ""
    rand = "0"      # "0" secara default, nilai lain boleh
    uid = "0"       # "0" secara default, nilai lain boleh
    sstring = "%s-%s-%s-%s-%s" %(path, exp, rand, uid, key)
    hashvalue = md5sum(sstring.encode('utf-8'))
    auth_key = "%s-%s-%s-%s" %(exp, rand, uid, hashvalue)
    if args:
        return "%s%s%s%s&auth_key=%s" %(scheme, host, path, args, auth_key)
    else:
        return "%s%s%s%s?auth_key=%s" %(scheme, host, path, args, auth_key)
def main():
    # URL ingest atau streaming yang akan ditandatangani. example.aliyundoc.com adalah domain ingest atau streaming, liveApp adalah AppName, dan liveStream adalah StreamName.
    # Metode penandatanganan yang sama digunakan untuk URL ingest dan URL streaming.
    # AppName dan StreamName dapat memiliki panjang hingga 256 karakter dan dapat berisi digit, huruf besar dan kecil, tanda hubung (-), garis bawah (_), dan tanda sama dengan (=).
    uri = "rtmp://example.aliyundoc.com/liveApp/liveStream"  
    # Kunci otentikasi. Gunakan kunci domain ingest untuk URL ingest dan kunci domain streaming untuk URL streaming.
    key = "<input private key>"                         
    # Waktu kedaluwarsa akhir URL adalah timestamp `exp` ditambah periode validitas yang dikonfigurasi untuk Penandatanganan URL domain. Misalnya, jika `exp` adalah `now + 3600`, URL akan kedaluwarsa pada `now + 3600 + validity_period`.
    exp = int(time.time()) + 1 * 3600                   
    authuri = a_auth(uri, key, exp)                     
    print("URL : %s\nAUTH: %s" %(uri, authuri))
if __name__ == "__main__":
    main()

Go

package main
import (
    "crypto/md5"
    "encoding/hex"
    "fmt"
    "regexp"
    "time"
)

func md5sum(src string) string {
    h := md5.New()
    h.Write([]byte(src))
    return hex.EncodeToString(h.Sum(nil))
}

func a_auth(uri, key string, exp int64) string {
    p, err := regexp.Compile("^(rtmp://)?([^/?]+)(/[^?]*)?(\\?.*)?$")
    if err != nil {
        fmt.Println(err)
        return ""
    }
    m := p.FindStringSubmatch(uri)
    var scheme, host, path, args string
    if len(m) == 5 {
        scheme, host, path, args = m[1], m[2], m[3], m[4]
    } else {
        scheme, host, path, args = "rtmp://", "", "/", ""
    }
    rand := "0" // "0" by default, other value is ok
    uid := "0"  // "0" by default, other value is ok
    sstring := fmt.Sprintf("%s-%d-%s-%s-%s", path, exp, rand, uid, key)
    hashvalue := md5sum(sstring)
    auth_key := fmt.Sprintf("%d-%s-%s-%s", exp, rand, uid, hashvalue)
    if len(args) != 0 {
        return fmt.Sprintf("%s%s%s%s&auth_key=%s", scheme, host, path, args, auth_key)
    } else {
        return fmt.Sprintf("%s%s%s%s?auth_key=%s", scheme, host, path, args, auth_key)
    }
}

func main() {
    // The ingest or streaming URL to be signed. example.aliyundoc.com is the ingest or streaming domain, liveApp is the AppName, and liveStream is the StreamName.
    // The same signing method is used for both ingest and streaming URLs.
    // The AppName and StreamName can be up to 256 characters long and can contain digits, uppercase and lowercase letters, hyphens (-), underscores (_), and equal signs (=).
    uri := "rtmp://example.aliyundoc.com/liveApp/liveStream" 
    // The authentication key. Use the key of the ingest domain for ingest URLs and the key of the streaming domain for streaming URLs.
    key := "<input private key>"     
    // The URL's final expiration time is the `exp` timestamp plus the validity period configured for the domain's URL signing. For example, if `exp` is `now + 3600`, the URL expires at `now + 3600 + validity_period`.
    exp := time.Now().Unix() + 3600                                    
    authuri := a_auth(uri, key, exp)                                       
    fmt.Printf("URL : %s\nAUTH: %s", uri, authuri)
}

PHP

<?php
function a_auth($uri, $key, $exp) {
    preg_match("/^(rtmp:\/\/)?([^\/?]+)?(\/[^?]*)?(\?.*)?$/", $uri, $matches);
    $scheme = $matches[1];
    $host = $matches[2];
    $path = $matches[3];
    $args = $matches[4];
    if  (empty($args)) {
        $args ="";
    }
    if  (empty($scheme)) {
        $scheme ="rtmp://";
    }
    if  (empty($path)) {
        $path ="/";
    }
    $rand = "0";
    // "0" by default, other value is ok
    $uid = "0";
    // "0" by default, other value is ok
    $sstring = sprintf("%s-%u-%s-%s-%s", $path, $exp, $rand, $uid, $key);
    $hashvalue = md5($sstring);
    $auth_key = sprintf("%u-%s-%s-%s", $exp, $rand, $uid, $hashvalue);
    if ($args) {
        return sprintf("%s%s%s%s&auth_key=%s", $scheme, $host, $path, $args, $auth_key);
    } else {
        return sprintf("%s%s%s%s?auth_key=%s", $scheme, $host, $path, $args, $auth_key);
    }
}
// The ingest or streaming URL to be signed. example.aliyundoc.com is the ingest or streaming domain, liveApp is the AppName, and liveStream is the StreamName.
// The same signing method is used for both ingest and streaming URLs.
// The AppName and StreamName can be up to 256 characters long and can contain digits, uppercase and lowercase letters, hyphens (-), underscores (_), and equal signs (=).
$uri = "rtmp://example.aliyundoc.com/liveApp/liveStream";
// The authentication key. Use the key of the ingest domain for ingest URLs and the key of the streaming domain for streaming URLs.
$key = "<input private key>";
// The URL's final expiration time is the `exp` timestamp plus the validity period configured for the domain's URL signing. For example, if `exp` is `now + 3600`, the URL expires at `now + 3600 + validity_period`.
$exp = time() + 3600;
$authuri = a_auth($uri, $key, $exp);
echo "URL :" . $uri;
echo PHP_EOL;
echo "AUTH:" . $authuri;
?>

C#

using System;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
using System.Text;
public class Test
{
    public static void Main()
    {
        // The ingest or streaming URL to be signed. example.aliyundoc.com is the ingest or streaming domain, liveApp is the AppName, and liveStream is the StreamName.
        // The same signing method is used for both ingest and streaming URLs.
        // The AppName and StreamName can be up to 256 characters long and can contain digits, uppercase and lowercase letters, hyphens (-), underscores (_), and equal signs (=).
        string uri= "rtmp://example.aliyundoc.com/liveApp/liveStream";  
        // The authentication key. Use the key of the ingest domain for ingest URLs and the key of the streaming domain for streaming URLs.
        string key= "<input private key>";                           
        DateTime dateStart = new DateTime(1970, 1, 1, 8, 0, 0);
        // The URL's final expiration time is the `exp` timestamp plus the validity period configured for the domain's URL signing. For example, if `exp` is `now + 3600`, the URL expires at `now + 3600 + validity_period`.
        string exp  = Convert.ToInt64((DateTime.Now - dateStart).TotalSeconds+3600).ToString(); 
        string authUri = aAuth(uri, key, exp);
        Console.WriteLine (String.Format("URL :{0}",uri));
        Console.WriteLine (String.Format("AUTH :{0}",authUri));
    }
    public static string aAuth(string uri, string key, string exp)
    {
        Regex regex = new Regex("^(rtmp://)?([^/?]+)(/[^?]*)?(\\\\?.*)?$");
        Match m = regex.Match(uri);
        string scheme = "rtmp://", host = "", path = "/", args = "";
        if (m.Success)
        {
            scheme=m.Groups[1].Value;
            host=m.Groups[2].Value;
            path=m.Groups[3].Value;
            args=m.Groups[4].Value;
        }else{
            Console.WriteLine ("NO MATCH");
        }
        string rand = "0";  // "0" by default, other value is ok
        string uid = "0";   // "0" by default, other value is ok
        string u = String.Format("{0}-{1}-{2}-{3}-{4}",  path, exp, rand, uid, key);
        string hashValue  = Md5(u);
        string authKey = String.Format("{0}-{1}-{2}-{3}", exp, rand, uid, hashValue);
        if (args=="")
        {
            return String.Format("{0}{1}{2}{3}?auth_key={4}", scheme, host, path, args, authKey);
        } else
        {
            return String.Format("{0}{1}{2}{3}&auth_key={4}", scheme, host, path, args, authKey);
        }
    }
    public static string Md5(string value)
    {
        MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
        byte[] bytes = Encoding.ASCII.GetBytes(value);
        byte[] encoded = md5.ComputeHash(bytes);
        StringBuilder sb = new StringBuilder();
        for(int i=0; i<encoded.Length; ++i)
        {
            sb.Append(encoded[i].ToString("x2"));
        }
        return sb.ToString();
   }
}

Contoh URL ingest

Protocol

Contoh URL

Deskripsi

RTMP

rtmp://{domain}/{AppName}/{StreamName}?auth_key={access_token}

Protokol standar untuk ingest streaming langsung.

RTMPS

rtmps://{domain}/{AppName}/{StreamName}?auth_key={access_token}

Protokol standar untuk ingest streaming langsung yang aman dan terenkripsi.

ARTC

artc://{domain}/{AppName}/{StreamName}?auth_key={access_token}

URL ingest untuk Real-Time Streaming (RTS).

SRT

srt://{domain}:1105?streamid=#!::h={domain},r=/{AppName}/{StreamName}?auth_key={access_token},m=publish

SRT dinonaktifkan secara default. Anda harus mengaktifkannya untuk domain ingest. Untuk petunjuknya, lihat SRT stream ingest.

Contoh URL streaming

Jenis URL

Deskripsi

Protocol

Contoh URL

URL streaming standar

Jika Anda menggunakan SRT untuk ingest streaming langsung, pemutaran didukung melalui RTMP, FLV, HLS, dan ARTC.

RTMP

rtmp://{domain}/{AppName}/{StreamName}?auth_key={access_token}

FLV

http://{domain}/{AppName}/{StreamName}.flv?auth_key={access_token}

HLS

http://{domain}/{AppName}/{StreamName}.m3u8?auth_key={access_token}

ARTC

artc://{domain}/{AppName}/{StreamName}?auth_key={access_token}

URL streaming yang telah dikodekan ulang (Default Transcoding/Custom Transcoding)

Untuk aliran yang telah dikodekan ulang, tambahkan _{transcoding_template_ID} ke StreamName. Dapatkan transcoding_template_ID dengan mengonfigurasi live stream transcoding.

RTMP

rtmp://{domain}/{AppName}/{StreamName}_{transcoding_template_ID}?auth_key={access_token}

FLV

http://{domain}/{AppName}/{StreamName}_{transcoding_template_ID}.flv?auth_key={access_token}

HLS

http://{domain}/{AppName}/{StreamName}_{transcoding_template_ID}.m3u8?auth_key={access_token}

ARTC

artc://{domain}/{AppName}/{StreamName}_{transcoding_template_ID}?auth_key={access_token}

URL streaming yang telah dikodekan ulang (Multi-bitrate Transcoding)

Untuk aliran bitrate adaptif, tambahkan _{transcoding_template_group_ID} ke StreamName dan tambahkan parameter aliyunols=on ke URL. Dapatkan transcoding_template_group_ID dengan mengonfigurasi live stream transcoding.

HLS

http://{domain}/{AppName}/{StreamName}_{transcoding_template_group_ID}.m3u8?aliyunols=on&auth_key={access_token}

URL aliran tertunda

Untuk aliran tertunda, tambahkan -alidelay ke StreamName. Anda harus terlebih dahulu mengonfigurasi stream delay.

RTMP

rtmp://{domain}/{AppName}/{StreamName}-alidelay?auth_key={access_token}

FLV

http://{domain}/{AppName}/{StreamName}-alidelay.flv?auth_key={access_token}

HLS

http://{domain}/{AppName}/{StreamName}-alidelay.m3u8?auth_key={access_token}

ARTC

artc://{domain}/{AppName}/{StreamName}-alidelay?auth_key={access_token}

URL aliran subtitle langsung

Untuk aliran dengan subtitle langsung, tambahkan _{subtitle_template_name} ke StreamName. Dapatkan subtitle_template_name dengan mengonfigurasi live subtitles.

RTMP

rtmp://{domain}/{AppName}/{StreamName}_{subtitle_template_name}?auth_key={access_token}

FLV

http://{domain}/{AppName}/{StreamName}_{subtitle_template_name}.flv?auth_key={access_token}

HLS

http://{domain}/{AppName}/{StreamName}_{subtitle_template_name}.m3u8?auth_key={access_token}

Verifikasi URL yang dihasilkan

Untuk memverifikasi URL Anda, kami merekomendasikan melakukan ingest aliran menggunakan aplikasi demo kami di perangkat seluler dan memutar ulang menggunakan VLC media player di PC. Untuk metode ingest dan pemutaran lainnya, lihat Live stream ingest dan Live stream playback:

Verifikasi URL ingest:

  1. Di perangkat seluler (Android atau iOS), pindai kode QR untuk mengunduh dan menginstal aplikasi demo ApsaraVideo Live.

    image

    Catatan

    Di perangkat iOS, jika muncul pesan yang menunjukkan developer enterprise tidak tepercaya, buka Settings > General > VPN & Device Management, temukan profil untuk Taobao, lalu ketuk Trust.

  2. Buka Demo App, lalu pilih Camera atau Screen Recording Ingest. Masukkan URL ingest. Anda dapat memindai kode QR untuk memasukkan URL yang dihasilkan di Konsol.

    imageimage

  3. Ketuk Start untuk mulai mengambil aliran.

    Anda dapat melihat aliran aktif di halaman Stream Management di Konsol ApsaraVideo Live. Jika aliran tidak ditampilkan, tinjau kembali langkah-langkah sebelumnya untuk mencari kesalahan.

    image

Verifikasi URL streaming:

Catatan

Pastikan klien ingest tetap berjalan. Jika tidak, pemutaran akan gagal.

  1. Unduh dan instal VLC media player.

  2. Buka VLC media player.

  3. Dari bilah menu, pilih Media > Open Network Stream.

  4. Di tab Network, masukkan URL streaming. Contohnya: rtmp://pull-singapore.cloud-example.net/testApp/testStream?auth_key=1750150177-0-0-9b7*******31acc543a99c69********

    p888206

Troubleshooting

Jika Anda mengalami masalah saat ingest atau pemutaran streaming langsung, gunakan troubleshooting tool untuk memvalidasi URL Anda, penandatanganannya, dan pengaturan lainnya.