How to upload a YouTube video

Using Amazon Web Services (AWS) Elastic Compute Cloud (EC2)

October 2017 --- updated for changes highlighted below

You'll need a Google developer's account in order to authenticate to the YouTube API using a JSON file. Assuming you have got a developer's account:

  • go to 'APIs and auth' in the Google Developers Console;

  • make sure the YouTube Data API is enabled;

  • then under Credentials:

  • select 'Create new Client ID';

  • select 'Installed application' and 'other' and create the ID.

This should create a Client ID for a native application. Click on 'Download JSON' and save the file somewhere.

Now start the EC2 instance. Here I'm using Ubuntu. Sign into the instance and do:

sudo apt-get update

sudo apt-get install python-pip

sudo pip install --upgrade google-api-python-client

sudo pip install --upgrade google-auth google-auth-oauthlib google-auth-httplib2

wget https://raw.githubusercontent.com/youtube/api-samples/master/python/upload_video.py

The first two lines install pip. The third line installs the python client for the Google API. The fourth line installs the libraries required for authentication [new]. The final line downloads (from its current location) the python script for video upload.

Now transfer the JSON file you downloaded to the EC2 instance, and rename it client_secret.json [note name changed from previous versions]. Similarly transfer the video file(s) (eg mp4) to the EC2 instance. Then to upload a file do the following

python upload_video.py --file your_video.mp4 --title "Your Title"

[Previously a --no-auth_local_webserver option was required]. The script asks you to visit a long https link to obtain a verification code. Copy and paste this link into a handy web browser and follow the instructions (eg, select the YouTube channel) to obtain the code which you can then copy and paste back into the EC2 instance command line. Then the video upload should start, and the assigned YouTube ID should appear at the end.

In the past [but now working OK at Oct 2016 onwards] I found the python script fails with an error due to a bug in the oauth2client package. This is now fixed.

The above upload example above just sets the title. There are more options for the python script that you can explore, but at present I upload the video with only the title set, and use the Google YouTube manage videos web interface to add comments and tags, etc.

I have been moving video files in a two stage process. First I upload the video file to an S3 bucket and make it public access. Then I download the video file into the EC2 instance using wget.

If the upload appears to have worked but the video doesn't appear (after a reasonable time), it could be that it needs to be 'published'. To check this log into YouTube Creator Studio and check that the video has indeed been uploaded. If necessary, change the setting to 'public' and click publish.

Current settings for recording minecraft etc: FRAPS: 30 fps, half size. Then MovieMaker: aspect ratio to widescreen 16:9 to avoid black bars in youtube, save to MPEG-4/H.264 (mp4) using a custom setting of 960x540 pixels, 8000 kbps, 29.97 fps; with audio set to 192kbps, 44.1kHz, stereo.