doukang1962 2016-02-19 14:07
浏览 81
已采纳

在wowza中流目标

I have implemented for creating stream target through php with the help of curl.

<?php
$service_url = 'http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/liveSource';
$curl = curl_init($service_url);
$curl_post_data ='
{
"restURI": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive"
"stream_target": {
 "name": “defaultTarget”,
 "provider": "rtmp",
 "username": "liveSource",
 "password": "Welcomehere",
 "stream_name": “customTarget”,
 "primary_url": "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/liveSource",
  } "https://api.cloud.wowza.com/api/v1/stream_targets"
}';
$headers = array(
  'Content-Type: application/json; charset=utf-8',
 'Accept: application/json; charset=utf-8' 
);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$curl_response = curl_exec($curl); 
curl_close($curl);

echo $curl_response;
?>

But it is showing error as success as false with code 401

 {"message":"The request requires user authentication","success":false,"wowzaServer":"4.4.0","code":"401"}
  • 写回答

1条回答 默认 最新

  • douqian2957 2016-02-24 12:33
    关注

    If you are trying to create a stream target in Wowza Streaming engine, I would start with a simple example as follows:

    <?php  
    // Modify values here
    $entryName = "ppSource";
    $appName = "live";
    $streamName = "myStream";
    $userName = "user";
    $password = "pass";
    $profile = "rtmp";
    $server = "localhost";
    // End modification
    
    $url = "http://{$server}:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/{$appName}/pushpublish/mapentries/{$entryName}";
    $json = "{
       \"restURI\": \"http://{$server}:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/{$appName}/pushpublish/mapentries/{$entryName}\",
       \"serverName\":\"_defaultServer_\",
                \"sourceStreamName\": \"{$streamName}\",
                \"entryName\": \"{$entryName}\",
                \"profile\": \"{$profile}\",
                \"host\": \"{$server}\",
                \"application\":\"{$appName}\",
                \"userName\":\"{$userName}\",
                \"password\":\"{$password}\",
                \"streamName\":\"{$streamName}\"
    }'";
    
    $ch = curl_init($url);                                                     
    curl_setopt($ch, CURLOPT_POST, true);                                     
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    curl_setopt($ch, CURLOPT_HEADER      ,0);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);
    // curl_setopt($ch, CURLOPT_USERPWD, "user:pass");                                                            
    // curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);             
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                        'Accept:application/json; charset=utf-8',
                        'Content-type:application/json; charset=utf-8',
                        'Content-Length: '.strlen($json)));
    $contents = curl_exec($ch); 
    curl_close($ch);
    
    $obj =  json_decode($contents);
    var_dump($obj);
    

    However if you are trying to initiate a live stream through our cloud api, here is a small example (only) of what your request might look like:

    // Modify values here 
    $cloudApiKey = "xxxxxxxxxxx";
    $cloudApiAccessKey="xxxxxxxxxx";
    // End modification 
    
    $url = "https://api.cloud.wowza.com/api/v1/live_streams";
    $json = "{
       \"live_stream\": {
         \"id\": \"1234abcd\",
         \"name\": \"MyLiveStream\",
         \"transcoder_type\": \"transcoded\",
         \"billing_mode\": \"pay_as_you_go\",
         \"broadcast_location\": \"us_west_california\",
         \"recording\": false,
         \"encoder\": \"wowza_gocoder\",
         \"delivery_method\": \"push\",
         \"use_stream_source\": false,
         \"aspect_ratio_width\": 1280,
         \"aspect_ratio_height\": 720,
         \"connection_code\": \"033334\",
         \"connection_code_expires_at\": \"2015-11-25T12:06:38.453-08:00\",
         \"source_connection_information\": {
           \"primary_server\": \"6022e9.entrypoint.cloud.wowza.com\",
           \"host_port\": 1935,
           \"application\": \"app-464b\",
           \"stream_name\": \"32a5814b\",
           \"disable_authentication\": false,
           \"username\": \"client2\",
           \"password\": \"1234abcd\"
         },
         \"player_responsive\": true,
         \"player_countdown\": false,
         \"player_embed_code\": \"in_progress\",
         \"player_hds_playback_url\": \"http://wowzadev-f.akamaihd.net/z/32a5814b_1@7217/manifest.f4m\",
         \"player_hls_playback_url\": \"http://wowzadev-f.akamaihd.net/i/32a5814b_1@7217/master.m3u8\",
         \"hosted_page\": true,
         \"hosted_page_title\": \"MyLiveStream\",
         \"hosted_page_url\": \"in_progress\",
         \"hosted_page_sharing_icons\": true
       } 
    }";
    
    $ch = curl_init($url);                                                     
    curl_setopt($ch, CURLOPT_POST, true);                                     
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    curl_setopt($ch, CURLOPT_HEADER      ,0);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);        
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                        'Accept:application/json; charset=utf-8',
                        'Content-type:application/json; charset=utf-8',
                        'wsc-api-key: '.$cloudApiKey,
                        'wsc-access-key: '.$cloudApiAccessKey,
     );
    $contents = curl_exec($ch); 
    curl_close($ch);
    

    This is obtained from the examples page and modified to fit into a PHP related request.

    Thanks, Matt

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)