【问题标题】:How to pass video from IP camera to LiveStream on Youtube?如何将视频从 IP 摄像机传递到 Youtube 上的 LiveStream?
【发布时间】:2019-10-28 13:21:14
【问题描述】:

我正在尝试通过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);
}

但在他们提供的关于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


    【解决方案1】:

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

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

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

    【讨论】:

    • 我设法找到了该字段,并从我的手机中输入了我的地址:192.168.0.100:8080/video,但什么也没发生。我在这件事上更新了我的问题。谢谢!
    猜你喜欢
    • 2019-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    • 1970-01-01
    • 1970-01-01
    • 2018-06-30
    • 1970-01-01
    相关资源
    最近更新 更多