【发布时间】:2019-10-28 13:21:14
【问题描述】:
我正在尝试通过vlcj 发送从 IP 摄像机(来自IP Webcam 的流)捕获的视频。我的流可以从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
我找到了一个可以将流绑定到广播的功能,但是当我打开直播控制室时,我得到了这个:
仍然没有设法绑定它们,但我想我越来越近了,有人可以把我推向正确的方向吗?
【问题讨论】:
标签: java youtube youtube-api streaming youtube-data-api