我正在尝试通过IP Webcam发送从IP摄像机捕获的视频(来自vlcj的视频)。可以从http://<phoneIP>:8080/video
如何使用YouTube Streaming API通过Java将视频发送到YT?
我看到了有关Youtube Streaming Api和Youtube Data Api v3的文档,到目前为止,我已经设法使用它们提供的代码将视频上传到我的频道。
public static void main(String[] args) throws GeneralSecurityException, IOException, GoogleJsonResponseException {
YouTube youtubeService = getService();
// Define the Video object, which will be uploaded as the request body.
Video video = new Video();
// Add the snippet object property to the Video object.
VideoSnippet snippet = new VideoSnippet();
Random rand = new Random();
snippet.setCategoryId("22");
snippet.setDescription("Description of uploaded video.");
snippet.setTitle("Test video upload. "+ rand.nextInt());
video.setSnippet(snippet);
// Add the status object property to the Video object.
VideoStatus status = new VideoStatus();
status.setPrivacyStatus("unlisted");
video.setStatus(status);
File mediaFile = new File(FILE_PATH);
InputStreamContent mediaContent = new InputStreamContent("video/*",
new BufferedInputStream(new FileInputStream(mediaFile)));
mediaContent.setLength(mediaFile.length());
// Define and execute the API request
YouTube.Videos.Insert request = youtubeService.videos().insert("snippet,status",
video, mediaContent);
Video response = request.execute();
System.out.println(response);
}
但是在他们提供的有关creating a Live stream的代码中,并没有提供您实际流式传输某些内容的部分。
谢谢!
编辑1 25.06.2019 / 17:00
我找到了名为提取地址的字段,并按如下所示完成了该操作:
cdn.setIngestionInfo(new IngestionInfo().setIngestionAddress("http://192.168.0.100:8080/video"));
,但在YouTube Studio中,当我运行该应用程序时没有任何显示(如下图所示)
经过一番挖掘,我发现LiveBroadcast比LiveStream大,并且可以嵌入LiveStream。到目前为止,我从下面介绍的LiveBroadcast insert docs中获取了代码。
public static void main(String[] args)
throws GeneralSecurityException, IOException, GoogleJsonResponseException {
YouTube youtubeService = getService();
// Define the LiveBroadcast object, which will be uploaded as the request body.
LiveBroadcast liveBroadcast = new LiveBroadcast();
LiveStream liveStream = new LiveStream();
// Add the contentDetails object property to the LiveBroadcast object.
LiveBroadcastContentDetails contentDetails = new LiveBroadcastContentDetails();
contentDetails.setEnableClosedCaptions(true);
contentDetails.setEnableContentEncryption(true);
contentDetails.setEnableDvr(true);
contentDetails.setEnableEmbed(true);
contentDetails.setRecordFromStart(true);
liveBroadcast.setContentDetails(contentDetails);
// Add the snippet object property to the LiveBroadcast object.
LiveBroadcastSnippet snippet = new LiveBroadcastSnippet();
snippet.setScheduledStartTime(new DateTime("2019-06-25T17:00:00+03:00"));
snippet.setScheduledEndTime(new DateTime("2019-06-25T17:05:00+03:00"));
snippet.setTitle("Test broadcast");
liveBroadcast.setSnippet(snippet);
// Add the status object property to the LiveBroadcast object.
LiveBroadcastStatus status = new LiveBroadcastStatus();
status.setPrivacyStatus("unlisted");
liveBroadcast.setStatus(status);
// Define and execute the API request
YouTube.LiveBroadcasts.Insert request = youtubeService.liveBroadcasts()
.insert("snippet,contentDetails,status", liveBroadcast);
LiveBroadcast response = request.execute();
System.out.println(response);
}
从上面运行代码后,我在YouTube Studio上获得了以下结果:
现在,我不知道如何结合两者,或者如何将LiveStream集成到LiveBroadcast中,这样我就可以从手机中流式传输内容。
再次感谢!
编辑2 25.06.2019 / 17:25
我找到了可以将流绑定到广播的功能,但是当我打开Live Control Room时,我得到了:
仍然没有束缚他们,但是我想我越来越近了,有人可以把我推向正确的方向吗?
答案 0 :(得分:1)
LiveStream是一种信息元数据集合,YouTube API使用该集合来了解您的流并保存有关它的信息。
其中部分信息是CDN URL,您必须将CDN URL从摄像机发送到(来自https://developers.google.com/youtube/v3/live/docs/liveStreams)
您可以在此处看到答案,并在此处使用示例:https://stackoverflow.com/a/29653174/334402