コード例 #1
0
        public static void CreateLiveChannelAndPushStream(string bucketName)
        {
            string liveChannelName = "rtmp-test";

            try
            {
                //create a live channel by using default paramters
                var result = client.CreateLiveChannel(new CreateLiveChannelRequest(bucketName, liveChannelName));

                //enable live channel
                client.SetLiveChannelStatus(new SetLiveChannelStatusRequest(bucketName, liveChannelName, "enabled"));

                //build a presigned push url
                var uri = client.GenerateRtmpPresignedUri(new GenerateRtmpPresignedUriRequest(bucketName, liveChannelName, "playlist.m3u8"));

                Console.WriteLine("push url: {0}", uri.ToString());

                //use ffmpeg to push stream
                //ffmpeg -re -i demo.mp4 -c copy -f flv "rtmp://...."
            }
            catch (OssException ex)
            {
                Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
                                  ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }