This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.
The demo application already provides request and response operators for authentication, search, and video upload. To simplify the API's usage, I added inline methods that fill in known details of a request, such as which function objects to use, and call YouTubeService::service() internally. A video upload can be achieved with only a few lines of code:
authenticationData.userName = "user";
authenticationData.password = "password";
uploadData.fileName = "screen.ogv";
uploadData.mimeType = "video/ogg";
uploadData.title = "Title";
uploadData.description = "Test upload";
uploadData.category = "Tech";
uploadData.isPrivate = false;
uploadData.developerTag = "TagName";
uploadData.keywords = "1Dot, 2Dots, 3Dots, more";
YouTubeServiceState upload =
ASSERT(upload == YouTubeServiceStates::Ok);
When uploading the video file, you have a number of options that describe the contents, such as title, description, and category. Useful is the developer tag, which is an invisible marker that's only accessible to your application.
This tag can be used in search requests to filter videos uploaded by your application. With the private flag, you can decide whether the video is accessible to everyone or only the user.
Once uploaded, it usually takes 5-10 minutes for YouTube to process the video and enable it for viewing on YouTube's web site. You can check the status of a video under My Account / My Videos / Uploaded Videos for the account that was used to upload the file. You can watch some sample videos on the test account I created for this article.
As you have seen, adding YouTube upload to your game is straightforward, but requires some planning.
To start with, you need to decide how you are going to record the game footage. From the discussed options, a framebuffer capture is the easiest to add to an existing game, but recording game state or player input gives you more flexibility to apply changes to the recording. If you want to change the camera angle later on, for example, game state recordings allow you to do that.
I chose the Theora video format to turn the recording into a video because the encoder comes with an easy to use reference implementation and doesn't require license fees. Other video formats accepted by YouTube include DivX and most formats of the MPEG suite.
Finally, an application can upload videos with YouTube's RESTful interface; a protocol based on HTTP. The demo application for this article comes with an implementation for authentication, search, and video upload requests that you can use for your own game.
Note: Demo updated 5 January 2009. Note from the author: "Update v1.1: Fixed a bug where I mixed up the color channels when reading from the DirectX render target. DXUT sets the render target to D3DFMT_X8R8G8B8 by default where the color channels are ordered BGRX in memory. For this reason, I added ImageFormat::B8G8R8A8 as a new image format and a new code path to ImageUtils::convertToYCbCr420p() to handle this format."
[EDITOR'S NOTE: This article was independently published by Gamasutra's editors, since it was deemed of value to the community. Its publishing has been made possible by Intel, as a platform and vendor-agnostic part of Intel's Visual Computing microsite.]