java - 如何将视频从 IP 摄像机传递到 Youtube 上的 LiveStream?
问题描述
我正在尝试通过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);
}
但是在他们提供的有关创建实时流的代码中,并未提供您实际流式传输某些内容的部分。
谢谢!
编辑 1 25.06.2019/17:00
我找到了名为摄取地址的字段并像这样完成了它:
cdn.setIngestionInfo(new IngestionInfo().setIngestionAddress("http://192.168.0.100:8080/video"));
但是在 YouTube Studio 中,当我运行应用程序时没有显示任何内容(如下图所示)
经过一番挖掘,我发现LiveBroadcast比LiveStream大,它可以嵌入一个LiveStream。到目前为止,我从下面介绍的LiveBroadcast 插入文档中获取了代码。
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 时,我得到了这个:
仍然没有设法绑定它们,但我想我越来越近了,有人可以把我推向正确的方向吗?
解决方案
LiveStream 是一种信息元数据集合,YouTube API 使用它来了解您的流并保存有关它的信息。
部分信息是您必须将实际视频流从相机发送到的 CDN URL(来自https://developers.google.com/youtube/v3/live/docs/liveStreams)
您可以在此处查看答案以及在此处使用此示例的示例:https ://stackoverflow.com/a/29653174/334402
推荐阅读
- ios - AR Kit 2.0 获取跟踪图像的图像细节?
- python - 如何检查两个列表是否与重复项相等?
- javascript - 查找通过在 linux 中无头运行 jasmine 触发的 Chromium 堆栈跟踪的原因
- java - NoSuchMethodError:com.fasterxml.jackson.core.JsonStreamContext
- swift - swift - 从类外的模型文件中激活类上的 segue?实例成员不能用于类型
- sql - Presto/SQL - 将字符串时间戳转换为日期会引发错误
- git - Git:如何在提交前将文件标记为已审核?
- conda - conda build 后如何获取 conda 包的路径
- q# - 如果 Q# 函数可以运行使用比特的经典代码,那么经典代码是否仍能以量子计算机运行的速度运行?
- java - 在 IntelliJ Idea 2018 中创建 jar 文件 - 运行 Jar 错误