Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将视频从IP摄像机传送到Youtube上的LiveStream?_Java_Youtube_Youtube Api_Streaming_Youtube Data Api - Fatal编程技术网

Java 如何将视频从IP摄像机传送到Youtube上的LiveStream?

Java 如何将视频从IP摄像机传送到Youtube上的LiveStream?,java,youtube,youtube-api,streaming,youtube-data-api,Java,Youtube,Youtube Api,Streaming,Youtube Data Api,我正在尝试通过发送从IP摄像头(流)捕获的视频。我的流可以从http://:8080/video 如何使用YouTube流媒体API通过Java将视频发送到YT 我看到了关于和的文档,到目前为止,我已经使用他们提供的代码将视频上传到我的频道 publicstaticvoidmain(String[]args)抛出GeneralSecurityException、IOException、GoogleJsonResponseException{ YouTube YouTube服务=getServic

我正在尝试通过发送从IP摄像头(流)捕获的视频。我的流可以从
http://:8080/video

如何使用YouTube流媒体API通过Java将视频发送到YT

我看到了关于和的文档,到目前为止,我已经使用他们提供的代码将视频上传到我的频道

publicstaticvoidmain(String[]args)抛出GeneralSecurityException、IOException、GoogleJsonResponseException{
YouTube YouTube服务=getService();
//定义将作为请求主体上载的视频对象。
视频=新视频();
//将snippet对象属性添加到视频对象。
VideoSnippet snippet=新的VideoSnippet();
Random rand=新的Random();
setCategoryId(“22”);
setDescription(“上传视频的描述”);
setTitle(“测试视频上传”+rand.nextInt());
视频剪辑(片段);
//将状态对象属性添加到视频对象。
VideoStatus状态=新的VideoStatus();
状态。setPrivacyStatus(“未上市”);
视频。设置状态(状态);
File mediaFile=新文件(文件路径);
InputStreamContent mediaContent=新的InputStreamContent(“视频/*”,
新的BufferedInputStream(新的FileInputStream(mediaFile));
setLength(mediaFile.length());
//定义并执行API请求
YouTube.Videos.Insert request=youtubeService.Videos().Insert(“代码段,状态”,
视频、媒体内容);
视频响应=请求。执行();
System.out.println(响应);
}
但是,在他们提供的代码中,并没有提供实际流式传输某些内容的部分

谢谢

编辑1 2019年6月25日/17:00

我找到了名为Inception address的字段,并按如下方式完成它:
cdn.setIngestionInfo(新的IngestionInfo().setIngestionAddress(“http://192.168.0.100:8080/video"));,但在YouTube Studio中,当我运行应用程序时,没有显示任何内容(如下图所示)

经过一些挖掘,我发现LiveBroadcast比LiveStream大,它可以嵌入LiveStream。到目前为止,我采用了下面给出的代码

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,您必须将实际视频流从相机发送到(从)


你可以在这里看到一个使用这个的例子的答案:

我设法找到了这个字段,从我的手机中输入了我的地址:192.168.0.100:8080/视频,但什么都没有发生。我更新了关于这件事的问题。谢谢