This repository contains a set of scripts that help you take long videos, split them into smaller videos, upload those smaller videos to YouTube, and then publish those videos in a playlist on YouTube.
This project targets Python 3.12.
Install required libraries:
pip install -r requirements.txt
Install ffmpeg
and add it and ffprobe
to your PATH
.
Set up the YouTube Data API client:
- Create or select a project in the Google API Console.
- In the library panel, ensure that the YouTube Data API v3 is enabled.
- In the credentials panel, create an OAuth 2.0 client ID and download the JSON file with your client secrets.
- Store the path to the client secrets JSON file in an environment variable called
GOOGLE_CLIENT_SECRETS_FILE
.
You will need enough storage space to store a copy of the footage from the camera and to store clips from the footage.
- If the camera split videos into multiple files, recombine them. For example, the DJI Osmo Action splits video files every 4 GB; run dji_concat.py to concatenate the 4 GB segments back into full videos.
- Use your favorite spreadsheet application to create a CSV file with timestamps at which the videos should be split.
It should have the following columns (other columns will be ignored):
- File: specify the path, relative to the CSV file, of the video to split into smaller clips.
- Rows with the same file should be together.
- Inpoint: specify the time in the video at which the clip should start.
- You can use any string that pytimeparse recognizes.
- Within each group of rows with the same file, rows should be ordered by inpoint in ascending order.
- The clip will end at the next clip's inpoint.
- For each file, no clip will be generated starting at the last inpoint; it instead will be treated as the outpoint of the last clip.
- Name: specify the name to use for the clip after it is uploaded to YouTube. This does not affect the filename of the clip.
- Description: specify a description for clip after it is uploaded to YouTube. This column is optional.
- Skip: put any string of text to skip saving a file for this clip. This column is optional.
- File: specify the path, relative to the CSV file, of the video to split into smaller clips.
- Run clip_videos.py to split the full videos into clips. Although the script supports making some
clips, getting an updated CSV file, and then making more clips, it is recommended that you make clips from an entire
full video at once. That is because
ffmpeg
must read the video file from the beginning every time that you run it; making some clips from the start of the video, stopping, and then making more clips from the end of the video is not efficient. - Upload the clips to YouTube. Do not rename them before uploading; their original filenames will be used to identify them when publishing them.
- Create an empty playlist on YouTube. Note its ID from the URL.
- Run publish_videos.py. It will rename the videos to match the Name column in your CSV file, add the descriptions from the Descriptions column, add the videos to the playlist, and change the privacy from Draft to Public.