Record Video and POST to YouTube via API
in
Contributed Library Questions
•
2 years ago
Hey All,
I'm working on an interactive installation where users are recorded via webcam. The footage is then uploaded to the web via the youtube API.
Issue: I am not an able programmer, and really need to know how to do this.
- //***** Webcam Capture and display with Social media integration *****
- //**** SJ, Victoria University of Wellington ****
- import com.google.gdata.client.Query;
- import com.google.gdata.client.Service;
- import com.google.gdata.client.youtube.YouTubeQuery;
- import com.google.gdata.client.youtube.YouTubeService;
- import com.google.gdata.data.Category;
- import com.google.gdata.data.Entry;
- import com.google.gdata.data.Feed;
- import com.google.gdata.data.TextContent;
- import com.google.gdata.data.extensions.Comments;
- import com.google.gdata.data.extensions.FeedLink;
- import com.google.gdata.data.youtube.FeedLinkEntry;
- import com.google.gdata.data.youtube.PlaylistEntry;
- import com.google.gdata.data.youtube.PlaylistFeed;
- import com.google.gdata.data.youtube.PlaylistLinkEntry;
- import com.google.gdata.data.youtube.PlaylistLinkFeed;
- import com.google.gdata.data.youtube.SubscriptionEntry;
- import com.google.gdata.data.youtube.SubscriptionFeed;
- import com.google.gdata.data.youtube.UserProfileEntry;
- import com.google.gdata.data.youtube.VideoEntry;
- import com.google.gdata.data.youtube.VideoFeed;
- import com.google.gdata.data.youtube.YouTubeMediaContent;
- import com.google.gdata.data.youtube.YouTubeMediaGroup;
- import com.google.gdata.data.youtube.YouTubeNamespace;
- import com.google.gdata.util.ServiceException;
- import com.google.common.collect.*;
- import com.google.gdata.client.*;
- import com.google.gdata.client.youtube.*;
- import com.google.gdata.data.*;
- import com.google.gdata.data.geo.impl.*;
- import com.google.gdata.data.media.*;
- import com.google.gdata.data.media.mediarss.*;
- import com.google.gdata.data.youtube.*;
- import com.google.gdata.data.extensions.*;
- import com.google.gdata.util.*;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintStream;
- import java.net.URL;
- import java.io.IOException;
- import java.io.OutputStreamWriter;
- import java.io.UnsupportedEncodingException;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.net.URLEncoder;
- import processing.video.*;
- import processing.net.*;
- import java.util.Iterator;
- import java.util.LinkedList;
- import java.util.List;
- Capture myCapture; //get video feed
- MovieMaker mm; //declear MovieMaker object
- Timer timer; // declear the Timer
- PFont font; //initiate font useage
- Client localClient;
- Service service;
- String developer_key = "DEVELOPER KEY HERE";
- String YOUTUBE_URL = "http://gdata.youtube.com/feeds/api/videos";
- YouTubeService Service;
- YouTubeQuery query;
- MalformedURLException e;
- void setup() {
- try {
- query = new YouTubeQuery(new URL(YOUTUBE_URL));
- } catch (MalformedURLException e){
- println("ERROR " +e.getMessage());
- } catch (IOException e){
- println("ERROR " +e.getMessage());
- }
- service = new YouTubeService("DEVELOPER KEY HERE");
- //set the size of the window
- size(1024, 768);
- //setup the video file that will be recorded
- mm=new MovieMaker(this, width, height, "EmotionalCapture.mov", 30, MovieMaker.H263, MovieMaker.HIGH);
- //setup the capture system for video capture
- myCapture=new Capture(this, 640, 480, 30);
- //initiate the timer
- //timer=new Timer(5, 5);
- //setup the text message(s)
- font = loadFont ("Helvetica-36.vlw");
- }
- void captureEvent(Capture myCapture) {
- myCapture.read();
- }
- void draw() {
- background(#FFFFFF);
- myCapture.read();
- image(myCapture, 190, 150);
- mm.addFrame(); // Add frames to the video - start video record
- //timer.update();
- textFont(font, 36);
- text ("Show me how you are feeling..", 240, 700);
- fill (0);
- println("Simon is awesome");
- }
- void keyPressed() {
- if (key == 'q') {
- //Finish the movie if the 'q' button is pressed
- mm.finish();
- //***** Upload the File to youtube *****
- VideoEntry newEntry = new VideoEntry();
- YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
- mg.setTitle(new MediaTitle());
- mg.getTitle().setPlainTextContent("My Test Movie");
- mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Installation"));
- mg.setKeywords(new MediaKeywords());
- mg.getKeywords().addKeyword("cars");
- mg.getKeywords().addKeyword("funny");
- mg.setDescription(new MediaDescription());
- mg.getDescription().setPlainTextContent("My description");
- mg.setPrivate(false);
- mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "Kapziel"));
- newEntry.setLocation("Te Aro Design Schoool, Wellington");
- // alternatively, one could specify just a descriptive string
- // newEntry.setLocation("Mountain View, CA");
- MediaFileSource ms = new MediaFileSource(new File("file.mov"), "video/quicktime");
- newEntry.setMediaSource(ms);
- String uploadUrl =
- "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
- // VideoEntry createdEntry = service.insert(new URL(uploadUrl), newEntry);
- println("upload complete");
- exit();
- }
- }
Sorry for the messy code, it is currently early early morning.. I also start installing this in my exhibition space very soon. So would love to figure out how to do this ASAP. Also, there are some aspects in there that are now redundant, such as the timer; which was an original element, but not not so much.
Back to the Red Bull.
Thanks in advanced,
S.
1