6

हम Google API PHP Client के साथ YouTube लाइव स्ट्रीमिंग API का उपयोग कर रहे हैं और मैं यह नहीं कर सकता कि इसे मूल (प्रीसेट) इंजेक्शन का उपयोग कैसे करें कस्टम एकYouTube लाइव स्ट्रीमिंग API का उपयोग करते समय या डुप्लिकेट कस्टम वाले से बचने के लिए बुनियादी इंजेक्शन का उपयोग करना

कस्टम वाले ठीक हैं, लेकिन किसी कारण से यदि आप उन्हें एक ही नाम कहते हैं तो यह लगातार आपके द्वारा बनाए गए प्रत्येक स्ट्रीम के लिए डुप्लीकेट बनाता है।

तो मेरा सवाल यह है कि, हम इसे बुनियादी इंजेक्शन का उपयोग करने के लिए कैसे प्राप्त करते हैं या हर बार एक नया निर्माण किए बिना कस्टम का चयन करने में सक्षम होते हैं?

उदाहरण यहां के लिए बुनियादी घूस है जब आप सेटअप एक धारा मैन्युअल रूप से अपने YouTube खाते के भीतर का चयन कर सकते हैं:

YouTube encoder

प्रासंगिक पीएचपी कोड:

// Create an object for the liveBroadcast resource's snippet. Specify values 
// for the snippet's title, scheduled start time, and scheduled end time. 
$broadcastSnippet = new Google_Service_YouTube_LiveBroadcastSnippet(); 
$broadcastSnippet->setTitle($this->title); 
$broadcastSnippet->setDescription($this->desc); 
$broadcastSnippet->setScheduledStartTime($this->start_time); 

// Create an object for the liveBroadcast resource's status, and set the 
// broadcast's status. 
$status = new Google_Service_YouTube_LiveBroadcastStatus(); 
$status->setPrivacyStatus($this->privacy_status); 

// Create the API request that inserts the liveBroadcast resource. 
$broadcastInsert = new Google_Service_YouTube_LiveBroadcast(); 
$broadcastInsert->setSnippet($broadcastSnippet); 
$broadcastInsert->setStatus($status); 
$broadcastInsert->setKind('youtube#liveBroadcast'); 

// Execute the request and return an object that contains information 
// about the new broadcast. 
$broadcastsResponse = $this->youtube->liveBroadcasts->insert('snippet,status', $broadcastInsert, array()); 

// Create an object for the liveStream resource's snippet. Specify a value 
// for the snippet's title. 
$streamSnippet = new Google_Service_YouTube_LiveStreamSnippet(); 
$streamSnippet->setTitle($this->stream_title); 

// Create an object for content distribution network details for the live 
// stream and specify the stream's format and ingestion type. 
$cdn = new Google_Service_YouTube_CdnSettings(); 
# TODO: Update the below `Format` method to use the new 'resolution' and 'frameRate' methods 
$cdn->setFormat($this->format); 
$cdn->setIngestionType('rtmp'); 

// Create the API request that inserts the liveStream resource. 
$streamInsert = new Google_Service_YouTube_LiveStream(); 
$streamInsert->setSnippet($streamSnippet); 
$streamInsert->setCdn($cdn); 
$streamInsert->setKind('youtube#liveStream'); 

// Execute the request and return an object that contains information 
// about the new stream. 
$streamsResponse = $this->youtube->liveStreams->insert('snippet,cdn', $streamInsert, array()); 

// Bind the broadcast to the live stream. 
$bindBroadcastResponse = $this->youtube->liveBroadcasts->bind(
    $broadcastsResponse['id'], 'id,contentDetails', 
    array(
     'streamId' => $streamsResponse['id'], 
    )); 

उत्तर

0

ठीक है, मैं जो कह सकता हूं उससे मूल इंजेस्टन का उपयोग करने का कोई तरीका नहीं है, लेकिन मुझे पता चला कि इसे मौजूदा कस्टम इंजेक्शन का उपयोग कैसे किया जाए।

यदि आप YouTube इंटरफ़ेस में इसे मैन्युअल रूप से पसंद करते हैं या इसे मैन्युअल रूप से बनाते हैं तो आप कोड के माध्यम से स्ट्रीम बना सकते हैं।

एक बार ऐसा करने के बाद आपको उस स्ट्रीम के स्ट्रीम ID स्ट्रीम प्राप्त करने की आवश्यकता होगी, जिसे आप बनाए गए नए प्रसारण के साथ जोड़ना चाहते हैं; मैं YouTube इंटरफ़ेस के माध्यम से इस जानकारी को खोजने का कोई तरीका नहीं बता सका ताकि आप इसे एपीआई के साथ भी कर सकें। कि इसके बाद के संस्करण कोड एक ठूंठ है

// Execute an API request that lists the streams owned by the user who 
// authorized the request. 
$streamsResponse = $this->youtube->liveStreams->listLiveStreams('id,snippet', array(
    'mine' => 'true', 
)); 

