首页 > 解决方案 > 如何将视频从 IP 摄像机传递到 Youtube 上的 LiveStream?

问题描述

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

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

我看到了有关Youtube Streaming ApiYoutube 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 中,当我运行应用程序时没有显示任何内容(如下图所示) LiveStream 插入后的 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 上得到了这个结果: LiveBroadcast 插入后的 YouTube Studio

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

再次感谢!

编辑 2 25.06.2019/17:25

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

绑定后的直播控制室

仍然没有设法绑定它们,但我想我越来越近了,有人可以把我推向正确的方向吗?

标签: javayoutubeyoutube-apistreamingyoutube-data-api

解决方案


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

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

在此处输入图像描述

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


推荐阅读