Description

I am fond of experimenting with the Raspberry Pi camera options (such as image effects and duration) while recording demonstration videos for my electronics projects, and especially when birdwatching in my balcony :) When I take a video with my Raspberry Pi for the mentioned reasons, I usually upload the video to my YouTube channel, as a private video, due to the storage limit on Pi. However, the process of recording and uploading through Raspberry Pi had miscellaneous and intricate steps to follow all over again: adjusting video settings manually, opening my YouTube channel, defining video parameters, etc.

Thus, I contemplated a GUI by which I could adjust the video recording settings and define the parameters to upload videos to YouTube without signing to my YouTube channel on the browser every time. After some research, I decided to use the Google APIs Client Library for Python to communicate with my YouTube channel through the YouTube Data API. In the end, I developed a GUI (YouTube Video Recorder and Uploader) in Python, including two interfaces - Record menu and Upload menu.

In the Record menu:

You can define filename (timestamp included automatically), annotation text (if required), the video duration, and select an image effect (predefined by the GUI, for instance, negative).

In the Upload menu:

You can upload the selected video to YouTube via the YouTube Data API without any further steps by merely entering the required parameters by YouTube - Title, Description, Keywords, Category, and Privacy Status.

You can find detailed information about the features of the GUI (YouTube Video Recorder and Uploader) in the Features.

After completing coding, to add mobility and night vision to my project - helpful while birdwatching or recording outside at night :) - I used a 7'' HDMI Display with Capacitive Touchscreen and a 5MP Night Vision Camera, kindly sponsored by DFRobot.

Sponsored Products by DFRobot:

Preview: What You Will Learn

Step 1: Registering an application with Google to use the OAuth 2.0 protocol to authorize access

You need to create an application on the Google API Console to run the Google APIs Client Library for Python properly, and your application must have authorization credentials to be able to use the YouTube Data API.

If you are a novice to the Google API Console, do not worry it is a simple process, apply the following steps only :)

Step 2: Installing the Google APIs Client Library for Python on Raspberry Pi 

Open the terminal and enter the command below (it will take some time to install all packages): 

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

Step 3: Authorizing Raspberry Pi to upload videos via the YouTube Data API

First of all, create a new folder at this path:

/home/pi/YouTube-Recorder-and-Uploader/

Then, download the upload_video.py file in the Code. It is the sample code provided by Google for the YouTube Data API.

Create the client_secrets.json (there is a sample in the Code) file that contains information from the Google API Console (Client ID and Client Secret).

{  "web": {    "client_id": "[[INSERT CLIENT ID HERE]]",    "client_secret": "[[INSERT CLIENT SECRET HERE]]",    "redirect_uris": [],    "auth_uri": "https://accounts.google.com/o/oauth2/auth",    "token_uri": "https://accounts.google.com/o/oauth2/token"  }
}

Inspect upload_video.py and client_secrets.json sample files I used from this guide by Google.

Do not forget to change the client secret path in the upload_video.py file.

Now, to verify your Raspberry Pi, open the terminal and enter the following command.

$ sudo python /home/pi/YouTube-Recorder-and-Uploader/                       --file="[[INSERT FILE PATH]]"                       --title="Test"                       --description="Test"                       --keywords="test"                       --category="22"                       --privacyStatus="private"

Do not worry; it will throw an error message which says "Cannot access:...upload_video.py-auth2.json" due to the absence of the confirmation tokens generated when you sign in to an application.

To create the requested file, click the link generated by the API.

And, sign in with your selected account to the application.

Copy the verification code.

Enter the verification code in the terminal and voila! Now, you can upload videos to your YouTube channel as many as you want without signing in again :)

You can see the generated verification file named upload_video.py-auth2.json (/home/pi/YouTube-Recorder-and-Uploader/).

Note: Do not forget to create a folder named Recorded in the parent folder (/home/pi/YouTube-Recorder-and-Uploader/) to save videos afterward.

Step 4: Developing a GUI (YouTube Video Recorder and Uploader) and programming Raspberry Pi

There are different modules by which you can create a GUI in Python; I chose to use the guizero module due to its simplicity and efficiency.

To be able to use all the provided widgets and events by the guizero module, install the module on Raspberry Pi:

