Reputation: 103
I am trying to send a video captured from an IP Camera (stream from IP Webcam) through vlcj. My stream can be grabbed from http://<phoneIP>:8080/video
How can I send the video through Java to YT using YouTube Streaming API?
I saw the documentation about Youtube Streaming Api and Youtube Data Api v3 and by far I've managed to upload a video to my channel by using the code provided by them.
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);
}
But in the code presented by them about creating a Live stream isn't presented the part where you actually stream some content.
Thanks!
EDIT 1 25.06.2019/17:00
I found the field named ingestion address and completed it like this:
cdn.setIngestionInfo(new IngestionInfo().setIngestionAddress("http://192.168.0.100:8080/video"));
, but in YouTube Studio, nothing shows up when I run the app (as seen in the photo below)
After some digging, i found out that LiveBroadcast is larger than LiveStream and it can embed a LiveStream. So far, i took the code from LiveBroadcast insert docs presented below.
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);
}
After running the code from above, I got this result on YouTube Studio:
Now I Don't know how to combine the two, or how to integrate LiveStream in LiveBroadcast so I can stream content from my phone.
Thanks again!
EDIT 2 25.06.2019/17:25
I found a function that can bind a stream to a broadcast, but when I open Live Control Room, i get this:
Still haven't managed to bind them, but i think i am getting closer, can someone push me towards the right direction here?
Upvotes: 1
Views: 565
Reputation: 25471
The LiveStream is a sort of metadata collection of information that the YouTube API uses to be aware of your stream and to hold information about it.
Part of the information is the CDN URL that you must send you actual video stream from your camera to (from https://developers.google.com/youtube/v3/live/docs/liveStreams)
You can see an answer here with an example of using this here: https://stackoverflow.com/a/29653174/334402
Upvotes: 1