$htmlBody .= "<h3>Live Streams</h3><ul>"; 
foreach ($streamsResponse['items'] as $streamItem) { 
    $htmlBody .= sprintf('<li>%s (%s)</li>', $streamItem['snippet']['title'], 
         $streamItem['id']); 
} 
$htmlBody .= '</ul>'; 

नोट;:

आप के साथ list method धाराओं की एक सूची प्राप्त करने के लिए निम्न कोड का उपयोग कर सकते आप उपरोक्त लिंक की गई सूची विधि पर एक पूर्ण उदाहरण देख सकते हैं; मूल रूप से आपको अभी भी Google_Client, Google_Service_YouTube पर कॉल करने की आवश्यकता होगी और सुनिश्चित करें कि आपके पास वैध पहुंच टोकन आदि है।

एक बार आपके पास स्ट्रीम आईडी है जो आपको ऊपर की प्रक्रिया के माध्यम से प्राप्त करना चाहिए था; आप तो यह है कि विशिष्ट स्ट्रीम आप चाहते हैं का उपयोग करने के लिए नीचे दिए गए की तरह कुछ कर सकते हैं: फिर

// Create an object for the liveBroadcast resource's snippet. Specify values 
// for the snippet's title, scheduled start time, and scheduled end time. 
$broadcastSnippet = new Google_Service_YouTube_LiveBroadcastSnippet(); 
$broadcastSnippet->setTitle($this->title); 
$broadcastSnippet->setDescription($this->desc); 
$broadcastSnippet->setScheduledStartTime($this->start_time); 

// Create an object for the liveBroadcast resource's status, and set the 
// broadcast's status. 
$status = new Google_Service_YouTube_LiveBroadcastStatus(); 
$status->setPrivacyStatus($this->privacy_status); 

// Create the API request that inserts the liveBroadcast resource. 
$broadcastInsert = new Google_Service_YouTube_LiveBroadcast(); 
$broadcastInsert->setSnippet($broadcastSnippet); 
$broadcastInsert->setStatus($status); 
$broadcastInsert->setKind('youtube#liveBroadcast'); 

// Execute the request and return an object that contains information 
// about the new broadcast. 
$broadcastsResponse = $this->youtube->liveBroadcasts->insert('snippet,status', $broadcastInsert, array()); 

// Bind the broadcast to the live stream. 
$bindBroadcastResponse = $this->youtube->liveBroadcasts->bind(
    $broadcastsResponse['id'], 'id,contentDetails', 
    array(
     'streamId' => 'stream_id_here', // <-- Insert your stream ID here 
    )); 

, ऊपर कोड एक ठूंठ है।

तो मूल रूप से नीचे की रेखा एक बार जब आप अपनी स्ट्रीम आईडी का उपयोग करना चाहते हैं तो आप पूरी तरह से स्ट्रीम कोड का निर्माण हटा सकते हैं और फिर स्ट्रीम आईडी में पास कर सकते हैं, आपको पहले से ही कॉल में होना चाहिए था bind विधि और आपको अच्छा होना चाहिए।

उम्मीद है कि यह किसी और की मदद करता है।

2

मैं मुझे यकीन नहीं है कि "बुनियादी इंजेक्शन" से आपका क्या मतलब है। एपीआई के मुताबिक, एकमात्र सेटटेबल इंजेस्टियन प्रॉपर्टी cdn.ingestionType है जो इस समय केवल आरटीएमपी इंजेक्शन का समर्थन करती है।

वेब पोर्टल में देखे गए एन्कोडर सेटिंग्स के बराबर cdn.format मान था, जो आपके लाइव प्रसारण के लिए बिटरेट-रिज़ॉल्यूशन जोड़ी का चयन करने के लिए एक इंटरफ़ेस प्रदान करता था। इस संपत्ति को दो नई संपत्तियों के पक्ष में 18 अप्रैल, 2016 को बहिष्कृत किया गया था: cdn.frameRate और cdn.resolution। वेब पोर्टल में सूचीबद्ध बिटरेट मान प्रत्येक रिज़ॉल्यूशन के लिए अनुशंसित बिटरेट हैं, जो आपके एन्कोडर द्वारा कॉन्फ़िगर किए गए हैं, एपीआई नहीं।

उचित रूप से कस्टम cdn स्वरूपों को डुप्लिकेट लाइव स्ट्रीम ऑब्जेक्ट्स का कारण नहीं बनना चाहिए। आपके कोड में कहीं और एक बग हो सकती है। अगर आपको लगता है कि यह एक एपीआई दोष है, तो मैं Google here के लिए टिकट खोलने की सलाह देता हूं।

+0

* मूलभूत * * का उदाहरण दिखाने के लिए अद्यतन प्रश्न। – Brett

+0

@ ब्रेट ने मेरा जवाब अपडेट किया। – JAL

+0

हाँ, मुझे बहिष्कृत 'cdn.format' से अवगत है, लेकिन दुर्भाग्य से 'Google API PHP क्लाइंट' ने अभी तक इसे करने के नए तरीके के लिए समर्थन नहीं जोड़ा है AFAIK; कम से कम वी 1 शाखा में। – Brett

संबंधित मुद्दे