$ sudo pip3 install guizero

After running the mentioned command on the terminal, you can use the code I provided (YouTube_Video_Recorder_and_Uploader_GUI.py) without any further requirements.

But, if you want to add new features or inspect the widget features, you can get more detailed information about the guizero module from here.

Unfortunately, Raspberry Pi captures video as a raw H264 video stream, and YouTube does not allow users to upload a video in the H264 format. So, we need to convert the video in the H264 format to the MP4 format by using MP4Box before uploading it to YouTube.

Install MP4Box with this command:

$ sudo apt install -y gpac

The code executes the following command automatically when the user records a new video using the GUI. So, while using the GUI (YouTube Video Recorder and Uploader), you do not need to take any further action to convert videos from the H264 format to the MP4 format to upload them to YouTube.

MP4Box -add [[INSERT PATH]].h264 [[INSERT PATH]].mp4

I will explain the code of the GUI step by step as follows, but if you want to inspect the features of the GUI (YouTube Video Recorder and Uploader), go to the Features.

Code Explanation:

Features

Record Menu:

1) You can define the filename and the annotation text (pinned on the video). For each video, the GUI (YouTube Video Recorder and Uploader) adds a timestamp at the end of the filename (example: test-05-06-2020_17.25.01.mp4). Also, you can define the video duration using the slider from 0 to 250 seconds.

2) You can choose one of the predefined image effects (solarize, negative, pastel, etc., ) provided by the GUI before recording.

3) The GUI allows you to preview your video while recording.

4) After taking a video by clicking the Record button, the GUI updates the video list to insert the recently recorded video's path automatically.

5) The GUI saves videos in two file types - H264 (default) and MP4 (automatically generated by the GUI) - to the Recorded folder.

Upload Menu:

1) You can define the video parameters required by the YouTube Data API - Title, Description, Keywords, and Privacy Status - in the GUI (YouTube Video Recorder and Uploader).

2) YouTube has a category list in numbers by which you can change the default category (22) before uploading videos with the GUI. I added these categories which you can choose between:

You can inspect all categories from here.

3) You can select the video you want to upload to YouTube on the list box. The GUI notifies you with an information (info) message, including the path of the selected video, to avoid selections by mistake.

4) You can play the video with the omxplayer before uploading it to YouTube if you want to check the video quality again.

5) When you fill all the required parameters, you can upload the selected video with the given parameters to your YouTube channel by merely clicking the Upload button, without any further action :)

6) Go to your YouTube Studio to view the video you upload with the YouTube Video Recorder and Uploader GUI.

Shell:

1) The GUI prints notification messages after every command: you can see the recording and uploading settings or check whether the video is uploaded to YouTube correctly - if it is, you should see the video ID.

Menubar:

I added this menubar for fun :)

1) You can see the project explanation in a nutshell.

2) And, you can access the videos and other files by clicking the Files button.

Connections (Hardware)

If you are a novice in programming with Raspberry Pi, to go to the official Raspberry Pi setting up tutorial, click here.

To learn how to connect the Raspberry Pi Camera Module to your Raspberry Pi and take pictures, record videos, and apply image effects, go to the official getting started with the camera module tutorial.

Assemble the DFRobot 5MP Night Vision Camera and connect it to your Pi.

DFRobot 7'' HDMI Display with Capacitive Touchscreen is a very reliable and compatible screen for your projects with Raspberry Pi. Attach your Raspberry Pi to the screen using the standoffs and machine screws. And, connect the Pi to the screen using the well-thought Raspberry Pi HDMI Adapter. As a bonus, you do not need any driver.

You can fasten the camera to the back of the screen using the little band coming with the camera module.

Now, you can use the GUI (YouTube Video Recorder and Uploader) with DFRobot 7'' HDMI Display with Capacitive Touchscreen and DFRobot 5MP Night Vision Camera :)

Conclusion and Testing Features

You can see the recording and uploading processes in the project demonstration video.

The video uploaded with the parameters shown in the Features:

Video recording with the negative image effect setting:

Video recording and uploading with the solarize image effect setting:

Video recording and uploading in the dark to test the night vision camera:

Outdoor testing while birdwatching :)