java - 如何将网络摄像机的视频传输到 Youtube 上的 LiveStream?

标签 java youtube youtube-api streaming youtube-data-api

我正在尝试通过 IP Webcam 发送从 IP 摄像机捕获的视频(来自 vlcj 的流) 。我的直播可以从 http://<phoneIP>:8080/video 获取

如何使用 YouTube Streaming API 通过 Java 将视频发送到 YT?

我看到了关于 Youtube Streaming Api 的文档和 Youtube Data Api v3到目前为止,我已经成功使用他们提供的代码将视频上传到我的 channel 。

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 2019年6月25日/17:00

我找到了名为摄取地址的字段并按如下方式完成: cdn.setIngestionInfo(new IngestionInfo().setIngestionAddress("http://192.168.0.100:8080/video")); ,但在 YouTube Studio 中,当我运行该应用时,什么也没有显示(如下图所示) YouTube Studio after LiveStream insert

经过一番挖掘,我发现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 上得到了以下结果: YouTube Studio after LiveBroadcast insert

现在我不知道如何将两者结合起来,也不知道如何将 LiveStream 集成到 LiveBroadcast 中,以便我可以从手机流式传输内容。

再次感谢!

编辑2 2019年6月25日/17:25

我找到了一个可以将流绑定(bind)到广播的函数,但是当我打开 Live Control Room 时,我得到了这个:

Live Control Room after bind

仍然没有成功绑定(bind)它们,但我想我已经接近了,有人可以把我推向正确的方向吗?

最佳答案

LiveStream 是一种元数据信息集合,YouTube API 使用它来了解您的直播并保存相关信息。

部分信息是您必须将相机中的实际视频流发送到的 CDN URL(来自 https://developers.google.com/youtube/v3/live/docs/liveStreams)

enter image description here

您可以在此处查看答案以及使用此示例的示例:https://stackoverflow.com/a/29653174/334402

关于java - 如何将网络摄像机的视频传输到 Youtube 上的 LiveStream?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56589111/

相关文章:

Curl 设置 Content-Type 不正确

java - 将 Gluon UI 库添加到 JavaFX 桌面应用程序

java - Java中的生产者消费者

android - 通过 Youtube App 上传视频并将视频链接返回到 Activity

ios - 在 iOS 中使用嵌入式 YouTube iframe 的共享功能

oauth - 谷歌 API : Find a Users YouTube Channel

python - 是否可以从 YouTube Analytics API 获取 'analytics group' 视频的数据?

sockets - .NET 2.0:已建立的连接被主机中的软件中止了

java - 更改列表中的值而不丢失旧值

java - 检索 selenium IE 驱动程序的 PID