使用php获取Flash Media Encoder xml配置文件



我想问一下在youtube上创建新广播后生成的xml文件,我需要使用PHP获得该文件,而无需登录youtube,

我已经做了类似的事情

public  function cURLcheckBasicFunctions() 
{ 
  if( !function_exists("curl_init") && 
      !function_exists("curl_setopt") && 
      !function_exists("curl_exec") && 
      !function_exists("curl_close") ) return false; 
  else return true; 
} 
/* 
* Returns string status information. 
* Can be changed to int or bool return types. 
*/ 
public function cURLdownload($url, $file) 
{ 
  if( !$this->cURLcheckBasicFunctions() ) return "UNAVAILABLE: cURL Basic Functions"; 
  $ch = curl_init(); 
  if($ch) 
  { 
    $fp = fopen($file, "w"); 
    if($fp) 
    { 
      if( !curl_setopt($ch, CURLOPT_URL, $url) ) 
      { 
        fclose($fp); // to match fopen() 
        curl_close($ch); // to match curl_init() 
        return "FAIL: curl_setopt(CURLOPT_URL)"; 
      } 
      if( !curl_setopt($ch, CURLOPT_FILE, $fp) ) return "FAIL: curl_setopt(CURLOPT_FILE)"; 
      if( !curl_setopt($ch, CURLOPT_HEADER, 0) ) return "FAIL: curl_setopt(CURLOPT_HEADER)"; 
      if( !curl_exec($ch) ) return "FAIL: curl_exec()"; 
      curl_close($ch); 
      fclose($fp); 
      return "SUCCESS: $file [$url]"; 
    } 
    else return "FAIL: fopen()"; 
  } 
  else return "FAIL: curl_init()"; 
} 
    public function testXmlFile(){
        $xml= 'https://www.youtube.com/livestreaming?source=primary&itag=33&v=CtAsVo0Mug0&action_fmle_profile=1';
        echo $this->cURLdownload($xml, "test.xml");

    }

但这总是返回空文件,但如果我在登录youtube时获取URl并在浏览器中通过它,则文件下载正常

由于没有人试图回答我的问题,我采取了令人沮丧的方式,为youtube可能生成的内容制作了一个xml模板,并使用smiple_xml 直接插入信息

$xml = new simple_xml_ext("youtube_template.xml",false,true);
    $name = "";
    $width = "";
    $height = "";
    $datarate = "";
    $outputsize = "";
    //getting the stream from youtube api and replacing it in the document
    $stream = "<![CDATA[".$streamName."]]>";
    switch ($broadcast_quality) {
        case "1080p":
            $name = "YouTube (1080p Stream)";
            $xml->children()->preset->name = $name;
            $width = "1920";
            $xml->children()->capture->video->size->width = $width;
            $height = "1080";
            $xml->children()->capture->video->size->height = $height;
            $datarate = "6000";
            $xml->children()->encode->video->datarate = $datarate;
            $outputsize = "1920x1080";
            $xml->children()->encode->video->outputsize = $outputsize;
            break;
        case "720p":
            $name = "YouTube (720p Stream)";
            $xml->children()->preset->name = $name;
            $width = "1280";
            $xml->children()->capture->video->size->width = $width;
            $height = "720";
            $xml->children()->capture->video->size->height = $height;
            $datarate = "4000";
            $xml->children()->encode->video->datarate = $datarate;
            $outputsize = "1280x720";
            $xml->children()->encode->video->outputsize = $outputsize;
            break;
        case "480p":
            $name = "YouTube (480p Stream)";
            $xml->children()->preset->name = $name;
            $width = "854";
            $xml->children()->capture->video->size->width = $width;
            $height = "480";
            $xml->children()->capture->video->size->height = $height;
            $datarate = "2000";
            $xml->children()->encode->video->datarate = $datarate;
            $outputsize = "854x480";
            $xml->children()->encode->video->outputsize = $outputsize;
            break;
        case "360p":
            $name = "YouTube (360p Stream)";
            $xml->children()->preset->name = $name;
            $width = "640";
            $xml->children()->capture->video->size->width = $width;
            $height = "360";
            $xml->children()->capture->video->size->height = $height;
            $datarate = "1000";
            $xml->children()->encode->video->datarate = $datarate;
            $outputsize = "640x360";
            $xml->children()->encode->video->outputsize = $outputsize;
            break;
        case "240p":
            $name = "YouTube (240p Stream)";
            $xml->children()->preset->name = $name;
            $width = "426";
            $xml->children()->capture->video->size->width = $width;
            $height = "240";
            $xml->children()->capture->video->size->height = $height;
            $datarate = "500";
            $xml->children()->encode->video->datarate = $datarate;
            $outputsize = "426x240";
            $xml->children()->encode->video->outputsize = $outputsize;
            break;
        default:
            return false;
            break;
    }
    $xml->children()->output->rtmp->stream = null;
    $xml->children()->output->rtmp->stream->add_cdata($streamName);
    $xml->saveXML("xml_file_path.xml");

相关内容

  • 没有找到相关文章

最新更新